authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-10-16 20:41:28-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-10-17 06:27:07-04:00
log877393d17ae6a7af55cc360fa10d5cc36367ce8b
tree6ae6ae3c97b341efe05cf89c374cc0f9ed0d6237
parent0b8fca5a195278bb5d5fb1ea09a504c30f751415

std.fs: fix relative symbolic links on Windows

closes #17564

2 files changed, 20 insertions(+), 1 deletions(-)

lib/std/fs/test.zig+17
......@@ -160,6 +160,23 @@ fn testReadLink(dir: Dir, target_path: []const u8, symlink_path: []const u8) !vo
160160 try testing.expectEqualStrings(target_path, given);
161161}
162162
163test "relative symlink to parent directory" {
164 var tmp = tmpDir(.{});
165 defer tmp.cleanup();
166
167 var subdir = try tmp.dir.makeOpenPath("subdir", .{});
168 defer subdir.close();
169
170 const expected_link_name = ".." ++ std.fs.path.sep_str ++ "b.txt";
171
172 try subdir.symLink(expected_link_name, "a.txt", .{});
173
174 var buf: [1000]u8 = undefined;
175 const link_name = try subdir.readLink("a.txt", &buf);
176
177 try testing.expectEqualStrings(expected_link_name, link_name);
178}
179
163180test "openDir" {
164181 try testWithAllSupportedPathTypes(struct {
165182 fn impl(ctx: *TestContext) !void {
lib/std/os/windows.zig+3-1
......@@ -766,7 +766,9 @@ pub fn CreateSymbolicLink(
766766 // it will still resolve the path relative to the root of
767767 // the C:\ drive.
768768 .rooted => break :target_path target_path,
769 else => {},
769 // Keep relative paths relative, but anything else needs to get NT-prefixed.
770 else => if (!std.fs.path.isAbsoluteWindowsWTF16(target_path))
771 break :target_path target_path,
770772 },
771773 // Already an NT path, no need to do anything to it
772774 .nt => break :target_path target_path,