| ... | ... | @@ -182,20 +182,21 @@ fn testWithPathTypeIfSupported(comptime path_type: PathType, comptime path_sep: |
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | // 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). |
| 186 | 186 | fn setupSymlink(io: Io, dir: Dir, target: []const u8, link: []const u8, flags: SymLinkFlags) !void { |
| 187 | 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. |
| 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, |
| 190 | 190 | else => return err, |
| 191 | 191 | }; |
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | // 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). |
| 196 | 196 | fn setupSymlinkAbsolute(io: Io, target: []const u8, link: []const u8, flags: SymLinkFlags) !void { |
| 197 | 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 | 200 | else => return err, |
| 200 | 201 | }; |
| 201 | 202 | } |
| ... | ... | @@ -847,7 +848,16 @@ test "file operations on directories" { |
| 847 | 848 | |
| 848 | 849 | { |
| 849 | 850 | const handle = try ctx.dir.openFile(io, test_dir_name, .{ .allow_directory = true, .mode = .read_only }); |
| 850 | | handle.close(io); |
| 851 | defer handle.close(io); |
| 852 | |
| 853 | // Reading from the handle should fail |
| 854 | const expected_err = switch (native_os) { |
| 855 | .wasi => error.NotOpenForReading, |
| 856 | else => error.IsDir, |
| 857 | }; |
| 858 | var buf: [1]u8 = undefined; |
| 859 | try expectError(expected_err, handle.readStreaming(io, &.{&buf})); |
| 860 | try expectError(expected_err, handle.readPositional(io, &.{&buf}, 0)); |
| 851 | 861 | } |
| 852 | 862 | try expectError(error.IsDir, ctx.dir.openFile(io, test_dir_name, .{ .allow_directory = false, .mode = .read_only })); |
| 853 | 863 | |
| ... | ... | @@ -2364,13 +2374,7 @@ test "readlinkat" { |
| 2364 | 2374 | try tmp.dir.writeFile(io, .{ .sub_path = "file.txt", .data = "nonsense" }); |
| 2365 | 2375 | |
| 2366 | 2376 | // create a symbolic link |
| 2367 | | tmp.dir.symLink(io, "file.txt", "link", .{}) catch |err| switch (err) { |
| 2368 | | error.AccessDenied => { |
| 2369 | | // Symlink requires admin privileges on windows, so this test can legitimately fail. |
| 2370 | | if (native_os == .windows) return error.SkipZigTest; |
| 2371 | | }, |
| 2372 | | else => |e| return e, |
| 2373 | | }; |
| 2377 | try setupSymlink(io, tmp.dir, "file.txt", "link", .{}); |
| 2374 | 2378 | |
| 2375 | 2379 | // read the link |
| 2376 | 2380 | var buffer: [Dir.max_path_bytes]u8 = undefined; |