GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fs: stat src through symlinks in cpSync() when dereference is set · gabylb/node@57a9c49

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • src
    • node_file.cc
  • test/parallel
    • test-fs-cp-dereference-symlink-to-file.mjs
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/node_file.cc‎

Copy file name to clipboardExpand all lines: src/node_file.cc
+3-5Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4567,8 +4567,8 @@ static void CpSyncCheckPaths(const FunctionCallbackInfo<Value>& args) {
45674567

45684568
std::error_code error_code;
45694569
auto src_status = dereference
4570-
? std::filesystem::symlink_status(src_path, error_code)
4571-
: std::filesystem::status(src_path, error_code);
4570+
? std::filesystem::status(src_path, error_code)
4571+
: std::filesystem::symlink_status(src_path, error_code);
45724572

45734573
if (error_code) {
45744574
#ifdef _WIN32
@@ -4586,9 +4586,7 @@ static void CpSyncCheckPaths(const FunctionCallbackInfo<Value>& args) {
45864586

45874587
bool dest_exists = !error_code && dest_status.type() !=
45884588
std::filesystem::file_type::not_found;
4589-
bool src_is_dir =
4590-
(src_status.type() == std::filesystem::file_type::directory) ||
4591-
(dereference && src_status.type() == std::filesystem::file_type::symlink);
4589+
bool src_is_dir = src_status.type() == std::filesystem::file_type::directory;
45924590

45934591
auto src_path_str = ConvertPathToUTF8(src_path);
45944592
auto dest_path_str = ConvertPathToUTF8(dest_path);
Collapse file

‎test/parallel/test-fs-cp-dereference-symlink-to-file.mjs‎

Copy file name to clipboard
+42Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// This tests that cp() and cpSync() copy the target file of a symlink passed
2+
// as src when dereference is true and recursive is not set.
3+
4+
import { mustCall, mustNotMutateObjectDeep } from '../common/index.mjs';
5+
import { nextdir } from '../common/fs.js';
6+
import assert from 'node:assert';
7+
import {
8+
cp,
9+
cpSync,
10+
lstatSync,
11+
mkdirSync,
12+
readFileSync,
13+
symlinkSync,
14+
writeFileSync,
15+
} from 'node:fs';
16+
import { join } from 'node:path';
17+
import tmpdir from '../common/tmpdir.js';
18+
19+
tmpdir.refresh();
20+
21+
const src = nextdir();
22+
mkdirSync(src);
23+
writeFileSync(join(src, 'foo.txt'), 'foo');
24+
symlinkSync(join(src, 'foo.txt'), join(src, 'link.txt'));
25+
26+
const opts = mustNotMutateObjectDeep({ dereference: true });
27+
28+
{
29+
const dest = join(nextdir(), 'foo.txt');
30+
cpSync(join(src, 'link.txt'), dest, opts);
31+
assert(lstatSync(dest).isFile());
32+
assert.strictEqual(readFileSync(dest, 'utf8'), 'foo');
33+
}
34+
35+
{
36+
const dest = join(nextdir(), 'foo.txt');
37+
cp(join(src, 'link.txt'), dest, opts, mustCall((err) => {
38+
assert.ifError(err);
39+
assert(lstatSync(dest).isFile());
40+
assert.strictEqual(readFileSync(dest, 'utf8'), 'foo');
41+
}));
42+
}

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.