authorgravatar for squeek502@hotmail.comRyan Liptak <squeek502@hotmail.com> 2023-08-18 00:26:29-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-08-18 12:21:54-07:00
log3dd439030ccc6cc9424ac03b70eab53b03f28356
tree35f7f4d6f66cb6c9f3c2849a3ff1ef3979d832ab
parent387b0ac4f1c54cb2f83792299aa628a316e17d88

fs tests: Use 127.0.0.1 instead of localhost as the server in UNC transformation

In theory, localhost could be mapped to a different address via the LMHOSTS file, so using 127.0.0.1 should remove that potential wrinkle and allow the drive-absolute -> UNC transformation to work on any(?) setup. Also print the error name to ensure it gets printed in CI (aarch64-windows ReleaseSmall seemed not to print the error in the last intermittent UNC failure)

1 files changed, 4 insertions(+), 4 deletions(-)

lib/std/fs/test.zig+4-4
...@@ -50,15 +50,15 @@ const PathType = enum {...@@ -50,15 +50,15 @@ const PathType = enum {
50 .unc => return struct {50 .unc => return struct {
51 fn transform(allocator: mem.Allocator, dir: Dir, relative_path: []const u8) TransformError![]const u8 {51 fn transform(allocator: mem.Allocator, dir: Dir, relative_path: []const u8) TransformError![]const u8 {
52 // Any drive absolute path (C:\foo) can be converted into a UNC path by52 // Any drive absolute path (C:\foo) can be converted into a UNC path by
53 // using 'localhost' as the server name and '<drive letter>$' as the share name.53 // using '127.0.0.1' as the server name and '<drive letter>$' as the share name.
54 var fd_path_buf: [fs.MAX_PATH_BYTES]u8 = undefined;54 var fd_path_buf: [fs.MAX_PATH_BYTES]u8 = undefined;
55 const dir_path = try os.getFdPath(dir.fd, &fd_path_buf);55 const dir_path = try os.getFdPath(dir.fd, &fd_path_buf);
56 const windows_path_type = std.os.windows.getUnprefixedPathType(u8, dir_path);56 const windows_path_type = std.os.windows.getUnprefixedPathType(u8, dir_path);
57 switch (windows_path_type) {57 switch (windows_path_type) {
58 .unc_absolute => return fs.path.join(allocator, &.{ dir_path, relative_path }),58 .unc_absolute => return fs.path.join(allocator, &.{ dir_path, relative_path }),
59 .drive_absolute => {59 .drive_absolute => {
60 // `C:\<...>` -> `\\localhost\C$\<...>`60 // `C:\<...>` -> `\\127.0.0.1\C$\<...>`
61 const prepended = "\\\\localhost\\";61 const prepended = "\\\\127.0.0.1\\";
62 var path = try fs.path.join(allocator, &.{ prepended, dir_path, relative_path });62 var path = try fs.path.join(allocator, &.{ prepended, dir_path, relative_path });
63 path[prepended.len + 1] = '$';63 path[prepended.len + 1] = '$';
64 return path;64 return path;
...@@ -117,7 +117,7 @@ fn testWithAllSupportedPathTypes(test_func: anytype) !void {...@@ -117,7 +117,7 @@ fn testWithAllSupportedPathTypes(test_func: anytype) !void {
117 defer ctx.deinit();117 defer ctx.deinit();
118118
119 test_func(&ctx) catch |err| {119 test_func(&ctx) catch |err| {
120 std.debug.print("path type: {s}\n", .{enum_field.name});120 std.debug.print("{s}, path type: {s}\n", .{ @errorName(err), enum_field.name });
121 return err;121 return err;
122 };122 };
123 }123 }