windows.DeleteFile
Does not fail on non-empty directories
#15315
Labels
bug
Observed behavior contradicts documented or intended behavior
Zig Version
0.11.0-dev.2613+b42562be7
Steps to Reproduce and Observed Behavior
Upon reading this unrelated issue: dokan-dev/dokany#883,
I learned that calling
NtCreateFile
withFILE_DELETE_ON_CLOSE
does not fail on non-empty directories, but simply mark it asDELETE_PENDING
with a successNTSTATUS
.Here are simple steps to reproduce this bug:
1- Create any folder, here i am using
C:\example
2- Create any empty file inside it
C:\example\test.txt
run the following:
deleteDir
will not complain and the folder will not be removed, which is not what the docs says hereExpected Behavior
DIRECTORY_NOT_EMPTY
/error.DirNotEmpty
should be returned.Side Note: I am mostly guessing here, and haven't looked deeply in the changes, but I think that the recent CI timeouts #14948 are caused by
windows.OpenFile
infinite looping throughDELETE_PENDING
due to this (again, i could definately be wrong here).zig/lib/std/os/windows.zig
Lines 141 to 156 in 23ac4dd
Solution/Alternative Delete Functions
I explored few solutions to resolve this bug to find out how other delete functions works:
kernel32!RemoveDirectory()
returns false and sets the last error to 145 - Directory not empty. I haven't traced it, but i assume it callsSetInformationFile
.ntdll!NtDeleteFile
Marks for deletion and silently fails as well (There is some controversy if it just setsFILE_DELETE_ON_CLOSE
).ntdll!NtSetInformationFile
withFileDispositionInformation
: this marks it for deletion and reports if not-empty.The text was updated successfully, but these errors were encountered: