Skip to content

Commit 7569219

Browse files
authored
fs: fix cp symlink and EEXIST handling on Windows
Fixes: #59636 Signed-off-by: Kirill Saied <sayed.kirill@gmail.com> PR-URL: #64353 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Stefan Stojanovic <stefan.stojanovic@janeasystems.com>
1 parent 874e96e commit 7569219

2 files changed

Lines changed: 13 additions & 3 deletions

File tree

src/node_file.cc

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3680,6 +3680,12 @@ std::vector<std::string> normalizePathToArray(
36803680
const std::filesystem::path& path) {
36813681
std::vector<std::string> parts;
36823682
std::filesystem::path absPath = std::filesystem::absolute(path);
3683+
#ifdef _WIN32
3684+
auto wstr = absPath.wstring();
3685+
if (wstr.starts_with(L"\\\\?\\")) {
3686+
absPath = std::filesystem::path(wstr.substr(4));
3687+
}
3688+
#endif
36833689
for (const auto& part : absPath) {
36843690
if (!part.empty()) parts.push_back(part.string());
36853691
}
@@ -3818,6 +3824,12 @@ static void CpSyncCopyDir(const FunctionCallbackInfo<Value>& args) {
38183824
}
38193825
auto symlink_target_absolute = std::filesystem::weakly_canonical(
38203826
std::filesystem::absolute(src / symlink_target));
3827+
#ifdef _WIN32
3828+
auto wstr = symlink_target_absolute.wstring();
3829+
if (wstr.starts_with(L"\\\\?\\")) {
3830+
symlink_target_absolute = std::filesystem::path(wstr.substr(4));
3831+
}
3832+
#endif
38213833
if (dir_entry.is_directory()) {
38223834
std::filesystem::create_directory_symlink(
38233835
symlink_target_absolute, dest_file_path, error);
@@ -3841,7 +3853,7 @@ static void CpSyncCopyDir(const FunctionCallbackInfo<Value>& args) {
38413853
std::filesystem::copy_file(
38423854
dir_entry.path(), dest_file_path, file_copy_opts, error);
38433855
if (error) {
3844-
if (error.value() == EEXIST) {
3856+
if (error == std::errc::file_exists) {
38453857
THROW_ERR_FS_CP_EEXIST(isolate,
38463858
"[ERR_FS_CP_EEXIST]: Target already exists: "
38473859
"cp returned EEXIST (%s already exists)",

test/parallel/parallel.status

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,8 @@ test-snapshot-incompatible: SKIP
2323
# https://github.com/nodejs/node/issues/59090
2424
test-inspector-network-fetch: PASS, FLAKY
2525
# https://github.com/nodejs/node/issues/59636
26-
test-fs-cp-sync-error-on-exist: SKIP
2726
test-fs-cp-sync-symlink-points-to-dest-error: SKIP
2827
test-fs-cp-async-symlink-points-to-dest: SKIP
29-
test-fs-cp-sync-unicode-folder-names: SKIP
3028

3129
# Windows on ARM
3230
[$system==win32 && $arch==arm64]

0 commit comments

Comments
 (0)