-
Notifications
You must be signed in to change notification settings - Fork 350
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
fix: use MoveFileEx for rename on win #2546
Conversation
6ad7289
to
30bc506
Compare
|
Does this work correctly for paths that contain (non-ASCII) Unicode characters? |
Could we add a test for the basic functionality? Might as well answer @eyelash's question at the same time. Probably we should also copy the "platform specific behaviour" section from https://doc.rust-lang.org/std/fs/fn.rename.html, and/or include that link. |
It is supposed to support non-ASCII, I don't see why it wouldn't, but it needs testing on a windows machine and I don't have one. |
The reason I was asking was because of these lines: std::wstring wfrom(string_cstr(from), string_cstr(from) + string_size(from));
std::wstring wto(string_cstr(to), string_cstr(to) + string_size(to)); I'm assuming that By the way just calling the standard library with UTF-8 strings on Windows often does not work for non-ASCII strings so there might be more problems in this file related to Unicode on Windows. The following page provides some more information: https://learn.microsoft.com/en-us/windows/apps/design/globalizing/use-utf8-code-page |
The conversion is the wstring constructor, or at least it's supposed to... Like I said I have no ability to test this so someone else will have to tell me if it works. |
A test file would run on Windows during CI! :-) |
I'm not sure I want to add tests which actually hit the filesystem... |
Please use the
We already have |
I'd be happy to use what is used elsewhere, I'm 100% cargo culting this code and don't do windows programming normally. But a grep for |
Bad wording, I just meant that we never use the |
Thanks! |
Head branch was pushed to by a user without write access
As discovered on Zulip, the C++ standard
std::rename
function does not overwrite the target on windows, unlike on linux and macos. https://doc.rust-lang.org/std/fs/fn.rename.html mentions that it usesMoveFileExW(from, to, MOVEFILE_REPLACE_EXISTING)
on windows to address this issue, so we implement the same fix here.