Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/node_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3245,8 +3245,8 @@ static void CpSyncCheckPaths(const FunctionCallbackInfo<Value>& args) {
errorno, dereference ? "stat" : "lstat", nullptr, src.out());
}
auto dest_status =
dereference ? std::filesystem::symlink_status(dest_path, error_code)
: std::filesystem::status(dest_path, error_code);
dereference ? std::filesystem::status(dest_path, error_code)
: std::filesystem::symlink_status(dest_path, error_code);

bool dest_exists = !error_code && dest_status.type() !=
std::filesystem::file_type::not_found;
Expand Down
39 changes: 0 additions & 39 deletions test/known_issues/test-fs-cp-sync-dereference.js

This file was deleted.

50 changes: 50 additions & 0 deletions test/parallel/test-fs-cp-sync-dereference.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
'use strict';

// Refs: https://github.com/nodejs/node/issues/58939
//
// In this test, both the cp and cpSync functions are attempting to copy
// a file over a symlinked directory.

const common = require('../common');

const {
cp,
cpSync,
mkdirSync,
symlinkSync,
writeFileSync,
readFileSync,
statSync
} = require('fs');

const {
join,
} = require('path');

const assert = require('assert');

const tmpdir = require('../common/tmpdir');
tmpdir.refresh();

const pathA = join(tmpdir.path, 'a'); // file
const pathB = join(tmpdir.path, 'b'); // directory
const pathC = join(tmpdir.path, 'c'); // c -> b
const pathD = join(tmpdir.path, 'd'); // d -> b

writeFileSync(pathA, 'file a');
mkdirSync(pathB);
symlinkSync(pathB, pathC, 'dir');
symlinkSync(pathB, pathD, 'dir');

cp(pathA, pathD, { dereference: false }, common.mustSucceed(() => {
// The path d is now a file, not a symlink
assert.strictEqual(readFileSync(pathA, 'utf-8'), readFileSync(pathD, 'utf-8'));
assert.ok(statSync(pathA).isFile());
assert.ok(statSync(pathD).isFile());
}));

cpSync(pathA, pathC, { dereference: false });

assert.strictEqual(readFileSync(pathA, 'utf-8'), readFileSync(pathC, 'utf-8'));
assert.ok(statSync(pathA).isFile());
assert.ok(statSync(pathC).isFile());
Loading