| ... | ... | @@ -5,7 +5,6 @@ const builtin = @import("builtin"); |
| 5 | 5 | |
| 6 | 6 | const std = @import("std"); |
| 7 | 7 | const Io = std.Io; |
| 8 | | const Allocator = std.mem.Allocator; |
| 9 | 8 | |
| 10 | 9 | pub fn main() !void { |
| 11 | 10 | if (builtin.target.os.tag == .wasi) return; // Can link, but can't change into tmpDir |
| ... | ... | @@ -24,37 +23,9 @@ pub fn main() !void { |
| 24 | 23 | // Want to test relative paths, so cd into the tmpdir for these tests |
| 25 | 24 | try std.process.setCurrentDir(io, tmp.dir); |
| 26 | 25 | |
| 27 | | try test_symlink(gpa, io, tmp); |
| 28 | 26 | try test_link(io, tmp); |
| 29 | 27 | } |
| 30 | 28 | |
| 31 | | fn test_symlink(gpa: Allocator, io: Io, tmp: TmpDir) !void { |
| 32 | | const target_name = "symlink-target"; |
| 33 | | const symlink_name = "symlinker"; |
| 34 | | |
| 35 | | // Create the target file |
| 36 | | try tmp.dir.writeFile(io, .{ .sub_path = target_name, .data = "nonsense" }); |
| 37 | | |
| 38 | | if (builtin.target.os.tag == .windows) { |
| 39 | | const wtarget_name = try std.unicode.wtf8ToWtf16LeAllocZ(gpa, target_name); |
| 40 | | const wsymlink_name = try std.unicode.wtf8ToWtf16LeAllocZ(gpa, symlink_name); |
| 41 | | defer gpa.free(wtarget_name); |
| 42 | | defer gpa.free(wsymlink_name); |
| 43 | | |
| 44 | | std.os.windows.CreateSymbolicLink(tmp.dir.fd, wsymlink_name, wtarget_name, false) catch |err| switch (err) { |
| 45 | | // Symlink requires admin privileges on windows, so this test can legitimately fail. |
| 46 | | error.AccessDenied => return, |
| 47 | | else => return err, |
| 48 | | }; |
| 49 | | } else { |
| 50 | | try Io.Dir.cwd().symLink(io, target_name, symlink_name, .{}); |
| 51 | | } |
| 52 | | |
| 53 | | var buffer: [std.fs.max_path_bytes]u8 = undefined; |
| 54 | | const given = buffer[0..try Io.Dir.cwd().readLink(io, symlink_name, &buffer)]; |
| 55 | | try std.testing.expectEqualStrings(target_name, given); |
| 56 | | } |
| 57 | | |
| 58 | 29 | fn test_link(io: Io, tmp: TmpDir) !void { |
| 59 | 30 | switch (builtin.target.os.tag) { |
| 60 | 31 | .linux, .illumos => {}, |