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:
182182}
183183
184184// 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).
186186fn setupSymlink(io: Io, dir: Dir, target: []const u8, link: []const u8, flags: SymLinkFlags) !void {
187187 return dir.symLink(io, target, link, flags) catch |err| switch (err) {
188 // Symlink requires admin privileges on windows, so this test can legitimately fail.
189 error.AccessDenied => if (native_os == .windows) return error.SkipZigTest else return err,
188 // On Windows, symlinks require admin privileges and the underlying filesystem must support symlinks
189 error.AccessDenied, error.PermissionDenied, error.FileSystem => if (native_os == .windows) return error.SkipZigTest else return err,
190190 else => return err,
191191 };
192192}
193193
194194// 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).
196196fn setupSymlinkAbsolute(io: Io, target: []const u8, link: []const u8, flags: SymLinkFlags) !void {
197197 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,
199200 else => return err,
200201 };
201202}
......@@ -2373,13 +2374,7 @@ test "readlinkat" {
23732374 try tmp.dir.writeFile(io, .{ .sub_path = "file.txt", .data = "nonsense" });
23742375
23752376 // create a symbolic link
2376 tmp.dir.symLink(io, "file.txt", "link", .{}) catch |err| switch (err) {
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 };
2377 try setupSymlink(io, tmp.dir, "file.txt", "link", .{});
23832378
23842379 // read the link
23852380 var buffer: [Dir.max_path_bytes]u8 = undefined;