From 0edd8d262da4409f1e5566c47bfed9b3f23636b7 Mon Sep 17 00:00:00 2001 From: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> Date: Sun, 19 Mar 2023 20:58:16 -0700 Subject: Fix bug with scoped aliased dependencies in bun install on macOS --- src/c.zig | 2 ++ src/install/install.zig | 5 ++--- src/string_immutable.zig | 12 ++++++++++++ 3 files changed, 16 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/c.zig b/src/c.zig index d6417bad2..3e9193069 100644 --- a/src/c.zig +++ b/src/c.zig @@ -42,6 +42,8 @@ pub const lstat = lstat64; pub const fstat = fstat64; pub const stat = stat64; +pub extern "c" fn strchr(str: [*]const u8, char: u8) ?[*]const u8; + pub fn lstat_absolute(path: [:0]const u8) !Stat { if (builtin.os.tag == .windows) { @compileError("Not implemented yet"); diff --git a/src/install/install.zig b/src/install/install.zig index 0927c9335..b8509f50a 100644 --- a/src/install/install.zig +++ b/src/install/install.zig @@ -1058,9 +1058,8 @@ const PackageInstall = struct { fn installWithClonefile(this: *PackageInstall) CloneFileError!Result { if (comptime !Environment.isMac) @compileError("clonefileat() is macOS only."); - if (this.package_name[0] == '@') { - const current = bun.span(this.destination_dir_subpath); - if (strings.indexOfChar(current, std.fs.path.sep)) |slash| { + if (this.destination_dir_subpath[0] == '@') { + if (strings.indexOfCharZ(this.destination_dir_subpath, std.fs.path.sep)) |slash| { this.destination_dir_subpath_buf[slash] = 0; var subdir = this.destination_dir_subpath_buf[0..slash :0]; this.destination_dir.dir.makeDirZ(subdir) catch {}; diff --git a/src/string_immutable.zig b/src/string_immutable.zig index 8f3859a34..d393577fc 100644 --- a/src/string_immutable.zig +++ b/src/string_immutable.zig @@ -3187,6 +3187,18 @@ test "indexOfNeedsEscape" { try std.testing.expectEqual(out.?, 48); } +pub fn indexOfCharZ(sliceZ: [:0]const u8, char: u8) ?u63 { + const ptr = bun.C.strchr(sliceZ.ptr, char) orelse return null; + const pos = @ptrToInt(ptr) - @ptrToInt(sliceZ.ptr); + + if (comptime Environment.allow_assert) + std.debug.assert(@ptrToInt(sliceZ.ptr) >= @ptrToInt(ptr) and + @ptrToInt(ptr) < @ptrToInt(sliceZ.ptr + sliceZ.len) and + pos <= sliceZ.len); + + return @truncate(u63, pos); +} + pub fn indexOfChar(slice: []const u8, char: u8) ?u32 { var remaining = slice; if (remaining.len == 0) -- cgit v1.2.3