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

【BUG REPORT】windows copy file to root directory error #36

Open
maxhub-fe opened this issue Aug 28, 2019 · 2 comments
Open

【BUG REPORT】windows copy file to root directory error #36

maxhub-fe opened this issue Aug 28, 2019 · 2 comments

Comments

@maxhub-fe
Copy link

const cpfile = require('cp-file');
const path = require('path')

const src = path.resolve(__dirname, './index.js');
const dest = "D:\\"
cpfile(src, dest, {
 }).on('progress', (process) => console.log(process)).then(done => console.log({done}))
 .catch(e => console.log(e));

stack:

$ node index.js
{ NestedError: Cannot create directory D:\: EPERM: operation not permitted, mkdir 'D:'
at makeDir.catch.error (d:\code\tset\node_modules\cp-file\fs.js:82:8)
Caused By: Error: EPERM: operation not permitted, mkdir 'D:'
nested:
{ Error: EPERM: operation not permitted, mkdir 'D:' errno: -4048, code: 'EPERM', syscall: 'mkdir', path: 'D:\' },
errno: -4048,
code: 'EPERM',
syscall: 'mkdir',
path: 'D:\',
name: 'CpFileError' }

I found that it was 'make-dir' cause error
mkdir

On Windows, using fs.mkdir() on the root directory even with recursion will result in an error:

fs.mkdir('/', { recursive: true }, (err) => {
  // => [Error: EPERM: operation not permitted, mkdir 'C:\']
});

@sindresorhus help plz !!!

@diegosucaria
Copy link

I was having the same issue, fixed it by forking, adding a check and using it from my repo.

if(process.platform==="win32" && path.length===3 && path[1]===':') console.log("skipping root directory")

Yeah, I know, it is ugly but it works

@kimlimjustin
Copy link

kimlimjustin commented Jul 7, 2021

It would be better if we replace
https://github.com/sindresorhus/cp-file/blob/589c637db381f93479031afaa8ab6ba907b7a957/index.js#L15

with

if(!(process.platform === "win32" && /\w:\\/.test(path.resolve(path.dirname(destination), "/")))){
        await fs.makeDir(path.dirname(destination), {mode: options.directoryMode});
}

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

No branches or pull requests

3 participants