Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copying a Link from One File to Another Link to the Same File errors out in isSrcSubdir #1019

Open
cowsandmilk opened this issue Oct 12, 2023 · 5 comments

Comments

@cowsandmilk
Copy link

  • Operating System: MacOS, Linux
  • Node.js version: 20.8.0, 18
  • fs-extra version: 11.1.1

Set up

touch testFile
ln -s testFile testLink1
ln -s testFile testLink2

Then, in node:

fs.copy('testLink1', 'testLink2');
Uncaught Error: Cannot copy 'testFile' to a subdirectory of itself, 'testFile'.

There are no directories involved here. The call to copyLink would succeed perfectly fine and do the correct thing in this case.

@RyanZim
Copy link
Collaborator

RyanZim commented Oct 13, 2023

Yeah, that's a bug. Out of curiosity, how does Node's experimental fs.cp behave here?

@cowsandmilk
Copy link
Author

how does Node's experimental fs.cp behave here?

apparently a similar error as fs-extra

> fs.cpSync('testLink1', 'testLink2')
Uncaught:
SystemError [ERR_FS_CP_EINVAL]: Invalid src or dest: cp returned EINVAL (cannot copy /private/tmp/node_fs_test/testFile to a subdirectory of self /private/tmp/node_fs_test/testFile) testLink2
    at __node_internal_captureLargerStackTrace (node:internal/errors:497:5)
    at new SystemError (node:internal/errors:257:5)
    at new NodeError (node:internal/errors:368:7)
    at onLink (node:internal/fs/cp/cp-sync:315:11)
    at getStats (node:internal/fs/cp/cp-sync:181:12)
    at checkParentDir (node:internal/fs/cp/cp-sync:159:10)
    at cpSyncFn (node:internal/fs/cp/cp-sync:61:10)
    at Object.cpSync (node:fs:2987:3) {
  code: 'ERR_FS_CP_EINVAL',
  info: {
    message: 'cannot copy /private/tmp/node_fs_test/testFile to a subdirectory of self /private/tmp/node_fs_test/testFile',
    path: 'testLink2',
    syscall: 'cp',
    errno: 22,
    code: 'EINVAL'
  },
  errno: [Getter/Setter: 22],
  syscall: [Getter/Setter: 'cp'],
  path: [Getter/Setter: 'testLink2']
}

@RyanZim
Copy link
Collaborator

RyanZim commented Oct 13, 2023

Yeah, fs.cp is based on fse.copy, so apparently this bug is both places. Should be raised as an issue on Node as well, so we can both fix it.

Just to make sure I understand this, in this particular case, performing a copy wouldn't actually change anything about the makeup of the filesystem, correct?

cc @manidlou

@cowsandmilk
Copy link
Author

performing a copy wouldn't actually change anything about the makeup of the filesystem, correct?

that would be my expectation

@bstst
Copy link

bstst commented Apr 29, 2024

it does indeed look like there's an issue here.

I have an electron app packaged with vite. the @electron-forge/vite-plugin does fs.copy on the files of packages in the package.json file. My project has a dependency on the @smile-cdr/fhirts package. I get this error ("src:" and "dst:" are my debug logs, just as the "catch me" tracer):

src: /Users/martin/Projects/CENSORED/node_modules/@istanbuljs/load-nyc-config/node_modules/js-yaml
dst: /var/folders/bm/ytnswbdd57b5dm28zg7x8ysc0000gn/T/electron-packager/tmp-8AxS5d/Electron.app/Contents/Resources/app/node_modules/@istanbuljs/load-nyc-config/node_modules/js-yaml

Trace: catch me
    at /Users/martin/Projects/CENSORED/node_modules/fs-extra/lib/copy/copy.js:213:19
    at FSReqCallback.oncomplete (node:fs:200:23)

An unhandled rejection has occurred inside Forge:
Error: Cannot copy '../../../../../../esprima/bin/esvalidate.js' to a subdirectory of itself, '../../../../../../esprima/bin/esvalidate.js'.
at /Users/martin/Projects/CENSORED/node_modules/fs-extra/lib/copy/copy.js:214:21
    at FSReqCallback.oncomplete (node:fs:200:23)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants