timkendrick / recursive-copy

Simple, flexible file copy utility
97 stars 18 forks source link

Chmod randomly fails despite the file being there #7

Closed MagmaRules closed 7 years ago

MagmaRules commented 7 years ago

This chmod call in the 'finish' event randomly fails in my project:

https://github.com/timkendrick/recursive-copy/blob/ceee5fb141af808a406a21a5f43f3c2b904e0c99/lib/copy.js#L317

If I just remove the chmod and assume it actually did the copy it works. What edge case is this trying to cover?

timkendrick commented 7 years ago

Sorry to hear this has been causing you problems. Thanks for bringing this to my attention!

The chmod() was there to ensure the target file has the same permissions as the source file – e.g. if you have a read-only source file, you want to make sure its copy is also read-only. The same goes for executable files.

It turns out that this extra step was unnecessary, and you can just set the mode on the write stream directly, so I've updated it to do exactly that:

https://github.com/timkendrick/recursive-copy/blob/c7160b68df4b40c9bd00bae97f0d24f090631243/lib/copy.js#L313-L316

I've published this fix on npm as recursive-copy@2.0.7. Feel free to close this issue if the new version solves your problem, otherwise let me know if you're still having trouble.

MagmaRules commented 7 years ago

Works great thanks =)

timkendrick commented 7 years ago

No problem! Glad that fixed it for you.