13 #ifndef __STOUT_OS_POSIX_RMDIR_HPP__ 14 #define __STOUT_OS_POSIX_RMDIR_HPP__ 20 #include <glog/logging.h> 41 #ifndef __sun // FTS is not available on Solaris. 43 const std::string& directory,
44 bool recursive =
true,
45 bool removeRoot =
true,
46 bool continueOnError =
false)
48 unsigned int errorCount = 0;
51 if (::
rmdir(directory.c_str()) < 0) {
62 char*
paths[] = {
const_cast<char*
>(directory.c_str()),
nullptr};
66 FTS* tree = fts_open(paths, (FTS_NOCHDIR | FTS_PHYSICAL),
nullptr);
67 if (tree ==
nullptr) {
72 while ((node = fts_read(tree)) !=
nullptr) {
73 switch (node->fts_info) {
77 if (!removeRoot && node->fts_level == FTS_ROOTLEVEL) {
81 if (::
rmdir(node->fts_path) < 0 && errno != ENOENT) {
82 if (continueOnError) {
83 LOG(ERROR) <<
"Failed to delete directory '" << node->fts_path
101 if (::unlink(node->fts_path) < 0 && errno != ENOENT) {
102 if (continueOnError) {
103 LOG(ERROR) <<
"Failed to delete path '" << node->fts_path
124 if (fts_close(tree) < 0) {
129 if (errorCount > 0) {
130 return Error(
"Failed to delete " +
stringify(errorCount) +
" paths");
140 #endif // __STOUT_OS_POSIX_RMDIR_HPP__ std::string strerror(int errno_)
A thread-safe version of strerror.
Definition: strerror.hpp:30
Try< Nothing > rmdir(const std::string &directory, bool recursive=true, bool removeRoot=true, bool continueOnError=false)
Definition: rmdir.hpp:42
bool exists(const std::string &path)
Definition: exists.hpp:26
Definition: nothing.hpp:16
Definition: errorbase.hpp:36
std::string paths()
Definition: os.hpp:138
Definition: errorbase.hpp:50
Definition: posix_signalhandler.hpp:23
std::string error(const std::string &msg, uint32_t code)
std::string stringify(int flags)