Skip to content

Commit 8ace94d

Browse files
committed
fs: fix dereference: false on cpSync
1 parent 7178e91 commit 8ace94d

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

src/node_file.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3245,8 +3245,8 @@ static void CpSyncCheckPaths(const FunctionCallbackInfo<Value>& args) {
32453245
errorno, dereference ? "stat" : "lstat", nullptr, src.out());
32463246
}
32473247
auto dest_status =
3248-
dereference ? std::filesystem::symlink_status(dest_path, error_code)
3249-
: std::filesystem::status(dest_path, error_code);
3248+
dereference ? std::filesystem::status(dest_path, error_code)
3249+
: std::filesystem::symlink_status(dest_path, error_code);
32503250

32513251
bool dest_exists = !error_code && dest_status.type() !=
32523252
std::filesystem::file_type::not_found;

test/known_issues/test-fs-cp-sync-dereference.js renamed to test/parallel/test-fs-cp-sync-dereference.js

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,38 @@ const {
1515
mkdirSync,
1616
symlinkSync,
1717
writeFileSync,
18+
readFileSync,
19+
statSync
1820
} = require('fs');
1921

2022
const {
2123
join,
2224
} = require('path');
2325

26+
const assert = require('assert/strict');
27+
2428
const tmpdir = require('../common/tmpdir');
2529
tmpdir.refresh();
2630

27-
const pathA = join(tmpdir.path, 'a');
28-
const pathB = join(tmpdir.path, 'b');
29-
const pathC = join(tmpdir.path, 'c');
30-
const pathD = join(tmpdir.path, 'd');
31+
const pathA = join(tmpdir.path, 'a'); // file
32+
const pathB = join(tmpdir.path, 'b'); // directory
33+
const pathC = join(tmpdir.path, 'c'); // c -> b
34+
const pathD = join(tmpdir.path, 'd'); // d -> b
3135

3236
writeFileSync(pathA, 'file a');
3337
mkdirSync(pathB);
3438
symlinkSync(pathB, pathC, 'dir');
3539
symlinkSync(pathB, pathD, 'dir');
3640

37-
cp(pathA, pathD, { dereference: false }, common.mustSucceed());
41+
cp(pathA, pathD, { dereference: false }, common.mustSucceed(() => {
42+
// d is now a file, not a symlink
43+
assert.strictEqual(readFileSync(pathA, 'utf-8'), readFileSync(pathD, 'utf-8'));
44+
assert.ok(statSync(pathA).isFile());
45+
assert.ok(statSync(pathD).isFile());
46+
}));
3847

3948
cpSync(pathA, pathC, { dereference: false });
49+
50+
assert.strictEqual(readFileSync(pathA, 'utf-8'), readFileSync(pathC, 'utf-8'));
51+
assert.ok(statSync(pathA).isFile());
52+
assert.ok(statSync(pathC).isFile());

0 commit comments

Comments
 (0)