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 {
5050 .unc => return struct {
5151 fn transform(allocator: mem.Allocator, dir: Dir, relative_path: []const u8) TransformError![]const u8 {
5252 // 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.
5454 var fd_path_buf: [fs.MAX_PATH_BYTES]u8 = undefined;
5555 const dir_path = try os.getFdPath(dir.fd, &fd_path_buf);
5656 const windows_path_type = std.os.windows.getUnprefixedPathType(u8, dir_path);
5757 switch (windows_path_type) {
5858 .unc_absolute => return fs.path.join(allocator, &.{ dir_path, relative_path }),
5959 .drive_absolute => {
60 // `C:\<...>` -> `\\localhost\C$\<...>`
61 const prepended = "\\\\localhost\\";
60 // `C:\<...>` -> `\\127.0.0.1\C$\<...>`
61 const prepended = "\\\\127.0.0.1\\";
6262 var path = try fs.path.join(allocator, &.{ prepended, dir_path, relative_path });
6363 path[prepended.len + 1] = '$';
6464 return path;
......@@ -117,7 +117,7 @@ fn testWithAllSupportedPathTypes(test_func: anytype) !void {
117117 defer ctx.deinit();
118118
119119 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 });
121121 return err;
122122 };
123123 }