Skip to content

Commit

Permalink
fix(install): tarball extracting bugfix (#11864)
Browse files Browse the repository at this point in the history
Co-authored-by: Jarred Sumner <[email protected]>
  • Loading branch information
dylan-conway and Jarred-Sumner authored Jun 15, 2024
1 parent eedb3e5 commit fa952b1
Show file tree
Hide file tree
Showing 14 changed files with 357 additions and 182 deletions.
7 changes: 4 additions & 3 deletions misctools/tgz.zig
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,9 @@ pub fn main() anyerror!void {
null,
void,
void{},
1,
false,
false,
.{
.depth_to_skip = 1,
.close_handles = false,
},
);
}
24 changes: 24 additions & 0 deletions src/bun.zig
Original file line number Diff line number Diff line change
Expand Up @@ -3260,6 +3260,19 @@ noinline fn assertionFailure() noreturn {
Output.panic("Internal assertion failure", .{});
}

noinline fn assertionFailureWithLocation(src: std.builtin.SourceLocation) noreturn {
if (@inComptime()) {
@compileError("assertion failure");
}

@setCold(true);
Output.panic("Internal assertion failure {s}:{d}:{d}", .{
src.file,
src.line,
src.column,
});
}

pub inline fn debugAssert(cheap_value_only_plz: bool) void {
if (comptime !Environment.isDebug) {
return;
Expand All @@ -3281,6 +3294,17 @@ pub fn assert(value: bool) callconv(callconv_inline) void {
}
}

pub fn assertWithLocation(value: bool, src: std.builtin.SourceLocation) callconv(callconv_inline) void {
if (comptime !Environment.allow_assert) {
return;
}

if (!value) {
if (comptime Environment.isDebug) unreachable;
assertionFailureWithLocation(src);
}
}

/// This has no effect on the real code but capturing 'a' and 'b' into parameters makes assertion failures much easier inspect in a debugger.
pub inline fn assert_eql(a: anytype, b: anytype) void {
return assert(a == b);
Expand Down
6 changes: 3 additions & 3 deletions src/cli/create_command.zig
Original file line number Diff line number Diff line change
Expand Up @@ -433,9 +433,9 @@ pub const CreateCommand = struct {
&archive_context,
void,
{},
1,
false,
false,
.{
.depth_to_skip = 1,
},
);

if (!create_options.skip_package_json) {
Expand Down
8 changes: 4 additions & 4 deletions src/compile_target.zig
Original file line number Diff line number Diff line change
Expand Up @@ -269,10 +269,10 @@ pub fn downloadToPath(this: *const CompileTarget, env: *bun.DotEnv.Loader, alloc
null,
void,
{},
// "package/bin"
2,
true,
false,
.{
// "package/bin"
.depth_to_skip = 2,
},
) catch |err| {
node.end();
Output.err(err,
Expand Down
20 changes: 12 additions & 8 deletions src/install/extract_tarball.zig
Original file line number Diff line number Diff line change
Expand Up @@ -240,10 +240,11 @@ fn extract(this: *const ExtractTarball, tgz_bytes: []const u8) !Install.ExtractD
null,
*DirnameReader,
&dirname_reader,
// for GitHub tarballs, the root dir is always <user>-<repo>-<commit_id>
1,
true,
log,
.{
// for GitHub tarballs, the root dir is always <user>-<repo>-<commit_id>
.depth_to_skip = 1,
.log = log,
},
),
}

Expand All @@ -265,10 +266,13 @@ fn extract(this: *const ExtractTarball, tgz_bytes: []const u8) !Install.ExtractD
null,
void,
{},
// for npm packages, the root dir is always "package"
1,
true,
log,
.{
.log = log,
// packages usually have root directory `package/`, and scoped packages usually have root `<scopename>/`
// https://github.com/npm/cli/blob/93883bb6459208a916584cad8c6c72a315cf32af/node_modules/pacote/lib/fetcher.js#L442
.depth_to_skip = 1,
.npm = true,
},
),
},
}
Expand Down
Loading

0 comments on commit fa952b1

Please sign in to comment.