authorgravatar for squeek502@hotmail.comRyan Liptak <squeek502@hotmail.com> 2026-01-07 20:47:08-08:00
committergravatar for squeek502@hotmail.comRyan Liptak <squeek502@hotmail.com> 2026-01-11 02:08:18-08:00
log4cf7dc22fa6796d231397ee38a54536d4e94f5bc
tree03dc77f0fc20bc847babd7d15c3b1703b3416af5
parentb4831403c929d429c7710d5004ec32fd0dfbd0a4

Expand the errors that act as "sym links can't be created" on Windows

Previously, the errors that are now mapped to AccessDenied, PermissionDenied, and FileSystem were all mapped to AccessDenied.

1 files changed, 7 insertions(+), 12 deletions(-)

lib/std/fs/test.zig+7-12
...@@ -182,20 +182,21 @@ fn testWithPathTypeIfSupported(comptime path_type: PathType, comptime path_sep:...@@ -182,20 +182,21 @@ fn testWithPathTypeIfSupported(comptime path_type: PathType, comptime path_sep:
182}182}
183183
184// For use in test setup. If the symlink creation fails on Windows with184// For use in test setup. If the symlink creation fails on Windows with
185// AccessDenied, then make the test failure silent (it is not a Zig failure).185// AccessDenied/PermissionDenied/FileSystem, then make the test failure silent (it is not a Zig failure).
186fn setupSymlink(io: Io, dir: Dir, target: []const u8, link: []const u8, flags: SymLinkFlags) !void {186fn setupSymlink(io: Io, dir: Dir, target: []const u8, link: []const u8, flags: SymLinkFlags) !void {
187 return dir.symLink(io, target, link, flags) catch |err| switch (err) {187 return dir.symLink(io, target, link, flags) catch |err| switch (err) {
188 // Symlink requires admin privileges on windows, so this test can legitimately fail.188 // On Windows, symlinks require admin privileges and the underlying filesystem must support symlinks
189 error.AccessDenied => if (native_os == .windows) return error.SkipZigTest else return err,189 error.AccessDenied, error.PermissionDenied, error.FileSystem => if (native_os == .windows) return error.SkipZigTest else return err,
190 else => return err,190 else => return err,
191 };191 };
192}192}
193193
194// For use in test setup. If the symlink creation fails on Windows with194// For use in test setup. If the symlink creation fails on Windows with
195// AccessDenied, then make the test failure silent (it is not a Zig failure).195// AccessDeniedPermissionDenied/FileSystem, then make the test failure silent (it is not a Zig failure).
196fn setupSymlinkAbsolute(io: Io, target: []const u8, link: []const u8, flags: SymLinkFlags) !void {196fn setupSymlinkAbsolute(io: Io, target: []const u8, link: []const u8, flags: SymLinkFlags) !void {
197 return Dir.symLinkAbsolute(io, target, link, flags) catch |err| switch (err) {197 return Dir.symLinkAbsolute(io, target, link, flags) catch |err| switch (err) {
198 error.AccessDenied => if (native_os == .windows) return error.SkipZigTest else return err,198 // On Windows, symlinks require admin privileges and the underlying filesystem must support symlinks
199 error.AccessDenied, error.PermissionDenied, error.FileSystem => if (native_os == .windows) return error.SkipZigTest else return err,
199 else => return err,200 else => return err,
200 };201 };
201}202}
...@@ -2373,13 +2374,7 @@ test "readlinkat" {...@@ -2373,13 +2374,7 @@ test "readlinkat" {
2373 try tmp.dir.writeFile(io, .{ .sub_path = "file.txt", .data = "nonsense" });2374 try tmp.dir.writeFile(io, .{ .sub_path = "file.txt", .data = "nonsense" });
23742375
2375 // create a symbolic link2376 // create a symbolic link
2376 tmp.dir.symLink(io, "file.txt", "link", .{}) catch |err| switch (err) {2377 try setupSymlink(io, tmp.dir, "file.txt", "link", .{});
2377 error.AccessDenied => {
2378 // Symlink requires admin privileges on windows, so this test can legitimately fail.
2379 if (native_os == .windows) return error.SkipZigTest;
2380 },
2381 else => |e| return e,
2382 };
23832378
2384 // read the link2379 // read the link
2385 var buffer: [Dir.max_path_bytes]u8 = undefined;2380 var buffer: [Dir.max_path_bytes]u8 = undefined;