Preserve native windows paths in filesystem operations

This commit is contained in:
Augusto Domingos
2026-09-19 13:11:55 +02:00
parent f100f785da
commit 001dfea501
+13 -28
View File
@@ -477,18 +477,10 @@ bool SysFileSetLastAccessAndWriteTimeUtc(const std::filesystem::path& name,
} }
void SysFileFindFiles(const std::filesystem::path& path, std::vector<sys_file_find_t>& out) { void SysFileFindFiles(const std::filesystem::path& path, std::vector<sys_file_find_t>& out) {
std::string real_path = Common::ReplaceChar(Common::PathToGenericString(path), '\\', '/'); const auto pattern = path / L"*";
if (!real_path.ends_with("/")) {
real_path += "/";
}
std::string pattern = real_path + "*"; WIN32_FIND_DATAW data {};
HANDLE h = FindFirstFileW(pattern.c_str(), &data);
HANDLE h = nullptr;
WIN32_FIND_DATAW data;
auto wide_pattern = std::filesystem::path(pattern).wstring();
h = FindFirstFileW(wide_pattern.c_str(), &data);
if (h == INVALID_HANDLE_VALUE) { if (h == INVALID_HANDLE_VALUE) {
return; return;
@@ -496,18 +488,19 @@ void SysFileFindFiles(const std::filesystem::path& path, std::vector<sys_file_fi
do { do {
std::filesystem::path file_name(data.cFileName); std::filesystem::path file_name(data.cFileName);
auto file_name_str = Common::PathToString(file_name);
if (file_name_str == "." || file_name_str == "..") { if (file_name == L"." || file_name == L"..") {
continue; continue;
} }
const auto full_path = path / file_name;
if ((data.dwFileAttributes & static_cast<DWORD>(FILE_ATTRIBUTE_DIRECTORY)) != 0u) { if ((data.dwFileAttributes & static_cast<DWORD>(FILE_ATTRIBUTE_DIRECTORY)) != 0u) {
SysFileFindFiles(std::filesystem::path(real_path) / file_name, out); SysFileFindFiles(full_path, out);
} else { } else {
sys_file_find_t r {}; sys_file_find_t r {};
r.path_with_name = std::filesystem::path(real_path) / file_name; r.path_with_name = full_path;
r.size = (static_cast<uint64_t>(data.nFileSizeHigh) << 32u) + r.size = (static_cast<uint64_t>(data.nFileSizeHigh) << 32u) +
static_cast<uint64_t>(data.nFileSizeLow); static_cast<uint64_t>(data.nFileSizeLow);
r.last_access_time.is_invalid = false; r.last_access_time.is_invalid = false;
@@ -515,7 +508,7 @@ void SysFileFindFiles(const std::filesystem::path& path, std::vector<sys_file_fi
r.last_write_time.is_invalid = false; r.last_write_time.is_invalid = false;
r.last_write_time.time = data.ftLastWriteTime; r.last_write_time.time = data.ftLastWriteTime;
out.push_back(r); out.push_back(std::move(r));
} }
} while (FindNextFileW(h, &data) != 0); } while (FindNextFileW(h, &data) != 0);
@@ -524,18 +517,10 @@ void SysFileFindFiles(const std::filesystem::path& path, std::vector<sys_file_fi
} }
void SysFileGetDents(const std::filesystem::path& path, std::vector<sys_dir_entry_t>& out) { void SysFileGetDents(const std::filesystem::path& path, std::vector<sys_dir_entry_t>& out) {
std::string real_path = Common::ReplaceChar(Common::PathToGenericString(path), '\\', '/'); const auto pattern = path / L"*";
if (!real_path.ends_with("/")) {
real_path += "/";
}
std::string pattern = real_path + "*"; WIN32_FIND_DATAW data {};
HANDLE h = FindFirstFileW(pattern.c_str(), &data);
HANDLE h = nullptr;
WIN32_FIND_DATAW data;
auto wide_pattern = std::filesystem::path(pattern).wstring();
h = FindFirstFileW(wide_pattern.c_str(), &data);
if (h == INVALID_HANDLE_VALUE) { if (h == INVALID_HANDLE_VALUE) {
return; return;
@@ -549,7 +534,7 @@ void SysFileGetDents(const std::filesystem::path& path, std::vector<sys_dir_entr
r.is_file = ((data.dwFileAttributes & static_cast<DWORD>(FILE_ATTRIBUTE_DIRECTORY)) == 0u); r.is_file = ((data.dwFileAttributes & static_cast<DWORD>(FILE_ATTRIBUTE_DIRECTORY)) == 0u);
r.name = Common::PathToString(file_name); r.name = Common::PathToString(file_name);
out.push_back(r); out.push_back(std::move(r));
} while (FindNextFileW(h, &data) != 0); } while (FindNextFileW(h, &data) != 0);