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
bugfix/492 - Replace fs.link/unlink with fs.rename in fse.move #507
Conversation
Add existence check first, since rename overwrites by default. Update unit tests.
ENOTSUP is not an error returned by rename, nor link for that matter. No unit tests require it either. Documentation: http://man7.org/linux/man-pages/man2/rename.2.html, http://man7.org/linux/man-pages/man2/link.2.html
It seems we added the I'm not really comfortable with using a sync method inside an asynchronous function; this could have a significant perf hit. I also don't like manually constructing fake system-level errors, but if it's a necessary evil, then so be it. |
@RyanZim Ah, apologies, I was too excited and forgot to run the tests after the last minute change. Added the EISDIR logic back in. However, the EISDIR logic was previously in the fs.link error handler, so I am not sure if the use case still applies. I am unsure how to manually test the quirky virtual filesystem scenario. Hopefully the test case will suffice. Please let me know if you or JP have any further thoughts here. I understand your reservations about the sync method. To be clear, since the boolean overwrite check short circuits, it will only run when overwrite is not true. I can try to find a folder with many files and profile move to compare performance in this scenario. |
@manidlou I'm not comfortable merging a PR that adds sync |
@manidlou @RyanZim This fix is based off the premise of using fs.rename, which is a fix I used for this bug at work. It works in our scenario, but for fs-extra, there needs to be an existsSync check before it because otherwise it will always overwrite. It only does this check when the overwrite option is false, but that could be a majority of the time. It could be that the previous way this worked on folders, through recursively copying, would be just as slow. Due to the holidays, I haven't had time to test this theory. If that sync check doesn't suit this code base, I'm fine with closing this PR and just referencing it as a "work around" solution in the bug, in case anyone encounters the same problem, and leave it up to you as to whether to close the bug or not. |
Superseded by #549 |
Fix for: #492
"Folders become inoperable after fse.move, because fs.link isn't returning EPERM error [Mac]"
Previous move logic:
The downside to the previous logic is that the recursive copy for the folder is a heavy operation, and it took several different fs operations instead of just one. Also, in the case of this bug on Macs, fs.link would partially succeed in moving a folder instead of throwing an error, leading to an inoperable state on the folder.
Updated move logic:
Unlike fs.link, fs.rename will overwrite by default, so must do an existence check first to prevent this. I believe this is a decent tradeoff for fixing this bug and avoiding heavy recursive copy operations on folders.
Other Changes:
Ran tests/linter on both Mac and Windows.