diff --git a/src/bun.js/node/node_fs.zig b/src/bun.js/node/node_fs.zig index 634e4d3f34..b2a3ddb389 100644 --- a/src/bun.js/node/node_fs.zig +++ b/src/bun.js/node/node_fs.zig @@ -4422,7 +4422,7 @@ pub const NodeFS = struct { .err => |err| .{ .err = .{ .syscall = .scandir, .errno = err.errno, - .path = err.path, + .path = args.path.slice(), } }, .result => |result| .{ .result = result }, }; @@ -4480,7 +4480,7 @@ pub const NodeFS = struct { }) |current| : (entry = iterator.next()) { if (ExpectedType == Dirent) { if (dirent_path.isEmpty()) { - dirent_path = JSC.WebCore.Encoder.toBunString(basename, args.encoding); + dirent_path = JSC.WebCore.Encoder.toBunString(strings.withoutNTPrefix(std.meta.Child(@TypeOf(basename)), basename), args.encoding); } } if (comptime !is_u16) { @@ -4784,7 +4784,7 @@ pub const NodeFS = struct { const path_u8 = bun.path.dirname(bun.path.join(&[_]string{ root_basename, name_to_copy }, .auto), .auto); if (dirent_path_prev.isEmpty() or !bun.strings.eql(dirent_path_prev.byteSlice(), path_u8)) { dirent_path_prev.deref(); - dirent_path_prev = JSC.WebCore.Encoder.toBunString(path_u8, args.encoding); + dirent_path_prev = JSC.WebCore.Encoder.toBunString(strings.withoutNTPrefix(std.meta.Child(@TypeOf(path_u8)), path_u8), args.encoding); } dirent_path_prev.ref(); entries.append(.{ @@ -4794,10 +4794,10 @@ pub const NodeFS = struct { }) catch bun.outOfMemory(); }, Buffer => { - entries.append(Buffer.fromString(name_to_copy, bun.default_allocator) catch bun.outOfMemory()) catch bun.outOfMemory(); + entries.append(Buffer.fromString(strings.withoutNTPrefix(std.meta.Child(@TypeOf(name_to_copy)), name_to_copy), bun.default_allocator) catch bun.outOfMemory()) catch bun.outOfMemory(); }, bun.String => { - entries.append(JSC.WebCore.Encoder.toBunString(name_to_copy, args.encoding)) catch bun.outOfMemory(); + entries.append(JSC.WebCore.Encoder.toBunString(strings.withoutNTPrefix(std.meta.Child(@TypeOf(name_to_copy)), name_to_copy), args.encoding)) catch bun.outOfMemory(); }, else => @compileError(unreachable), } diff --git a/src/string_immutable.zig b/src/string_immutable.zig index 958942c050..75fe6b1441 100644 --- a/src/string_immutable.zig +++ b/src/string_immutable.zig @@ -1908,14 +1908,19 @@ pub fn fromWPath(buf: []u8, utf16: []const u16) [:0]const u8 { return buf[0..encode_into_result.written :0]; } -pub fn withoutNTPrefix(path: [:0]const u16) [:0]const u16 { - if (hasPrefixComptimeUTF16(path, &bun.windows.nt_object_prefix_u8)) { +pub fn withoutNTPrefix(comptime T: type, path: []const T) []const T { + if (comptime !Environment.isWindows) return path; + const cmp = if (T == u8) + hasPrefixComptime + else + hasPrefixComptimeUTF16; + if (cmp(path, &bun.windows.nt_object_prefix_u8)) { return path[bun.windows.nt_object_prefix.len..]; } - if (hasPrefixComptimeUTF16(path, &bun.windows.nt_maxpath_prefix_u8)) { - return path[bun.windows.nt_maxpath_prefix.len..]; + if (cmp(path, &bun.windows.long_path_prefix_u8)) { + return path[bun.windows.long_path_prefix.len..]; } - if (hasPrefixComptimeUTF16(path, &bun.windows.nt_unc_object_prefix_u8)) { + if (cmp(path, &bun.windows.nt_unc_object_prefix_u8)) { return path[bun.windows.nt_unc_object_prefix.len..]; } return path;