13 #ifndef __STOUT_WINDOWS_FS_HPP__
14 #define __STOUT_WINDOWS_FS_HPP__
37 "Failed to get realpath for '" + path+
"': " +
38 (real_path.
isError() ? real_path.
error() :
"No such directory"));
41 ULARGE_INTEGER free_bytes, total_bytes, total_free_bytes;
42 if (::GetDiskFreeSpaceExW(
46 &total_free_bytes) == 0) {
48 "Error invoking 'GetDiskFreeSpaceEx' on '" + path +
"'");
51 return Bytes(total_bytes.QuadPart);
62 "Failed to get realpath for '" + path +
"': " +
63 (real_path.
isError() ? real_path.
error() :
"No such directory"));
66 ULARGE_INTEGER free_bytes, total_bytes, total_free_bytes;
67 if (::GetDiskFreeSpaceExW(
71 &total_free_bytes) == 0) {
73 "Error invoking 'GetDiskFreeSpaceEx' on '" + path +
"'");
76 double used =
static_cast<double>(total_bytes.QuadPart - free_bytes.QuadPart);
77 return used / total_bytes.QuadPart;
82 const std::string& original,
83 const std::string& link)
95 std::list<std::string> found_files;
96 WIN32_FIND_DATAW found;
98 ::FindFirstFileW(wide_stringify(pattern).data(), &found),
101 if (search_handle.get() == INVALID_HANDLE_VALUE) {
104 int error = ::GetLastError();
105 if (error == ERROR_FILE_NOT_FOUND || error == ERROR_PATH_NOT_FOUND) {
110 "'fs::list' failed when searching for files with pattern '" +
115 const std::wstring current_file(found.cFileName);
118 if (current_file.compare(L
".") != 0 && current_file.compare(L
"..") != 0) {
119 found_files.push_back(
stringify(current_file));
121 }
while (::FindNextFileW(search_handle.get(), &found));
123 const DWORD error = ::GetLastError();
124 if (error != ERROR_NO_MORE_FILES) {
127 "'fs::list': 'FindNextFile' failed when searching for files with "
128 "'pattern '" + pattern +
"'");
136 #endif // __STOUT_WINDOWS_FS_HPP__
Definition: errorbase.hpp:35
Definition: windows.hpp:78
Result< std::string > realpath(const std::string &path)
Definition: realpath.hpp:24
static Result< T > error(const std::string &message)
Definition: result.hpp:53
Try< Nothing > symlink(const std::string &original, const std::string &link)
Definition: fs.hpp:54
Definition: error.hpp:106
Definition: result.hpp:40
Try< Bytes > size(const std::string &path="/")
Definition: fs.hpp:32
Try< std::list< std::string > > list(const std::string &pattern)
Definition: fs.hpp:75
Try< double > usage(const std::string &path="/")
Definition: fs.hpp:44
const T & get() const
Definition: result.hpp:115
std::string error(const std::string &msg, uint32_t code)
bool isSome() const
Definition: result.hpp:111
bool isError() const
Definition: result.hpp:113
std::wstring longpath(const std::string &path)
Definition: longpath.hpp:38
std::string stringify(int flags)
Try< Nothing > create_symbolic_link(const std::string &target, const std::string &reparse_point)
Definition: reparsepoint.hpp:315