13 #ifndef __STOUT_OS_WINDOWS_RMDIR_HPP__ 14 #define __STOUT_OS_WINDOWS_RMDIR_HPP__ 18 #include <glog/logging.h> 44 const std::string&
path,
bool removeRoot,
bool continueOnError)
59 const std::string current_path =
62 const std::wstring long_current_path =
69 WIN32_FIND_DATAW found;
70 const std::wstring search_pattern = long_current_path + L
"*";
72 ::FindFirstFileW(search_pattern.data(), &found), ::FindClose);
74 if (search_handle.get() == INVALID_HANDLE_VALUE) {
76 "FindFirstFile failed for pattern " +
stringify(search_pattern));
82 const std::wstring current_file(found.cFileName);
84 const bool is_current_directory = current_file.compare(L
".") == 0;
85 const bool is_parent_directory = current_file.compare(L
"..") == 0;
88 if (is_current_directory || is_parent_directory) {
93 const std::wstring current_absolute_path =
94 long_current_path + current_file;
98 stringify(current_absolute_path),
true, continueOnError);
101 if (continueOnError) {
102 LOG(WARNING) <<
"Failed to delete path " 103 <<
stringify(current_absolute_path) <<
" with error " 109 }
while (::FindNextFileW(search_handle.get(), &found));
112 const DWORD
error = ::GetLastError();
113 if (error != ERROR_NO_MORE_FILES) {
122 return Error(
"Refusing to rmdir non-directory " + current_path);
124 return os::rm(current_path);
146 const std::string& directory,
147 bool recursive =
true,
148 bool removeRoot =
true,
149 bool continueOnError =
false)
159 directory, removeRoot, continueOnError);
163 return Error(
"Refusing to rmdir non-directory " + directory);
173 #endif // __STOUT_OS_WINDOWS_RMDIR_HPP__ bool endsWith(const std::string &s, const std::string &suffix)
Definition: strings.hpp:402
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
bool isfile(const std::string &path, const FollowSymlink follow=FollowSymlink::FOLLOW_SYMLINK)
Definition: stat.hpp:108
Definition: errorbase.hpp:36
Try< Nothing > rm(const std::string &path)
Definition: rm.hpp:26
Definition: windows.hpp:72
bool islink(const std::string &path)
Definition: stat.hpp:80
Definition: error.hpp:108
Definition: posix_signalhandler.hpp:23
Try< Nothing > recursive_remove_directory(const std::string &path, bool removeRoot, bool continueOnError)
Definition: rmdir.hpp:43
process::Future< Nothing > removed(const std::string &link)
static Try error(const E &e)
Definition: try.hpp:43
Definition: attributes.hpp:24
bool isError() const
Definition: try.hpp:78
std::string error(const std::string &msg, uint32_t code)
bool isdir(const std::string &path, const FollowSymlink follow=FollowSymlink::FOLLOW_SYMLINK)
Definition: stat.hpp:91
std::wstring longpath(const std::string &path)
Definition: longpath.hpp:38
std::string stringify(int flags)