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

Error: EEXIST, file already exists '../mkdirp/bin/cmd.js' on fs.copySync() #94

Closed
falmp opened this issue Nov 25, 2014 · 11 comments
Closed

Comments

@falmp
Copy link

falmp commented Nov 25, 2014

When copying files with fs.copySync(), I'm getting this error:

fs.js:741
  return binding.symlink(preprocessSymlinkDestination(destination, type),
                 ^
Error: EEXIST, file already exists '../mkdirp/bin/cmd.js'
    at Object.fs.symlinkSync (fs.js:741:18)
    at copySync (/private/tmp/test/node_modules/fs-extra/lib/copy.js:83:8)
    at /private/tmp/test/node_modules/fs-extra/lib/copy.js:79:7

Here's a little script to reproduce:

package.json:

{
    "name": "test",
    "dependencies": {
        "glob": "4.2.1",
        "fs-extra": "0.12.0"
    }
}

test.js:

var glob = require('glob'),
    fs = require('fs-extra');

glob('node_modules/**/*', function(err, files) {
    files.forEach(function(file) {
        var dest = 'copy/' + file;
        console.log('copying ' + file + ' to ' + dest);
        fs.copySync(file, dest);
    });
});

I'm using node v0.10.33 on Mac OS X 10.10.1.

@falmp
Copy link
Author

falmp commented Nov 26, 2014

And here's a workaround for now:

fs.ensureDirSync(path.dirname(dest));
if (fs.statSync(file).isFile())
    fs.writeFileSync(dest, fs.readFileSync(file));

@jprichardson
Copy link
Owner

Yeah, it's because copySync has no way to clobber right now like copy. Leaving this open as a reminder to add this.

@Globegitter
Copy link

@jprichardson Hmmm, for me fs.copySync(sourcePath, destPath) just seems to overwrite the file now. I actually want it to throw an error so I can ask the user to overwrite/diff, etc.

@Globegitter
Copy link

Hmm, even if I use fs.copy() I don't manage to get an error at all, no matter what I set clobber to. And if I do

console.log('destPath exists', fs.existsSync(destPath));
console.log('sourcePath exists', fs.existsSync(sourcePath));

I get true for both. So how can I get this to throw an error, intervene, etc when a file already exists?

Edit: It seems there aren't any tests either that test the behaviour for what happens when a file already exists using copy/copySync()

@falmp
Copy link
Author

falmp commented Feb 25, 2015

Still getting an error here with latest versions:

The error is a little bit different though:

evalmachine.<anonymous>:741
  return binding.symlink(preprocessSymlinkDestination(destination, type),
                 ^
Error: EEXIST, file already exists '../rimraf/bin.js'
    at Object.fs.symlinkSync (evalmachine.<anonymous>:741:18)
    at copySync (/private/tmp/test/node_modules/fs-extra/lib/copy.js:91:8)
    at /private/tmp/test/node_modules/fs-extra/lib/copy.js:86:7
    at Array.forEach (native)
    at copySync (/private/tmp/test/node_modules/fs-extra/lib/copy.js:85:14)
    at /private/tmp/test/node_modules/fs-extra/lib/copy.js:86:7
    at Array.forEach (native)
    at copySync (/private/tmp/test/node_modules/fs-extra/lib/copy.js:85:14)
    at /private/tmp/test/node_modules/fs-extra/lib/copy.js:86:7
    at Array.forEach (native)

Here are the versions used:

package.json:

{
  "name": "test",
  "dependencies": {
    "fs-extra": "^0.16.3",
    "glob": "^4.4.0"
  }
}

@jprichardson
Copy link
Owner

By default, do you think the sensible approach is to throw an error if the destination exists? But a flag like clobber should exist to allow the user to force it if need be?

@Globegitter
Copy link

Yep, I think that would be the most sensible approach - that would be a breaking change though right?

@jprichardson
Copy link
Owner

Working on this... added clobber to copySync() for files. Will slowly make my way through all of it :) 0bed228 and a592001

@jprichardson jprichardson modified the milestone: 1.0 Jul 2, 2015
@RyanZim
Copy link
Collaborator

RyanZim commented Oct 26, 2016

@jprichardson What needs done here yet?

@jprichardson
Copy link
Owner

I believe two things:

  1. copySync() should throw an error if dest exists.
  2. copySync() should have clobber.

And now looking at my most previous commits tagged here... IDK. Weird.

@falmp or @Globegitter do you know what's still missing?

@RyanZim
Copy link
Collaborator

RyanZim commented Oct 27, 2016

@jprichardson Both these issues have been fixed.

See #296

Closing, please reopen if I missed something.

@RyanZim RyanZim closed this as completed Oct 27, 2016
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

4 participants