aboutsummaryrefslogtreecommitdiff
path: root/lib/std/os
diff options
context:
space:
mode:
authorJakub Konka <kubkon@jakubkonka.com>2020-09-27 21:59:29 +0200
committerGitHub <noreply@github.com>2020-09-27 21:59:29 +0200
commite60939bfaafc9e6b3ccdc172009b950fc7a3eab1 (patch)
tree8b3306daa258e9adf303d1c9be2c3fbab5af0977 /lib/std/os
parent8794ce6f79886e5ebbf0476d56917e219b52c561 (diff)
parent43cd9eb110f6803f4e19d92347ebf263e6e644af (diff)
downloadzig-e60939bfaafc9e6b3ccdc172009b950fc7a3eab1.tar.gz
zig-e60939bfaafc9e6b3ccdc172009b950fc7a3eab1.zip
Merge pull request #6397 from suirad/fix-5537
Fix for Windows: std.os.windows.DeleteFile()
Diffstat (limited to 'lib/std/os')
-rw-r--r--lib/std/os/windows.zig18
1 files changed, 17 insertions, 1 deletions
diff --git a/lib/std/os/windows.zig b/lib/std/os/windows.zig
index de0d0ea45f..2aa222414f 100644
--- a/lib/std/os/windows.zig
+++ b/lib/std/os/windows.zig
@@ -764,6 +764,7 @@ pub const DeleteFileError = error{
Unexpected,
NotDir,
IsDir,
+ DirNotEmpty,
};
pub const DeleteFileOptions = struct {
@@ -818,7 +819,7 @@ pub fn DeleteFile(sub_path_w: []const u16, options: DeleteFileOptions) DeleteFil
0,
);
switch (rc) {
- .SUCCESS => return CloseHandle(tmp_handle),
+ .SUCCESS => CloseHandle(tmp_handle),
.OBJECT_NAME_INVALID => unreachable,
.OBJECT_NAME_NOT_FOUND => return error.FileNotFound,
.INVALID_PARAMETER => unreachable,
@@ -826,6 +827,21 @@ pub fn DeleteFile(sub_path_w: []const u16, options: DeleteFileOptions) DeleteFil
.NOT_A_DIRECTORY => return error.NotDir,
else => return unexpectedStatus(rc),
}
+
+ // If a directory fails to be deleted, CloseHandle will still report success
+ // Check if the directory still exists and return error.DirNotEmpty if true
+ if (options.remove_dir) {
+ var basic_info: FILE_BASIC_INFORMATION = undefined;
+ switch (ntdll.NtQueryAttributesFile(&attr, &basic_info)) {
+ .SUCCESS => return error.DirNotEmpty,
+ .OBJECT_NAME_NOT_FOUND => return,
+ .OBJECT_PATH_NOT_FOUND => return,
+ .INVALID_PARAMETER => unreachable,
+ .ACCESS_DENIED => return error.AccessDenied,
+ .OBJECT_PATH_SYNTAX_BAD => unreachable,
+ else => |urc| return unexpectedStatus(urc),
+ }
+ }
}
pub const MoveFileError = error{ FileNotFound, Unexpected };