Skip to content

Copy failed with EACCES if directory in source dirs has no write permissions #66

@isqua

Description

@isqua

How to reproduce:

  1. Create file structure like this:
mkdir -p src/bar # create nested folders
touch src/bar/test.txt # create file
chmod -w -R src # revoke write permissions
  1. Try to copy src folder with cpr:
const cpr = require('cpr')
cpr('src', 'dest', (err, res) => { if (err) throw err; console.log(res) })

It will produce this error:

Uncaught [Error: Unable to copy directory entirely] {
  list: [
    [Error: EACCES: permission denied, mkdir '/path/to/dest/bar'] {
      errno: -13,
      code: 'EACCES',
      syscall: 'mkdir',
      path: '/path/to/dest/bar'
    },
    [Error: ENOENT: no such file or directory, open 'dest/bar/test.txt'] {
      errno: -2,
      code: 'ENOENT',
      syscall: 'open',
      path: 'dest/bar/test.txt'
    }
  ]
}

I expect behaviour as original cp command has:

cp -R src dest # success
ls -l dest
total 0
dr-xr-xr-x  3 isqua isqua 102 Oct 30 22:53 ./
drwxr-xr-x 19 isqua isqua 646 Oct 30 22:53 ../
dr-xr-xr-x  3 isqua isqua 102 Oct 30 22:53 bar/
ll dest/bar
total 0
dr-xr-xr-x 3 isqua isqua 102 Oct 30 22:53 ./
dr-xr-xr-x 3 isqua isqua 102 Oct 30 22:53 ../
-r--r--r-- 1 isqua isqua   0 Oct 30 22:53 test.txt

NodeJS version: v12.18.1
cpr version: 3.0.1, 2.2.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions