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

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 @@ -3210,8 +3210,8 @@ static void CpSyncCheckPaths(const FunctionCallbackInfo<Value>& args) {

std::error_code error_code;
auto src_status = dereference
? std::filesystem::symlink_status(src_path, error_code)
: std::filesystem::status(src_path, error_code);
? std::filesystem::status(src_path, error_code)
: std::filesystem::symlink_status(src_path, error_code);

if (error_code) {
#ifdef _WIN32
Expand Down
42 changes: 42 additions & 0 deletions test/parallel/test-fs-cp-sync-dereference-true.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
'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.
Comment on lines +5 to +6
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unlike the original test-fs-cp-sync-dereference.js, this one seems to test only the synchronous version.


require('../common');

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

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

const assert = require('assert');

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

const pathA = join(tmpdir.path, 'a');
const pathC = join(tmpdir.path, 'c');
const pathD = join(tmpdir.path, 'd');

writeFileSync(pathA, 'file a');
assert.ok(statSync(pathA).isFile());
symlinkSync(pathA, pathC); // c -> a
assert.ok(lstatSync(pathC).isSymbolicLink());
assert.ok(statSync(pathC).isFile());

cpSync(pathC, pathD, { dereference: true });
// d/c -> a
// d/c
assert.ok(statSync(pathD).isFile());
assert.strictEqual(readFileSync(pathD, 'utf8'), 'file a');
Loading