authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-10-21 20:58:53-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-10-21 20:58:53-04:00
logfc6f84f3f08aca0d4e2352091cc2db2ca5779c7d
treeeff19bb866323c3403c59cdcbc99a9fa137f0cd2
parent65165554d0c6cf39ff091ace5ab5d48106a935fd

fix os.unlinkatW implementation


2 files changed, 19 insertions(+), 4 deletions(-)

lib/std/os.zig+18-4
......@@ -1045,11 +1045,24 @@ pub fn unlinkatW(dirfd: fd_t, sub_path_w: [*]const u16, flags: u32) UnlinkatErro
10451045 w.ULONG(w.FILE_DELETE_ON_CLOSE)
10461046 else
10471047 w.ULONG(w.FILE_DELETE_ON_CLOSE | w.FILE_NON_DIRECTORY_FILE);
1048 var nt_name: w.UNICODE_STRING = undefined;
1049 if (w.ntdll.RtlDosPathNameToNtPathName_U(sub_path_w, &nt_name, null, null) == 0) {
1050 return error.FileNotFound;
1048
1049 const path_len_bytes = @intCast(u16, mem.toSliceConst(u16, sub_path_w).len * 2);
1050 var nt_name = w.UNICODE_STRING{
1051 .Length = path_len_bytes,
1052 .MaximumLength = path_len_bytes,
1053 // The Windows API makes this mutable, but it will not mutate here.
1054 .Buffer = @intToPtr([*]u16, @ptrToInt(sub_path_w)),
1055 };
1056
1057 if (sub_path_w[0] == '.' and sub_path_w[1] == 0) {
1058 // Windows does not recognize this, but it does work with empty string.
1059 nt_name.Length = 0;
10511060 }
1052 defer w.ntdll.RtlFreeUnicodeString(&nt_name);
1061 if (sub_path_w[0] == '.' and sub_path_w[1] == '.' and sub_path_w[2] == 0) {
1062 // Can't remove the parent directory with an open handle.
1063 return error.FileBusy;
1064 }
1065
10531066
10541067 var attr = w.OBJECT_ATTRIBUTES{
10551068 .Length = @sizeOf(w.OBJECT_ATTRIBUTES),
......@@ -1082,6 +1095,7 @@ pub fn unlinkatW(dirfd: fd_t, sub_path_w: [*]const u16, flags: u32) UnlinkatErro
10821095 w.STATUS.OBJECT_NAME_INVALID => unreachable,
10831096 w.STATUS.OBJECT_NAME_NOT_FOUND => return error.FileNotFound,
10841097 w.STATUS.INVALID_PARAMETER => unreachable,
1098 w.STATUS.FILE_IS_A_DIRECTORY => return error.IsDir,
10851099 else => return w.unexpectedStatus(rc),
10861100 }
10871101}
lib/std/os/windows/status.zig+1
......@@ -10,3 +10,4 @@ pub const OBJECT_NAME_INVALID = 0xC0000033;
1010pub const OBJECT_NAME_NOT_FOUND = 0xC0000034;
1111pub const OBJECT_PATH_NOT_FOUND = 0xC000003A;
1212pub const OBJECT_PATH_SYNTAX_BAD = 0xC000003B;
13pub const FILE_IS_A_DIRECTORY = 0xC00000BA;