proxygen
folly::test::WriteFileAtomic Class Reference
Inheritance diagram for folly::test::WriteFileAtomic:
testing::Test

Protected Member Functions

 WriteFileAtomic ()
 
std::set< std::stringlistTmpDir () const
 
std::string readData (const string &path) const
 
struct stat statFile (const string &path) const
 
mode_t getPerms (const string &path)
 
string tmpPath (StringPiece name)
 
void setDirPerms (mode_t mode)
 
- Protected Member Functions inherited from testing::Test
 Test ()
 
virtual void SetUp ()
 
virtual void TearDown ()
 
 Test ()
 
virtual void SetUp ()
 
virtual void TearDown ()
 
 Test ()
 
virtual void SetUp ()
 
virtual void TearDown ()
 

Protected Attributes

TemporaryDirectory tmpDir_ {"folly_file_test"}
 

Additional Inherited Members

- Public Types inherited from testing::Test
typedef internal::SetUpTestCaseFunc SetUpTestCaseFunc
 
typedef internal::TearDownTestCaseFunc TearDownTestCaseFunc
 
typedef internal::SetUpTestCaseFunc SetUpTestCaseFunc
 
typedef internal::TearDownTestCaseFunc TearDownTestCaseFunc
 
typedef internal::SetUpTestCaseFunc SetUpTestCaseFunc
 
typedef internal::TearDownTestCaseFunc TearDownTestCaseFunc
 
- Public Member Functions inherited from testing::Test
virtual ~Test ()
 
virtual ~Test ()
 
virtual ~Test ()
 
- Static Public Member Functions inherited from testing::Test
static void SetUpTestCase ()
 
static void TearDownTestCase ()
 
static bool HasFatalFailure ()
 
static bool HasNonfatalFailure ()
 
static bool HasFailure ()
 
static void RecordProperty (const std::string &key, const std::string &value)
 
static void RecordProperty (const std::string &key, int value)
 
static void SetUpTestCase ()
 
static void TearDownTestCase ()
 
static bool HasFatalFailure ()
 
static bool HasNonfatalFailure ()
 
static bool HasFailure ()
 
static void RecordProperty (const std::string &key, const std::string &value)
 
static void RecordProperty (const std::string &key, int value)
 
static void SetUpTestCase ()
 
static void TearDownTestCase ()
 
static bool HasFatalFailure ()
 
static bool HasNonfatalFailure ()
 
static bool HasFailure ()
 
static void RecordProperty (const std::string &key, const std::string &value)
 
static void RecordProperty (const std::string &key, int value)
 

Detailed Description

Definition at line 351 of file FileUtilTest.cpp.

Constructor & Destructor Documentation

folly::test::WriteFileAtomic::WriteFileAtomic ( )
inlineprotected

Definition at line 353 of file FileUtilTest.cpp.

353 {}

Member Function Documentation

mode_t folly::test::WriteFileAtomic::getPerms ( const string path)
inlineprotected

Definition at line 378 of file FileUtilTest.cpp.

378  {
379  return (statFile(path).st_mode & 0777);
380  }
struct stat statFile(const string &path) const
std::set<std::string> folly::test::WriteFileAtomic::listTmpDir ( ) const
inlineprotected

Definition at line 355 of file FileUtilTest.cpp.

355  {
356  std::set<std::string> entries;
357  for (auto& entry : fs::directory_iterator(tmpDir_.path())) {
358  entries.insert(entry.path().filename().string());
359  }
360  return entries;
361  }
TemporaryDirectory tmpDir_
const fs::path & path() const
Definition: TestUtil.h:116
std::string folly::test::WriteFileAtomic::readData ( const string path) const
inlineprotected

Definition at line 363 of file FileUtilTest.cpp.

References folly::data(), folly::readFile(), and folly::throwSystemError().

363  {
364  string data;
365  if (!readFile(path.c_str(), data)) {
366  throwSystemError("failed to read ", path);
367  }
368  return data;
369  }
bool readFile(int fd, Container &out, size_t num_bytes=std::numeric_limits< size_t >::max())
Definition: FileUtil.h:125
constexpr auto data(C &c) -> decltype(c.data())
Definition: Access.h:71
void throwSystemError(Args &&...args)
Definition: Exception.h:76
void folly::test::WriteFileAtomic::setDirPerms ( mode_t  mode)
inlineprotected

Definition at line 386 of file FileUtilTest.cpp.

References folly::checkUnixError(), and mode.

386  {
387  auto rc = chmod(tmpDir_.path().string().c_str(), mode);
388  checkUnixError(rc, "failed to set permissions on tmp dir");
389  }
TemporaryDirectory tmpDir_
folly::Optional< PskKeyExchangeMode > mode
void checkUnixError(ssize_t ret, Args &&...args)
Definition: Exception.h:101
const fs::path & path() const
Definition: TestUtil.h:116
struct stat folly::test::WriteFileAtomic::statFile ( const string path) const
inlineprotected

Definition at line 371 of file FileUtilTest.cpp.

References folly::checkUnixError(), and s.

371  {
372  struct stat s;
373  auto rc = stat(path.c_str(), &s);
374  checkUnixError(rc, "failed to stat() ", path);
375  return s;
376  }
void checkUnixError(ssize_t ret, Args &&...args)
Definition: Exception.h:101
static set< string > s
string folly::test::WriteFileAtomic::tmpPath ( StringPiece  name)
inlineprotected

Definition at line 382 of file FileUtilTest.cpp.

References folly::Range< Iter >::str().

382  {
383  return tmpDir_.path().string() + "/" + name.str();
384  }
TemporaryDirectory tmpDir_
const char * name
Definition: http_parser.c:437
const fs::path & path() const
Definition: TestUtil.h:116

Member Data Documentation

TemporaryDirectory folly::test::WriteFileAtomic::tmpDir_ {"folly_file_test"}
protected

Definition at line 391 of file FileUtilTest.cpp.


The documentation for this class was generated from the following file: