-
Notifications
You must be signed in to change notification settings - Fork 13.3k
fs::rename fails when dest exists only on windows #31301
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
Comments
I opened this awhile ago as #15836 and closed that as "not a bug" because we're just exporting the system's behavior. I'm personally inclined to say that this is something we shouldn't handle in the standard library (but may wish to document) |
FYI, Java 7 introduced |
Interestingly, the option |
I'd be wary of making a core operation like this do more than one I/O operation as it'd be tough to ensure that it remains "transactional". We already attempt to make Windows/Unix behave the same by passing the flag @retep998 mentioned, and the remaining behavior is something I'd prefer to just document. |
I'm not suggesting that the standard library do that, documenting the current behavior should be sufficient. It's just a workaround that users can easily use right now if they do want that sort of behavior on Windows. |
I tested |
Describe more platform-specific behaviors of `std::fs::rename` I did some tests myself regarding the situation when both `from` and `to` exist, and the results were: On Linux: `from` | `to` | Result ---- | ---- | ---- Directory | Directory | Ok Directory | File | Error File | Directory | Error File | File | Ok On Windows: `from` | `to` | Result ---- | ---- | ---- Directory | Directory | Error Directory | File | Ok File | Directory | Error File | File | Ok This is a bit against the official MSDN documentation, which says "(`MOVEFILE_REPLACE_EXISTING`) cannot be used if `lpNewFileName` or `lpExistingFileName` names a directory." As evidenced above, `lpExistingFileName` *can* be a directory. I also mentioned the atomicity of the operation. Fixes #31301.
This code fails on windows, not on linux:
with
The text was updated successfully, but these errors were encountered: