From d0f0302468624deb8b74b407569baa6684cee6ad Mon Sep 17 00:00:00 2001 From: chloe caruso Date: Sun, 19 Jan 2025 20:47:11 -0800 Subject: [PATCH] hi --- .vscode/launch.json | 4 ++++ jj.js | 2 ++ src/bun.js/node/types.zig | 23 ++++++++++++++--------- src/string_immutable.zig | 3 +-- 4 files changed, 21 insertions(+), 11 deletions(-) create mode 100644 jj.js diff --git a/.vscode/launch.json b/.vscode/launch.json index d8efde85d1..b4149c3020 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -736,6 +736,10 @@ "name": "BUN_DEBUG_QUIET_LOGS", "value": "1", }, + { + "name": "BUN_DEBUG_SYS", + "value": "1", + }, { "name": "BUN_GARBAGE_COLLECTOR_LEVEL", "value": "2", diff --git a/jj.js b/jj.js new file mode 100644 index 0000000000..e961a4bd4d --- /dev/null +++ b/jj.js @@ -0,0 +1,2 @@ +require("fs").writeFileSync("awa2", "meowy", { flag: "a" }); +require("fs").writeFileSync("awa2", "meowy", { flag: "a" }); diff --git a/src/bun.js/node/types.zig b/src/bun.js/node/types.zig index 483c6f2573..81a7ae0d44 100644 --- a/src/bun.js/node/types.zig +++ b/src/bun.js/node/types.zig @@ -901,11 +901,14 @@ pub const PathLike = union(enum) { if (std.fs.path.isAbsolute(sliced)) { if (sliced.len > 2 and bun.path.isDriveLetter(sliced[0]) and sliced[1] == ':' and bun.path.isSepAny(sliced[2])) { // 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."); + const drive_resolve_buf = bun.PathBufferPool.get(); + defer bun.PathBufferPool.put(drive_resolve_buf); + const rest = path_handler.PosixToWinNormalizer.resolveCWDWithExternalBufZ(drive_resolve_buf, sliced) catch @panic("Error while resolving path."); buf[0..4].* = bun.windows.long_path_prefix_u8; - // When long path syntax is used, the slashes must be facing the correct direction. - bun.path.dangerouslyConvertPathToWindowsInPlace(u8, buf[4..][0..rest.len]); - return buf[0 .. 4 + rest.len :0]; + // When long path syntax is used, the entire string should be normalized + const n = bun.path.normalizeBuf(rest, buf[4..], .windows).len; + buf[4 + n] = 0; + return buf[0 .. 4 + n :0]; } return path_handler.PosixToWinNormalizer.resolveCWDWithExternalBufZ(buf, sliced) catch @panic("Error while resolving path."); } @@ -948,13 +951,15 @@ pub const PathLike = union(enum) { pub inline fn osPathKernel32(this: PathLike, buf: *bun.PathBuffer) bun.OSPathSliceZ { if (comptime Environment.isWindows) { const s = this.slice(); + const b = bun.PathBufferPool.get(); + defer bun.PathBufferPool.put(b); if (bun.strings.hasPrefixComptime(s, "/")) { - const b = bun.PathBufferPool.get(); - defer bun.PathBufferPool.put(b); - const resolve = path_handler.PosixToWinNormalizer.resolveCWDWithExternalBuf(b, s) catch @panic("Error while resolving path."); - return strings.toKernel32Path(@alignCast(std.mem.bytesAsSlice(u16, buf)), resolve); + const resolve = path_handler.PosixToWinNormalizer.resolveCWDWithExternalBuf(buf, s) catch @panic("Error while resolving path."); + const normal = path_handler.normalizeBuf(resolve, b, .windows); + return strings.toKernel32Path(@alignCast(std.mem.bytesAsSlice(u16, buf)), normal); } - return strings.toKernel32Path(@alignCast(std.mem.bytesAsSlice(u16, buf)), s); + const normal = path_handler.normalizeBuf(s, b, .windows); + return strings.toKernel32Path(@alignCast(std.mem.bytesAsSlice(u16, buf)), normal); } return sliceZWithForceCopy(this, buf, false); diff --git a/src/string_immutable.zig b/src/string_immutable.zig index 82ac457212..958942c050 100644 --- a/src/string_immutable.zig +++ b/src/string_immutable.zig @@ -2179,8 +2179,7 @@ pub fn toWPathMaybeDir(wbuf: []u16, utf8: []const u8, comptime add_trailing_lash // // 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]); + bun.path.dangerouslyConvertPathToWindowsInPlace(u16, wbuf[0..result.count]); if (add_trailing_lash and result.count > 0 and wbuf[result.count - 1] != '\\') { wbuf[result.count] = '\\';