13 #ifndef __STOUT_OS_WINDOWS_RMDIR_HPP__
14 #define __STOUT_OS_WINDOWS_RMDIR_HPP__
18 #include <glog/logging.h>
47 const std::string& path,
bool removeRoot,
bool continueOnError)
62 const std::string current_path =
65 const std::wstring long_current_path =
72 WIN32_FIND_DATAW found;
73 const std::wstring search_pattern = long_current_path + L
"*";
75 ::FindFirstFileW(search_pattern.data(), &found), ::FindClose);
77 if (search_handle.get() == INVALID_HANDLE_VALUE) {
79 "FindFirstFile failed for pattern " +
stringify(search_pattern));
85 const std::wstring current_file(found.cFileName);
87 const bool is_current_directory = current_file.compare(L
".") == 0;
88 const bool is_parent_directory = current_file.compare(L
"..") == 0;
91 if (is_current_directory || is_parent_directory) {
96 const std::wstring current_absolute_path =
97 long_current_path + current_file;
101 stringify(current_absolute_path),
true, continueOnError);
104 if (continueOnError) {
105 LOG(WARNING) <<
"Failed to delete path "
106 <<
stringify(current_absolute_path) <<
" with error "
112 }
while (::FindNextFileW(search_handle.get(), &found));
115 const DWORD
error = ::GetLastError();
116 if (error != ERROR_NO_MORE_FILES) {
125 return Error(
"Refusing to rmdir non-directory " + current_path);
127 return os::rm(current_path);
149 const std::string& directory,
150 bool recursive =
true,
151 bool removeRoot =
true,
152 bool continueOnError =
false)
162 directory, removeRoot, continueOnError);
166 return Error(
"Refusing to rmdir non-directory " + directory);
176 #endif // __STOUT_OS_WINDOWS_RMDIR_HPP__
bool endsWith(const std::string &s, const std::string &suffix)
Definition: strings.hpp:393
Try< Nothing > rmdir(const std::string &directory, bool recursive=true, bool removeRoot=true, bool continueOnError=false)
Definition: rmdir.hpp:43
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:87
Definition: errorbase.hpp:35
Try< Nothing > rm(const std::string &path)
Definition: rm.hpp:26
Definition: windows.hpp:78
bool islink(const std::string &path)
Definition: stat.hpp:67
Definition: error.hpp:106
Try< Nothing > recursive_remove_directory(const std::string &path, bool removeRoot, bool continueOnError)
Definition: rmdir.hpp:46
process::Future< Nothing > removed(const std::string &link)
static Try error(const E &e)
Definition: try.hpp:42
bool isError() const
Definition: try.hpp:71
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:78
std::wstring longpath(const std::string &path)
Definition: longpath.hpp:38
std::string stringify(int flags)