Flutter Engine
fml::ScopedTemporaryDirectory Class Reference

#include <file.h>

Public Member Functions

 ScopedTemporaryDirectory ()
 
 ~ScopedTemporaryDirectory ()
 
const std::string & path () const
 
const UniqueFDfd ()
 

Detailed Description

Definition at line 140 of file file.h.

Constructor & Destructor Documentation

◆ ScopedTemporaryDirectory()

fml::ScopedTemporaryDirectory::ScopedTemporaryDirectory ( )

Definition at line 47 of file file.cc.

References fml::kRead, and fml::OpenDirectory().

48  : path_(CreateTemporaryDirectory()) {
49  if (path_ != "") {
50  dir_fd_ = OpenDirectory(path_.c_str(), false, FilePermission::kRead);
51  }
52 }
std::string CreateTemporaryDirectory()
Definition: file_posix.cc:23
fml::UniqueFD OpenDirectory(const char *path, bool create_if_necessary, FilePermission permission)
Definition: file_posix.cc:94

◆ ~ScopedTemporaryDirectory()

fml::ScopedTemporaryDirectory::~ScopedTemporaryDirectory ( )

Definition at line 54 of file file.cc.

References FML_LOG, fml::RemoveFilesInDirectory(), fml::UniqueObject< T, Traits >::reset(), and fml::UnlinkDirectory().

54  {
55  // POSIX requires the directory to be empty before UnlinkDirectory.
56  if (path_ != "") {
57  if (!RemoveFilesInDirectory(dir_fd_)) {
58  FML_LOG(ERROR) << "Could not clean directory: " << path_;
59  }
60  }
61 
62  // Windows has to close UniqueFD first before UnlinkDirectory
63  dir_fd_.reset();
64  if (path_ != "") {
65  if (!UnlinkDirectory(path_.c_str())) {
66  FML_LOG(ERROR) << "Could not remove directory: " << path_;
67  }
68  }
69 }
bool RemoveFilesInDirectory(const fml::UniqueFD &directory)
Definition: file.cc:102
void reset(const T &value=Traits::InvalidValue())
Definition: unique_object.h:62
#define FML_LOG(severity)
Definition: logging.h:65
bool UnlinkDirectory(const char *path)
Definition: file_posix.cc:160

Member Function Documentation

◆ fd()

const UniqueFD& fml::ScopedTemporaryDirectory::fd ( )
inline

Definition at line 147 of file file.h.

Referenced by TEST(), and flutter::testing::TEST_F().

147 { return dir_fd_; }

◆ path()

const std::string& fml::ScopedTemporaryDirectory::path ( ) const
inline

Definition at line 146 of file file.h.

Referenced by TEST(), and flutter::testing::TEST_F().

146 { return path_; }

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