From 3dd439030ccc6cc9424ac03b70eab53b03f28356 Mon Sep 17 00:00:00 2001 From: Ryan Liptak Date: Fri, 18 Aug 2023 00:26:29 -0700 Subject: [PATCH] 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) --- lib/std/fs/test.zig | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/std/fs/test.zig b/lib/std/fs/test.zig index 65bb82385b..ade3fc55ab 100644 --- a/lib/std/fs/test.zig +++ b/lib/std/fs/test.zig @@ -50,15 +50,15 @@ const PathType = enum { .unc => return struct { fn transform(allocator: mem.Allocator, dir: Dir, relative_path: []const u8) TransformError![]const u8 { // Any drive absolute path (C:\foo) can be converted into a UNC path by - // using 'localhost' as the server name and '$' as the share name. + // using '127.0.0.1' as the server name and '$' as the share name. var fd_path_buf: [fs.MAX_PATH_BYTES]u8 = undefined; const dir_path = try os.getFdPath(dir.fd, &fd_path_buf); const windows_path_type = std.os.windows.getUnprefixedPathType(u8, dir_path); switch (windows_path_type) { .unc_absolute => return fs.path.join(allocator, &.{ dir_path, relative_path }), .drive_absolute => { - // `C:\<...>` -> `\\localhost\C$\<...>` - const prepended = "\\\\localhost\\"; + // `C:\<...>` -> `\\127.0.0.1\C$\<...>` + const prepended = "\\\\127.0.0.1\\"; var path = try fs.path.join(allocator, &.{ prepended, dir_path, relative_path }); path[prepended.len + 1] = '$'; return path; @@ -117,7 +117,7 @@ fn testWithAllSupportedPathTypes(test_func: anytype) !void { defer ctx.deinit(); test_func(&ctx) catch |err| { - std.debug.print("path type: {s}\n", .{enum_field.name}); + std.debug.print("{s}, path type: {s}\n", .{ @errorName(err), enum_field.name }); return err; }; }