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

fs.copyFile fails if source is readonly and target is a WSL volume #44261

Open
juanrgm opened this issue Aug 17, 2022 · 2 comments
Open

fs.copyFile fails if source is readonly and target is a WSL volume #44261

juanrgm opened this issue Aug 17, 2022 · 2 comments
Labels
fs Issues and PRs related to the fs subsystem / file system.

Comments

@juanrgm
Copy link

juanrgm commented Aug 17, 2022

Version

v18.7.0

Platform

Linux 774484ed2c79 5.10.102.1-microsoft-standard-WSL2 #1 SMP Wed Mar 2 00:30:59 UTC 2022 x86_64 Linux

Subsystem

fs

What steps will reproduce the bug?

  • Command Prompt
docker run --rm -it ^
-e "CODE=require('fs').copyFileSync('/tmp/file', '/target/file')" ^
-v "%TEMP%:/target" ^
node:alpine ^
sh -c "touch /tmp/file && chmod -w /tmp/file && node -e 'eval(process.env.CODE)'"
  • Git Bash
docker run --rm -it \
-e "CODE=require('fs').copyFileSync('/tmp/file', '/target/file')" \
-v "$TEMP:/target" \
node:alpine \
sh -c "touch /tmp/file && chmod -w /tmp/file && node -e 'eval(process.env.CODE)'"

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

Always.

What is the expected behavior?

No error.

What do you see instead?

node:internal/fs/utils:348
    throw err;
    ^

Error: EACCES: permission denied, copyfile '/tmp/file' -> '/target/file'
    at Object.copyFileSync (node:fs:2866:3)
    at eval (eval at <anonymous> ([eval]:1:1), <anonymous>:1:15)
    at [eval]:1:1
    at Script.runInThisContext (node:vm:129:12)
    at Object.runInThisContext (node:vm:313:38)
    at node:internal/process/execution:76:19
    at [eval]-wrapper:6:22
    at evalScript (node:internal/process/execution:75:60)
    at node:internal/main/eval_string:27:3 {
  errno: -13,
  syscall: 'copyfile',
  code: 'EACCES',
  path: '/tmp/file',
  dest: '/target/file'
}

Additional information

@cola119 cola119 added the fs Issues and PRs related to the fs subsystem / file system. label Aug 17, 2022
juanrgm added a commit to swordev/datatruck that referenced this issue Aug 18, 2022
@prettydiff
Copy link
Contributor

prettydiff commented Aug 19, 2022

Is the file in question read protected by the operating system? If the operating system has marked a file as read protected, such that it is locked by an underlying operating system process Node will not be able to perform the necessary fs.open method on the file to access the file contents. You will not see this very often on files you, as a user or administrator, own. However, it will happen on some files at the file system root, in system32, file associated with regedit, and so forth. You should still be able to see these files with fs.readdir and fs.stat though.

See also:

@juanrgm
Copy link
Author

juanrgm commented Aug 19, 2022

But this it works:

  • Command Prompt
docker run --rm -it ^
-v "%TEMP%:/target" ^
node:alpine ^
sh -c "touch /tmp/file && chmod -w /tmp/file && cp /tmp/file /target/file"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fs Issues and PRs related to the fs subsystem / file system.
Projects
None yet
Development

No branches or pull requests

3 participants