-
Notifications
You must be signed in to change notification settings - Fork 772
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
copy can delete file content #565
Comments
Ouch, that's an ugly bug! @manidlou can you look into this? Any PR work should be against |
Sure thing! |
@TanninOne will you please try your case with |
It fixes this case but looking at the code, if I'm honest, I don't think this was solved cleanly. Also, this change doesn't fix the problem with links/junction points. I'm not sure what the best way to fix this would be. You could try to stat source and destination files and refuse to copy if they have the same ino id. |
@TanninOne I confirm that! Though one of those edge cases! I am working on it. |
Fixed by #582; will be released in v7 |
I'm so sorry to have to return to this but I feel I have to warn you about this bug in node.js: |
IMO, there's nothing we can do about it when Node.js itself has a bug. This is a problem with Node.js, not us; it's unfortunate that fs-extra users are affected by Node's bug. |
fs-extra
version: 4.0.3I realize that fs-extra 5.0.0 uses fs.copy if supported but I believe this bug to be still present and relevant when using node.js versions older than 8.5.
Since the latest stable electron version is still using node.js 8.2.1 I think this might affect a considerable number of applications.
Ok, so there was a patch to prevent copying a file onto itself, but that patch is broken or rather: it doesn't consider all possible cases, mainly: case insensitive file systems.
if (src === dest) return cb(new Error('Source and destination must not be the same.'))
will not catch cases like
copy('c:\\dummy.txt', 'C:\\dUmMy.txt')
on a case insensitive drive.But this is probably not the only possible situation where that check fails, you can easily construct a case using junction points/directory symlinks where two paths are different according to a string comparison but are actually the same file.
What happens in this case is that fs-extra creates the destination file empty, overwriting the existing file and then fails because the source file no longer exists for reading.
And to add insult to injury it leaves a file handle open so the empty file can't be removed until the application is closed.
The text was updated successfully, but these errors were encountered: