Skip to content

Commit

Permalink
[fix] os.mkdir() recursive mode failed on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
pajama-coder committed Jul 26, 2024
1 parent c42fd19 commit e391b8d
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/fs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,11 +233,11 @@ auto abs_path(const std::string &filename) -> std::string {
auto len = GetFullPathNameW(inp.c_str(), sizeof(buf) / sizeof(buf[0]), buf, NULL);
if (len <= sizeof(buf) / sizeof(buf[0])) {
std::wstring ws(buf, len);
return os::windows::w2a(ws);
return os::windows::convert_slash(os::windows::w2a(ws));
}
pjs::vl_array<wchar_t, 1000> wca(len);
GetFullPathNameW(inp.c_str(), len, wca.data(), NULL);
return os::windows::w2a(std::wstring(wca, len));
return os::windows::convert_slash(os::windows::w2a(std::wstring(wca, len)));
}

bool stat(const std::string &filename, Stat &s) {
Expand All @@ -263,11 +263,13 @@ bool exists(const std::string &filename) {
bool is_dir(const std::string &filename) {
auto wpath = os::windows::convert_slash(os::windows::a2w(filename));
auto attrs = GetFileAttributesW(wpath.c_str());
return (attrs & FILE_ATTRIBUTE_DIRECTORY);
return (attrs != INVALID_FILE_ATTRIBUTES && (attrs & FILE_ATTRIBUTE_DIRECTORY));
}

bool is_file(const std::string &filename) {
return !is_dir(filename);
auto wpath = os::windows::convert_slash(os::windows::a2w(filename));
auto attrs = GetFileAttributesW(wpath.c_str());
return (attrs != INVALID_FILE_ATTRIBUTES && !(attrs & FILE_ATTRIBUTE_DIRECTORY));
}

auto get_file_time(const std::string &filename) -> double {
Expand Down

0 comments on commit e391b8d

Please sign in to comment.