Skip to content

Commit bb636cb

Browse files
kubkonandrewrk
authored andcommitted
Revert "Fix for Windows: std.os.windows.DeleteFile()"
1 parent 6368519 commit bb636cb

File tree

2 files changed

+1
-40
lines changed

2 files changed

+1
-40
lines changed

lib/std/fs/test.zig

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -813,26 +813,3 @@ fn run_lock_file_test(contexts: []FileLockTestContext) !void {
813813
try threads.append(try std.Thread.spawn(ctx, FileLockTestContext.run));
814814
}
815815
}
816-
817-
test "deleteDir" {
818-
var tmp_dir = tmpDir(.{});
819-
defer tmp_dir.cleanup();
820-
821-
// deleting a non-existent directory
822-
testing.expectError(error.FileNotFound, tmp_dir.dir.deleteDir("test_dir"));
823-
824-
var dir = try tmp_dir.dir.makeOpenPath("test_dir", .{});
825-
var file = try dir.createFile("test_file", .{});
826-
file.close();
827-
dir.close();
828-
829-
// deleting a non-empty directory
830-
testing.expectError(error.DirNotEmpty, tmp_dir.dir.deleteDir("test_dir"));
831-
832-
dir = try tmp_dir.dir.openDir("test_dir", .{});
833-
try dir.deleteFile("test_file");
834-
dir.close();
835-
836-
// deleting an empty directory
837-
try tmp_dir.dir.deleteDir("test_dir");
838-
}

lib/std/os/windows.zig

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -764,7 +764,6 @@ pub const DeleteFileError = error{
764764
Unexpected,
765765
NotDir,
766766
IsDir,
767-
DirNotEmpty,
768767
};
769768

770769
pub const DeleteFileOptions = struct {
@@ -819,29 +818,14 @@ pub fn DeleteFile(sub_path_w: []const u16, options: DeleteFileOptions) DeleteFil
819818
0,
820819
);
821820
switch (rc) {
822-
.SUCCESS => CloseHandle(tmp_handle),
821+
.SUCCESS => return CloseHandle(tmp_handle),
823822
.OBJECT_NAME_INVALID => unreachable,
824823
.OBJECT_NAME_NOT_FOUND => return error.FileNotFound,
825824
.INVALID_PARAMETER => unreachable,
826825
.FILE_IS_A_DIRECTORY => return error.IsDir,
827826
.NOT_A_DIRECTORY => return error.NotDir,
828827
else => return unexpectedStatus(rc),
829828
}
830-
831-
// If a directory fails to be deleted, CloseHandle will still report success
832-
// Check if the directory still exists and return error.DirNotEmpty if true
833-
if (options.remove_dir) {
834-
var basic_info: FILE_BASIC_INFORMATION = undefined;
835-
switch (ntdll.NtQueryAttributesFile(&attr, &basic_info)) {
836-
.SUCCESS => return error.DirNotEmpty,
837-
.OBJECT_NAME_NOT_FOUND => return,
838-
.OBJECT_PATH_NOT_FOUND => return,
839-
.INVALID_PARAMETER => unreachable,
840-
.ACCESS_DENIED => return error.AccessDenied,
841-
.OBJECT_PATH_SYNTAX_BAD => unreachable,
842-
else => |urc| return unexpectedStatus(urc),
843-
}
844-
}
845829
}
846830

847831
pub const MoveFileError = error{ FileNotFound, Unexpected };

0 commit comments

Comments
 (0)