Skip to content

fs.cp/fs.cpSync convert relative symlinks to absolute symlinks #41693

Closed
@marcosbc

Description

@marcosbc

Version

v16.13.2

Platform

Linux mbdev 4.15.0-142-generic #146~16.04.1-Ubuntu SMP Tue Apr 13 09:27:15 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

Subsystem

No response

What steps will reproduce the bug?

Create the following folder structure (see example code below):

.
├── test1
│   ├── bar -> foo
│   └── foo
└── test2

This can be achieved with the following commands:

$ mkdir test1 test2
$ touch test1/foo
$ ln -s foo test1/bar

Afterwards, execute the following command in your Node.js console:

$ fs.cpSync('test1', 'test2', {recursive: true});

How often does it reproduce? Is there a required condition?

This happens in all Node.js releases from 16.7.0, where fs.cp and fs.cpSync are supported.

What is the expected behavior?

Given the above example, it would be expected for the test2 folder to contain a relative symlink bar, same than test1, since the action is expected to replicate the entire structure from one folder to another, i.e.:

.
├── test1
│   ├── bar -> foo
│   └── foo
└── test2
    ├── bar -> foo
    └── foo

What do you see instead?

Given the above example, the symlinks are converted to absolute symlinks, and also pointing to the "previous" path, i.e.:

.
├── test1
│   ├── bar -> foo
│   └── foo
└── test2
    ├── bar -> /tmp/nodejs-cp-error/test1/foo
    └── foo

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestIssues that request new features to be added to Node.js.fsIssues and PRs related to the fs subsystem / file system.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions