-
Notifications
You must be signed in to change notification settings - Fork 13.4k
std: Make unlink() more consistent #15227
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
Conversation
Just for completeness: did you consider doing the reverse (rejecting |
@huonw That would be completely wrong in Unix, since unlink removes the name from the directory, which has nothing to do with whether the file is writable or not, but depends of course on whether the directory is writable or not. @alexcrichton However, the code seems to suffer from race conditions, since it will fail if someone unsets the read-only attribute just after the unlink fails, but it looks like this race condition is unfixable if ERROR_ACCESS_DENIED is returned for other errors too (however, retrying N times might be better). It appears, from web searches (https://vtopan.wordpress.com/2009/05/26/using-ntdeletefile-from-delphi/), that the NT API NtDeleteFile will delete read-only files too (and also delete the file immediately, like Unix): maybe that could be the best solution if it's indeed the case. |
I suppose I hadn't given it an overwhelming amount of thought, no! I suppose I conceptually would rather just delete a file when I call |
That is correct, and this was written with that in mind. I would think that essentially any filesystem interaction is inherently racy, however, so trying to protect this one case on windows may not be buying us much.
Interesting! I was under the impression that |
Currently when a read-only file has unlink() invoked on it on windows, the call will fail. On unix, however, the call will succeed. In order to have a more consistent behavior across platforms, this error is recognized on windows and the file is changed to read-write before removal is attempted.
Currently when a read-only file has unlink() invoked on it on windows, the call will fail. On unix, however, the call will succeed. In order to have a more consistent behavior across platforms, this error is recognized on windows and the file is changed to read-write before removal is attempted.
…nicola fix: Indent after pressing enter on a blank line Regressed after rust-lang/rust-analyzer#13975 (whoops).
Currently when a read-only file has unlink() invoked on it on windows, the call
will fail. On unix, however, the call will succeed. In order to have a more
consistent behavior across platforms, this error is recognized on windows and
the file is changed to read-write before removal is attempted.