proxygen
folly::test::TemporaryDirectory Class Reference

#include <TestUtil.h>

Public Types

enum  Scope { Scope::PERMANENT, Scope::DELETE_ON_DESTRUCTION }
 

Public Member Functions

 TemporaryDirectory (StringPiece namePrefix=StringPiece(), fs::path dir=fs::path(), Scope scope=Scope::DELETE_ON_DESTRUCTION)
 
 ~TemporaryDirectory ()
 
 TemporaryDirectory (TemporaryDirectory &&)=default
 
TemporaryDirectoryoperator= (TemporaryDirectory &&)=default
 
const fs::path & path () const
 

Private Attributes

Scope scope_
 
std::unique_ptr< fs::path > path_
 

Detailed Description

Temporary directory.

By default, the temporary directory is created in a system-specific location (the value of the TMPDIR environment variable, or /tmp), but you can override that with a non-empty directory passed to the constructor.

By default, the directory is recursively deleted when the TemporaryDirectory object is destroyed, but that can be overridden with an argument to the constructor.

Definition at line 100 of file TestUtil.h.

Member Enumeration Documentation

Enumerator
PERMANENT 
DELETE_ON_DESTRUCTION 

Definition at line 102 of file TestUtil.h.

102  {
103  PERMANENT,
104  DELETE_ON_DESTRUCTION,
105  };

Constructor & Destructor Documentation

folly::test::TemporaryDirectory::TemporaryDirectory ( StringPiece  namePrefix = StringPiece(),
fs::path  dir = fs::path(),
Scope  scope = Scope::DELETE_ON_DESTRUCTION 
)
explicit

Definition at line 113 of file TestUtil.cpp.

References path().

117  : scope_(scope),
118  path_(std::make_unique<fs::path>(
119  generateUniquePath(std::move(dir), namePrefix))) {
120  fs::create_directory(path());
121 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
std::unique_ptr< fs::path > path_
Definition: TestUtil.h:122
const fs::path & path() const
Definition: TestUtil.h:116
folly::test::TemporaryDirectory::~TemporaryDirectory ( )

Definition at line 123 of file TestUtil.cpp.

References DELETE_ON_DESTRUCTION, path(), path_, scope_, and folly::WARNING.

123  {
124  if (scope_ == Scope::DELETE_ON_DESTRUCTION && path_ != nullptr) {
125  boost::system::error_code ec;
126  fs::remove_all(path(), ec);
127  if (ec) {
128  LOG(WARNING) << "recursive delete on destruction failed: " << ec;
129  }
130  }
131 }
std::unique_ptr< fs::path > path_
Definition: TestUtil.h:122
const fs::path & path() const
Definition: TestUtil.h:116
folly::test::TemporaryDirectory::TemporaryDirectory ( TemporaryDirectory &&  )
default

Member Function Documentation

TemporaryDirectory& folly::test::TemporaryDirectory::operator= ( TemporaryDirectory &&  )
default
const fs::path& folly::test::TemporaryDirectory::path ( ) const
inline

Member Data Documentation

std::unique_ptr<fs::path> folly::test::TemporaryDirectory::path_
private

Definition at line 122 of file TestUtil.h.

Referenced by ~TemporaryDirectory().

Scope folly::test::TemporaryDirectory::scope_
private

Definition at line 121 of file TestUtil.h.

Referenced by ~TemporaryDirectory().


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