-
-
Notifications
You must be signed in to change notification settings - Fork 2.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
Use posix semantics when deleting files on Windows #11793
Conversation
Looks like the mac os test failed for an unrelated reason? I think this is good to go, unless there's some connection I'm missing. |
I think this is the correct approach rather than work around Windows changing file semantics in Windows 10 (found it here https://news.ycombinator.com/item?id=23745019) https://stackoverflow.com/questions/60424732/did-the-behaviour-of-deleted-files-open-with-fileshare-delete-change-on-windows The workaround with renaming sounds more cumbersome. One annoyance of all those issues is that reporters did not provide a script + program to reproduce. |
A few notes:
|
Good find, that's the stack trace that is currently blocking me, which is why I made this PR. This triggers consistently on my computer when I try to run compiler tests (
It's actually three now instead of two, deleting a file already requires
There probably are circumstances where DOS semantics are ok, however given IMO the default should be posix semantics, with a potential opt-in to DOS semantics to avoid the syscall if performance is worth introducing a possible race condition.
Ah, that's a problem. We probably need a different implementation then. It might be worth looking at another implementation like boost::fs, which implements posix semantics on windows. |
As I understand it, Zig currently has no bindings to
Thus my questions:
Update: Crossed out clarified parts. |
The relevant parts of boost (without functionality fallback) work like the following: 1. set_file_information_by_handle with file_disposition_info_ex_class for deletion; break on success;
2. ifnot ERROR_ACCESS_DENIED goto error;
3. get_file_information_by_handle_ex with file_basic_info_class (basic file info like access time and access permissions); goto error on failure;
4. set_file_information_by_handle without READ-ONLY; goto error on failure;
5. set_file_information_by_handle with file_disposition_info_ex_class for deletion; break on success;
6. set_file_information_by_handle with READ-ONLY; goto error; Thus the (only?) remaining question is, how we should deal with read-only files. Context Update: Clarified wording. |
6bd61f0
to
e3fd441
Compare
33f9fad
to
d145320
Compare
According to Microsoft, Windows 8.1 reaches end of Extended Support on January 10, 2023. source |
Not sure if/how this factors in, but needing Windows 10 >= 1607 means that builds of Windows 10 earlier than that will also not have the feature; i.e it's not new with Windows 10, it was added in a particular build of Windows 10. |
Also useful: python/cpython#84324 |
This PR can still be merged if a target OS version check is added. |
d145320
to
45307fc
Compare
45307fc
to
de163e6
Compare
Unfortunately this was never quite merge-ready. Any contributor is welcome to resurrect this PR against latest master. As far as I know it only needs a OS min version check added. |
This is the PR with requested fixups. Thanks to @SpexGuy for the original PR ziglang#11793.
When a file is deleted on Windows, it may not be immediately removed from the directory entry. This can cause problems with future scans of that directory, which will see the partially deleted file. However, it should be noted that under some workloads and system configurations, Windows files may appear to be deleted immediately. This seems to be why the CI is not failing under this bug.
This change forces file deletion to use posix semantics, removing it from the directory immediately on delete.
This fixes a bug that occurs on some windows systems/hard drives where
std.fs.Dir.deleteTree
fails due to assumed posix semantics. This may also fix rare bugs in other systems (like the cache system), which may assume posix semantics for file deletion.