|
40 | 40 | #include "string_bytes.h" |
41 | 41 | #include "uv.h" |
42 | 42 |
|
| 43 | +#include <filesystem> |
| 44 | + |
43 | 45 | #if defined(__MINGW32__) || defined(_MSC_VER) |
44 | 46 | # include <io.h> |
45 | 47 | #endif |
@@ -76,12 +78,6 @@ using v8::Value; |
76 | 78 | # define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR) |
77 | 79 | #endif |
78 | 80 |
|
79 | | -#ifdef __POSIX__ |
80 | | -constexpr char kPathSeparator = '/'; |
81 | | -#else |
82 | | -const char* const kPathSeparator = "\\/"; |
83 | | -#endif |
84 | | - |
85 | 81 | inline int64_t GetOffset(Local<Value> value) { |
86 | 82 | return IsSafeJsInt(value) ? value.As<Integer>()->Value() : -1; |
87 | 83 | } |
@@ -1591,9 +1587,9 @@ int MKDirpSync(uv_loop_t* loop, |
1591 | 1587 | return err; |
1592 | 1588 | } |
1593 | 1589 | case UV_ENOENT: { |
1594 | | - std::string dirname = next_path.substr(0, |
1595 | | - next_path.find_last_of(kPathSeparator)); |
1596 | | - if (dirname != next_path) { |
| 1590 | + auto filesystem_path = std::filesystem::path(next_path); |
| 1591 | + if (filesystem_path.has_parent_path()) { |
| 1592 | + std::string dirname = filesystem_path.parent_path().string(); |
1597 | 1593 | req_wrap->continuation_data()->PushPath(std::move(next_path)); |
1598 | 1594 | req_wrap->continuation_data()->PushPath(std::move(dirname)); |
1599 | 1595 | } else if (req_wrap->continuation_data()->paths().size() == 0) { |
@@ -1671,9 +1667,9 @@ int MKDirpAsync(uv_loop_t* loop, |
1671 | 1667 | break; |
1672 | 1668 | } |
1673 | 1669 | case UV_ENOENT: { |
1674 | | - std::string dirname = path.substr(0, |
1675 | | - path.find_last_of(kPathSeparator)); |
1676 | | - if (dirname != path) { |
| 1670 | + auto filesystem_path = std::filesystem::path(path); |
| 1671 | + if (filesystem_path.has_parent_path()) { |
| 1672 | + std::string dirname = filesystem_path.parent_path().string(); |
1677 | 1673 | req_wrap->continuation_data()->PushPath(path); |
1678 | 1674 | req_wrap->continuation_data()->PushPath(std::move(dirname)); |
1679 | 1675 | } else if (req_wrap->continuation_data()->paths().size() == 0) { |
|
0 commit comments