Skip to content

Bug in fs.cpSync handling of the dereference option #58939

@jasnell

Description

@jasnell

Setup:

$ cd ~/tmp
$ touch a
$ mkdir b
$ ln -s b c

Then in Node.js:

> fs.cpSync('a', 'c', { dereference: false })
Uncaught Error: Cannot overwrite directory c with non-directory a
    at cpSyncFn (node:internal/fs/cp/cp-sync:56:13)
    at Object.cpSync (node:fs:3128:3) {
  code: 'ERR_FS_CP_NON_DIR_TO_DIR'
}
> fs.cp('a', 'c', { dereference: false }, console.log)
undefined
> null undefined

The fs.cpSync call should not be throwing in this case and does not do so in Node.js v20.x. It throws in v22.x, v24.x, and main.

/cc @anonrig @nodejs/fs

Metadata

Metadata

Assignees

No one assigned

    Labels

    confirmed-bugIssues with confirmed bugs.fsIssues and PRs related to the fs subsystem / file system.regressionIssues related to regressions.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions