-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
EPERM when renaming files on Windows #29481
Comments
See discussion in libuv/libuv#1981 - which was subsequently reverted in response to libuv/libuv#2098. Long story short: this is not something that's really under Node's or libuv's control and the best we could do is try to work around it by means of a grace period. That's what modules like graceful-fs do, it arguably has no place in Node.js itself. |
I noticed that Windows 10 recently added some features that perhaps might help here. In particular, FILE_RENAME_POSIX_SEMANTICS and FILE_RENAME_POSIX_SEMANTICS. Posting here (instead of libuv) to get more eyeballs on this and to ask whether these are flags that libuv should try to use. |
For reference, this problem was tackled in the Go community by making |
Integrating Barring that, the only alternative I see is for the JavaScript application code to have a code path detecting this specific failure on Windows, then using low-level Windows APIs to try and detect the software holding the handles ... and terminate them/forcibly close the handles/call Windows' own rename API with whatever flags needed for the rename to work in that situation. In any case, it would make for a comparatively much more complex workaround for something that could be rather simple to implement in NodeJS's |
Use Also note that Windows Policy doesn't allow you to rename the file that is open in any other program. So, close before renaming. |
The docs for
fs.rename(oldPath, newPath, callback)
say:This happens on Linux/Mac OS X but doesn't appear to happen with Windows. If you run the following script:
You will see:
The same script runs to completion on Linux & Mac OS X without an error.
Setting
count
to a low value (e.g.2
) doesn't trigger the bug for me, so if it works for you on Windows, your computer is likely faster than mine - try setting it to something unreasonable like1000
.This could be what was happening in #6335 and appears at least tangentially related to #21957
The text was updated successfully, but these errors were encountered: