From 097e290127861c62fe3d5279b724d9b412166323 Mon Sep 17 00:00:00 2001 From: chloe caruso Date: Wed, 15 Jan 2025 20:08:12 -0800 Subject: [PATCH] lalalalala --- src/bun.js/node/node_fs.zig | 2 +- src/bun.js/node/types.zig | 1 + src/resolver/resolve_path.zig | 2 -- src/string_immutable.zig | 9 ++++++--- test/js/node/test/common/tmpdir.js | 3 ++- .../node/test/parallel/test-fs-symlink-dir-junction.js | 4 +++- 6 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/bun.js/node/node_fs.zig b/src/bun.js/node/node_fs.zig index 37d60cd3ec..717676a4f2 100644 --- a/src/bun.js/node/node_fs.zig +++ b/src/bun.js/node/node_fs.zig @@ -5477,7 +5477,7 @@ pub const NodeFS = struct { if (!args.throw_if_no_entry and err.getErrno() == .NOENT) { return .{ .result = .{ .not_found = {} } }; } - break :brk .{ .err = err.withPath(path) }; + break :brk .{ .err = err.withPath(args.path.slice()) }; }, }; } diff --git a/src/bun.js/node/types.zig b/src/bun.js/node/types.zig index c8b277d4a6..e653cfb7b2 100644 --- a/src/bun.js/node/types.zig +++ b/src/bun.js/node/types.zig @@ -892,6 +892,7 @@ pub const PathLike = union(enum) { // Add the long path syntax. This affects most of node:fs const rest = path_handler.PosixToWinNormalizer.resolveCWDWithExternalBufZ(@ptrCast(buf[4..]), sliced) catch @panic("Error while resolving path."); buf[0..4].* = bun.windows.nt_maxpath_prefix_u8; + bun.path.dangerouslyConvertPathToWindowsInPlace(u8, buf[4..][0..rest.len]); return buf[0 .. 4 + rest.len :0]; } return path_handler.PosixToWinNormalizer.resolveCWDWithExternalBufZ(buf, sliced) catch @panic("Error while resolving path."); diff --git a/src/resolver/resolve_path.zig b/src/resolver/resolve_path.zig index 62b4c2ff00..dec3d1bc49 100644 --- a/src/resolver/resolve_path.zig +++ b/src/resolver/resolve_path.zig @@ -2095,8 +2095,6 @@ pub fn dangerouslyConvertPathToPosixInPlace(comptime T: type, path: []T) void { pub fn dangerouslyConvertPathToWindowsInPlace(comptime T: type, path: []T) void { var idx: usize = 0; - if (T == u16) - std.debug.print("ugh {}\n", .{bun.fmt.utf16(path)}); while (std.mem.indexOfScalarPos(T, path, idx, std.fs.path.sep_posix)) |index| : (idx = index + 1) { path[index] = '\\'; } diff --git a/src/string_immutable.zig b/src/string_immutable.zig index 857f16a724..b95ddb39f1 100644 --- a/src/string_immutable.zig +++ b/src/string_immutable.zig @@ -2049,9 +2049,12 @@ pub fn toKernel32Path(wbuf: []u16, utf8: []const u8) [:0]u16 { if (hasPrefixComptime(path, bun.windows.nt_maxpath_prefix_u8)) { return toWPath(wbuf, path); } - wbuf[0..4].* = bun.windows.nt_maxpath_prefix; - const wpath = toWPath(wbuf[4..], path); - return wbuf[0 .. wpath.len + 4 :0]; + if (utf8.len > 2 and bun.path.isDriveLetter(utf8[0]) and utf8[1] == ':' and bun.path.isSepAny(utf8[2])) { + wbuf[0..4].* = bun.windows.nt_maxpath_prefix; + const wpath = toWPath(wbuf[4..], path); + return wbuf[0 .. wpath.len + 4 :0]; + } + return toWPath(wbuf, path); } fn isUNCPath(comptime T: type, path: []const T) bool { diff --git a/test/js/node/test/common/tmpdir.js b/test/js/node/test/common/tmpdir.js index b17a00cc00..089e4d03a9 100644 --- a/test/js/node/test/common/tmpdir.js +++ b/test/js/node/test/common/tmpdir.js @@ -46,7 +46,8 @@ function refresh(useSpawn = false) { } function onexit(useSpawn) { - return; + if (process.env.KEEP_TEMP) return; + // Change directory to avoid possible EBUSY if (isMainThread) process.chdir(testRoot); diff --git a/test/js/node/test/parallel/test-fs-symlink-dir-junction.js b/test/js/node/test/parallel/test-fs-symlink-dir-junction.js index 4d5db3b444..5f46b7f826 100644 --- a/test/js/node/test/parallel/test-fs-symlink-dir-junction.js +++ b/test/js/node/test/parallel/test-fs-symlink-dir-junction.js @@ -38,7 +38,9 @@ fs.symlink(linkData, linkPath, 'junction', common.mustSucceed(() => { assert.ok(stats.isSymbolicLink()); fs.readlink(linkPath, common.mustSucceed((destination) => { - assert.strictEqual(destination, linkData); + // BUN: It was observed that Node.js 22 fails on this line, bun includes the trailing \ too. Make this test looser. + const withoutTrailingSlash = str => str.replace(/\\$/, ''); + assert.strictEqual(withoutTrailingSlash(destination), withoutTrailingSlash(linkData)); fs.unlink(linkPath, common.mustSucceed(() => { assert(!fs.existsSync(linkPath));