Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 5692dec

Browse filesBrowse files
npaunrichardlau
authored andcommitted
fs: fix dereference: false on cpSync
PR-URL: #59681 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com> Reviewed-By: Dario Piotrowicz <dario.piotrowicz@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent 3839593 commit 5692dec
Copy full SHA for 5692dec

File tree

Expand file treeCollapse file tree

3 files changed

+52
-41
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

3 files changed

+52
-41
lines changed
Open diff view settings
Collapse file

‎src/node_file.cc‎

Copy file name to clipboardExpand all lines: src/node_file.cc
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3132,8 +3132,8 @@ static void CpSyncCheckPaths(const FunctionCallbackInfo<Value>& args) {
31323132
errorno, dereference ? "stat" : "lstat", nullptr, src.out());
31333133
}
31343134
auto dest_status =
3135-
dereference ? std::filesystem::symlink_status(dest_path, error_code)
3136-
: std::filesystem::status(dest_path, error_code);
3135+
dereference ? std::filesystem::status(dest_path, error_code)
3136+
: std::filesystem::symlink_status(dest_path, error_code);
31373137

31383138
bool dest_exists = !error_code && dest_status.type() !=
31393139
std::filesystem::file_type::not_found;
Collapse file

‎test/known_issues/test-fs-cp-sync-dereference.js‎

Copy file name to clipboardExpand all lines: test/known_issues/test-fs-cp-sync-dereference.js
-39Lines changed: 0 additions & 39 deletions
This file was deleted.
Collapse file
+50Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
'use strict';
2+
3+
// Refs: https://github.com/nodejs/node/issues/58939
4+
//
5+
// In this test, both the cp and cpSync functions are attempting to copy
6+
// a file over a symlinked directory.
7+
8+
const common = require('../common');
9+
10+
const {
11+
cp,
12+
cpSync,
13+
mkdirSync,
14+
symlinkSync,
15+
writeFileSync,
16+
readFileSync,
17+
statSync
18+
} = require('fs');
19+
20+
const {
21+
join,
22+
} = require('path');
23+
24+
const assert = require('assert');
25+
26+
const tmpdir = require('../common/tmpdir');
27+
tmpdir.refresh();
28+
29+
const pathA = join(tmpdir.path, 'a'); // file
30+
const pathB = join(tmpdir.path, 'b'); // directory
31+
const pathC = join(tmpdir.path, 'c'); // c -> b
32+
const pathD = join(tmpdir.path, 'd'); // d -> b
33+
34+
writeFileSync(pathA, 'file a');
35+
mkdirSync(pathB);
36+
symlinkSync(pathB, pathC, 'dir');
37+
symlinkSync(pathB, pathD, 'dir');
38+
39+
cp(pathA, pathD, { dereference: false }, common.mustSucceed(() => {
40+
// The path d is now a file, not a symlink
41+
assert.strictEqual(readFileSync(pathA, 'utf-8'), readFileSync(pathD, 'utf-8'));
42+
assert.ok(statSync(pathA).isFile());
43+
assert.ok(statSync(pathD).isFile());
44+
}));
45+
46+
cpSync(pathA, pathC, { dereference: false });
47+
48+
assert.strictEqual(readFileSync(pathA, 'utf-8'), readFileSync(pathC, 'utf-8'));
49+
assert.ok(statSync(pathA).isFile());
50+
assert.ok(statSync(pathC).isFile());

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.