authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2020-09-30 00:25:35+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-09-29 19:35:44-04:00
logbb636cb3bffadf5a03e592b97a1968492f16f8cd
tree9107a9d3052791a775010e40d9ddf5b4f689c97d
parent63685190da9415ff7d27080e0f33cbeab6a80156

Revert "Fix for Windows: std.os.windows.DeleteFile()"


2 files changed, 1 insertions(+), 40 deletions(-)

lib/std/fs/test.zig-23
...@@ -813,26 +813,3 @@ fn run_lock_file_test(contexts: []FileLockTestContext) !void {...@@ -813,26 +813,3 @@ fn run_lock_file_test(contexts: []FileLockTestContext) !void {
813 try threads.append(try std.Thread.spawn(ctx, FileLockTestContext.run));813 try threads.append(try std.Thread.spawn(ctx, FileLockTestContext.run));
814 }814 }
815}815}
816
817test "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+1-17
...@@ -764,7 +764,6 @@ pub const DeleteFileError = error{...@@ -764,7 +764,6 @@ pub const DeleteFileError = error{
764 Unexpected,764 Unexpected,
765 NotDir,765 NotDir,
766 IsDir,766 IsDir,
767 DirNotEmpty,
768};767};
769768
770pub const DeleteFileOptions = struct {769pub const DeleteFileOptions = struct {
...@@ -819,7 +818,7 @@ pub fn DeleteFile(sub_path_w: []const u16, options: DeleteFileOptions) DeleteFil...@@ -819,7 +818,7 @@ pub fn DeleteFile(sub_path_w: []const u16, options: DeleteFileOptions) DeleteFil
819 0,818 0,
820 );819 );
821 switch (rc) {820 switch (rc) {
822 .SUCCESS => CloseHandle(tmp_handle),821 .SUCCESS => return CloseHandle(tmp_handle),
823 .OBJECT_NAME_INVALID => unreachable,822 .OBJECT_NAME_INVALID => unreachable,
824 .OBJECT_NAME_NOT_FOUND => return error.FileNotFound,823 .OBJECT_NAME_NOT_FOUND => return error.FileNotFound,
825 .INVALID_PARAMETER => unreachable,824 .INVALID_PARAMETER => unreachable,
...@@ -827,21 +826,6 @@ pub fn DeleteFile(sub_path_w: []const u16, options: DeleteFileOptions) DeleteFil...@@ -827,21 +826,6 @@ pub fn DeleteFile(sub_path_w: []const u16, options: DeleteFileOptions) DeleteFil
827 .NOT_A_DIRECTORY => return error.NotDir,826 .NOT_A_DIRECTORY => return error.NotDir,
828 else => return unexpectedStatus(rc),827 else => return unexpectedStatus(rc),
829 }828 }
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 }
845}829}
846830
847pub const MoveFileError = error{ FileNotFound, Unexpected };831pub const MoveFileError = error{ FileNotFound, Unexpected };