Windows: Files marked as read-only fail to get deleted #13084
Labels
bug
Observed behavior contradicts documented or intended behavior
os-windows
standard library
This issue involves writing Zig code for the standard library.
Milestone
Uh oh!
There was an error while loading. Please reload this page.
Zig Version
0.10.0-dev.4247+3234e8de3
Steps to Reproduce
The
std.fs
permissions tests take special steps to undo the read-only flag before allowing the tmp_dir to be cleaned up because otherwise the file (and tmp dir) would fail to get cleaned up (due toCANNOT_DELETE
returned fromDeleteFile
):zig/lib/std/fs/test.zig
Lines 1243 to 1245 in 3234e8d
This is required; from https://learn.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-deletefile:
CANNOT_DELETE
being translated toerror.AccessDenied
was done by me in #10495 but I'm second guessing whether or not this is the correct way to go, as it means thatdeleteFile
will fail for read-only files anddeleteTree
will fail for any tree with a read-only file inside it, the latter of which is probably unexpected behavior.An alternate implementation could be to try to recover from
CANNOT_DELETE
by trying to unset the read-only flag and then retrying the delete. Where exactly this handling of deletion of read-only files should be handled I'm unsure about (at thedeleteFile
level, or only fordeleteTree
?).Expected Behavior
deleteTree
and possibilydeleteFile
successfully delete read-only files on WindowsActual Behavior
deleteFile
fails on read-only files witherror.AccessDenied
, and in turndeleteTree
fails and returnserror.AccessDenied
whenever it hits a read-only file.The text was updated successfully, but these errors were encountered: