we are now long paths

This commit is contained in:
chloe caruso
2025-01-15 19:35:10 -08:00
parent 5f33c877d2
commit 99ed7b278d
7 changed files with 155 additions and 32 deletions

View File

@@ -2041,7 +2041,7 @@ pub fn toWDirPath(wbuf: []u16, utf8: []const u8) [:0]const u16 {
return toWPathMaybeDir(wbuf, utf8, true);
}
pub fn toKernel32Path(wbuf: []u16, utf8: []const u8) [:0]const u16 {
pub fn toKernel32Path(wbuf: []u16, utf8: []const u8) [:0]u16 {
const path = if (hasPrefixComptime(utf8, bun.windows.nt_object_prefix_u8))
utf8[bun.windows.nt_object_prefix_u8.len..]
else
@@ -2088,6 +2088,15 @@ pub fn toWPathMaybeDir(wbuf: []u16, utf8: []const u8, comptime add_trailing_lash
wbuf[0..wbuf.len -| (1 + @as(usize, @intFromBool(add_trailing_lash)))],
);
// Many Windows APIs expect normalized path slashes, particularly when the
// long path prefix is added or the nt object prefix. To make this easier,
// but a little redundant, this function always normalizes the slashes here.
//
// An example of this is GetFileAttributesW(L"C:\\hello/world.txt") being OK
// but GetFileAttributesW(L"\\\\?\\C:\\hello/world.txt") is NOT
if (Environment.isWindows)
bun.path.dangerouslyConvertPathToWindowsInPlace(u16, wbuf[0..result.count]);
if (add_trailing_lash and result.count > 0 and wbuf[result.count - 1] != '\\') {
wbuf[result.count] = '\\';
result.count += 1;