From 001334266a0f6d0d7da4e0eba5b5e317456a39ff Mon Sep 17 00:00:00 2001 From: Jonathan S Date: Fri, 22 Nov 2019 16:25:43 -0600 Subject: [PATCH] Don't pass `FILE_LIST_DIRECTORY` in `openDirTraverseW`. --- lib/std/fs.zig | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/std/fs.zig b/lib/std/fs.zig index 7c25895c44a3b00453e880b0259eca850236be98..aa45513e05008d114096f386fea3eb8ab182ce54 100644 --- a/lib/std/fs.zig +++ b/lib/std/fs.zig @@ -836,7 +836,7 @@ pub const Dir = struct { } } - fn openDirFlagsC(self: Dir, sub_path_c: [*]const u8, flags: u32) OpenError!Dir { + fn openDirFlagsC(self: Dir, sub_path_c: [*:0]const u8, flags: u32) OpenError!Dir { const fd = os.openatC(self.fd, sub_path_c, flags, 0) catch |err| switch (err) { error.FileTooBig => unreachable, // can't happen for directories error.IsDir => unreachable, // we're providing O_DIRECTORY @@ -850,13 +850,16 @@ pub const Dir = struct { /// Same as `openDirTraverse` except the path parameter is UTF16LE, NT-prefixed. /// This function is Windows-only. pub fn openDirTraverseW(self: Dir, sub_path_w: [*:0]const u16) OpenError!Dir { - // TODO: open without FILE_LIST_DIRECTORY - return self.openDirListW(sub_path_w); + return self.openDirAccessMaskW(sub_path_w, w.STANDARD_RIGHTS_READ | w.FILE_READ_ATTRIBUTES | w.FILE_READ_EA | w.SYNCHRONIZE | w.FILE_TRAVERSE); } /// Same as `openDirList` except the path parameter is UTF16LE, NT-prefixed. /// This function is Windows-only. pub fn openDirListW(self: Dir, sub_path_w: [*:0]const u16) OpenError!Dir { + return self.openDirAccessMaskW(sub_path_w, w.STANDARD_RIGHTS_READ | w.FILE_READ_ATTRIBUTES | w.FILE_READ_EA | w.SYNCHRONIZE | w.FILE_TRAVERSE | w.FILE_LIST_DIRECTORY); + } + + fn openDirAccessMaskW(self: Dir, sub_path_w: [*:0]const u16, access_mask: u32) OpenError!Dir { const w = os.windows; var result = Dir{ @@ -889,7 +892,7 @@ pub const Dir = struct { var io: w.IO_STATUS_BLOCK = undefined; const rc = w.ntdll.NtCreateFile( &result.fd, - w.STANDARD_RIGHTS_READ | w.FILE_READ_ATTRIBUTES | w.FILE_READ_EA | w.SYNCHRONIZE | w.FILE_TRAVERSE | w.FILE_LIST_DIRECTORY, + access_mask, &attr, &io, null, -- 2.54.0