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.copy fails silently if source file is /dev/null #193

Closed
raybellis opened this issue Nov 18, 2015 · 8 comments
Closed

fs.copy fails silently if source file is /dev/null #193

raybellis opened this issue Nov 18, 2015 · 8 comments

Comments

@raybellis
Copy link
Contributor

Using bluebird with fs.copyAsync, my program finished with no error despite a .catch(console.error) when I tried to copy /dev/null onto a file.

@jprichardson
Copy link
Owner

Do you get the same problem with just fs.copy?

@raybellis
Copy link
Contributor Author

It appears to fail, silently, without creating the file or calling the callback:

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

fs.copy('/dev/null', '/tmp/foo', function(err) {
    console.log('in callback');
});

(Node 4.2.1, Fedora 22)

@jprichardson
Copy link
Owner

Thanks. Verified. Just hangs on OS X 10.11 / Node 4.2.1.

Surely this is the offending line: https://github.com/jprichardson/node-fs-extra/blob/0.26.2/lib/copy/copy.js#L15

Ideas on a practical solution? I'd hate as something could be symlinked to /dev/null right? Surely others have experienced this... a cursory Google search didn't return much.

Thanks for your help.

@jprichardson
Copy link
Owner

Nope, this is the offending line:

https://github.com/jprichardson/node-fs-extra/blob/0.26.2/lib/copy/copy.js#L24

Is there something about the stats of /dev/null that I could use to reliably detect it?

@jprichardson jprichardson added this to the 1.0 milestone Dec 17, 2015
jprichardson added a commit that referenced this issue Dec 17, 2015
@raybellis
Copy link
Contributor Author

No, it's not there, either - it's the getStats() function in lib/copy/ncp.js which doesn't have a branch to take if the given file isn't either a directory, a plain file, or a symlink.

@raybellis
Copy link
Contributor Author

I think the check in that function for stats.isFile() needs the addition of:

|| stats.isBlockDevice() || stats.isCharacterDevice()

I've tried that (can branch and submit a pull request if you like). It makes the Node function behave the same way that cp does - it just treats copying /dev/null (or /dev/zero) as a copy of all available bytes from the source to the destination.

@jprichardson
Copy link
Owner

I would love a pull request :) I have a test here: 631ed20

@jprichardson
Copy link
Owner

Updated test. Thanks again for your help, it's much appreciated!

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

2 participants