diff options
author | 2023-07-28 18:52:04 -0700 | |
---|---|---|
committer | 2023-07-28 18:52:04 -0700 | |
commit | da7c1d84e924ce3c80c453eecd88c06e58b0c1d7 (patch) | |
tree | 4e676571f942b3cb57fcf3ce98b5d1dbb63d47fc | |
parent | aebec5b329a6bbe99142ee12d737cf0784533a58 (diff) | |
download | bun-da7c1d84e924ce3c80c453eecd88c06e58b0c1d7.tar.gz bun-da7c1d84e924ce3c80c453eecd88c06e58b0c1d7.tar.zst bun-da7c1d84e924ce3c80c453eecd88c06e58b0c1d7.zip |
Fix bug with `/path/to/absolute/bun.lockb`
-rw-r--r-- | src/install/lockfile.zig | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/src/install/lockfile.zig b/src/install/lockfile.zig index dbbb22300..7263a2c63 100644 --- a/src/install/lockfile.zig +++ b/src/install/lockfile.zig @@ -886,29 +886,32 @@ pub const Printer = struct { pub const Format = enum { yarn }; - var lockfile_path_buf1: [bun.MAX_PATH_BYTES]u8 = undefined; - var lockfile_path_buf2: [bun.MAX_PATH_BYTES]u8 = undefined; - pub fn print( allocator: Allocator, log: *logger.Log, - lockfile_path_: string, + input_lockfile_path: string, format: Format, ) !void { @setCold(true); + // We truncate longer than allowed paths. We should probably throw an error instead. + var path = input_lockfile_path[0..@min(input_lockfile_path.len, bun.MAX_PATH_BYTES)]; + + var lockfile_path_buf1: [bun.MAX_PATH_BYTES]u8 = undefined; + var lockfile_path_buf2: [bun.MAX_PATH_BYTES]u8 = undefined; + var lockfile_path: stringZ = ""; - if (!std.fs.path.isAbsolute(lockfile_path_)) { + if (!std.fs.path.isAbsolute(path)) { var cwd = try std.os.getcwd(&lockfile_path_buf1); - var parts = [_]string{lockfile_path_}; + var parts = [_]string{path}; var lockfile_path__ = Path.joinAbsStringBuf(cwd, &lockfile_path_buf2, &parts, .auto); lockfile_path_buf2[lockfile_path__.len] = 0; lockfile_path = lockfile_path_buf2[0..lockfile_path__.len :0]; - } else { - bun.copy(u8, &lockfile_path_buf1, lockfile_path); - lockfile_path_buf1[lockfile_path_.len] = 0; - lockfile_path = lockfile_path_buf1[0..lockfile_path_.len :0]; + } else if (path.len > 0) { + @memcpy(lockfile_path_buf1[0..path.len], path); + lockfile_path_buf1[path.len] = 0; + lockfile_path = lockfile_path_buf1[0..path.len :0]; } if (lockfile_path.len > 0 and lockfile_path[0] == std.fs.path.sep) |