Skip to content

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

Description

@juanrgm

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

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    fsIssues and PRs related to file-system APIs and the fs module.staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions