authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-12-09 15:03:17-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-12-09 17:32:26-07:00
log1f09584d059cb5864228eb4188496decdc825584
tree03400cdb74e3f1a477d6cfd28a9bdbe5271abed7
parentcad2e8da9d10fc6f591b8da6396191735d795c80

MoveFileEx can return ACCESS_DENIED

I observed this on Windows 10, trying to use MoveFileEx with MOVEFILE_REPLACE_EXISTING | MOVEFILE_WRITE_THROUGH to overwrite a running executable.

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

lib/std/os/windows.zig+2-1
......@@ -828,7 +828,7 @@ pub fn DeleteFile(sub_path_w: []const u16, options: DeleteFileOptions) DeleteFil
828828 }
829829}
830830
831pub const MoveFileError = error{ FileNotFound, Unexpected };
831pub const MoveFileError = error{ FileNotFound, AccessDenied, Unexpected };
832832
833833pub fn MoveFileEx(old_path: []const u8, new_path: []const u8, flags: DWORD) MoveFileError!void {
834834 const old_path_w = try sliceToPrefixedFileW(old_path);
......@@ -840,6 +840,7 @@ pub fn MoveFileExW(old_path: [*:0]const u16, new_path: [*:0]const u16, flags: DW
840840 if (kernel32.MoveFileExW(old_path, new_path, flags) == 0) {
841841 switch (kernel32.GetLastError()) {
842842 .FILE_NOT_FOUND => return error.FileNotFound,
843 .ACCESS_DENIED => return error.AccessDenied,
843844 else => |err| return unexpectedError(err),
844845 }
845846 }