diff options
author | 2023-01-19 16:38:08 +0200 | |
---|---|---|
committer | 2023-01-19 06:38:08 -0800 | |
commit | 61736966ad003b231b67c2be9e2462b176053038 (patch) | |
tree | ddde99194a980d1cad3db7ddfee2ac131e91cb71 | |
parent | 8bdcded5c10aa9e280c33c829988ad8363feba9f (diff) | |
download | bun-61736966ad003b231b67c2be9e2462b176053038.tar.gz bun-61736966ad003b231b67c2be9e2462b176053038.tar.zst bun-61736966ad003b231b67c2be9e2462b176053038.zip |
fix stale references upon `Lockfile` tree cloning (#1845)
-rw-r--r-- | src/install/install.zig | 6 | ||||
-rw-r--r-- | src/install/lockfile.zig | 12 |
2 files changed, 14 insertions, 4 deletions
diff --git a/src/install/install.zig b/src/install/install.zig index 3ce46b3ce..674ca5ae0 100644 --- a/src/install/install.zig +++ b/src/install/install.zig @@ -1375,7 +1375,6 @@ pub const PackageManager = struct { resolve_tasks: TaskChannel, timestamp_for_manifest_cache_control: u32 = 0, extracted_count: u32 = 0, - alias_map: std.ArrayHashMapUnmanaged(PackageID, string, ArrayIdentityContext, false) = .{}, default_features: Features = Features{}, summary: Lockfile.Package.Diff.Summary = Lockfile.Package.Diff.Summary{}, env: *DotEnv.Loader, @@ -2071,8 +2070,7 @@ pub const PackageManager = struct { const buf = this.lockfile.buffers.string_bytes.items; if (!alias.eql(name, buf, buf)) { - const alias_str = try this.allocator.dupe(u8, alias.slice(buf)); - try this.alias_map.put(this.allocator, package.meta.id, alias_str); + try this.lockfile.alias_map.put(this.allocator, package.meta.id, alias); } if (!behavior.isEnabled(if (this.isRootDependency(dependency_id)) @@ -5534,7 +5532,7 @@ pub const PackageManager = struct { resolution: Resolution, ) void { const buf = this.lockfile.buffers.string_bytes.items; - const alias = this.manager.alias_map.get(package_id) orelse name; + const alias = if (this.lockfile.alias_map.get(package_id)) |str| str.slice(buf) else name; std.mem.copy(u8, &this.destination_dir_subpath_buf, alias); this.destination_dir_subpath_buf[alias.len] = 0; var destination_dir_subpath: [:0]u8 = this.destination_dir_subpath_buf[0..alias.len :0]; diff --git a/src/install/lockfile.zig b/src/install/lockfile.zig index 465398fc6..9a0fabc87 100644 --- a/src/install/lockfile.zig +++ b/src/install/lockfile.zig @@ -106,6 +106,7 @@ allocator: std.mem.Allocator, scratch: Scratch = Scratch{}, scripts: Scripts = .{}, +alias_map: std.ArrayHashMapUnmanaged(PackageID, String, ArrayIdentityContext, false) = .{}, workspace_paths: std.ArrayHashMapUnmanaged(u32, String, ArrayIdentityContext, false) = .{}, const Stream = std.io.FixedBufferStream([]u8); @@ -205,6 +206,7 @@ pub fn loadFromBytes(this: *Lockfile, buf: []u8, allocator: std.mem.Allocator, l this.format = FormatVersion.current; this.scripts = .{}; + this.alias_map = .{}; this.workspace_paths = .{}; Lockfile.Serializer.load(this, &stream, allocator, log) catch |err| { @@ -1494,6 +1496,7 @@ pub fn initEmpty(this: *Lockfile, allocator: std.mem.Allocator) !void { .allocator = allocator, .scratch = Scratch.init(allocator), .scripts = .{}, + .alias_map = .{}, .workspace_paths = .{}, }; } @@ -1878,6 +1881,10 @@ pub const Package = extern struct { this.meta.count(old_string_buf, *Lockfile.StringBuilder, builder); const new_extern_string_count = this.bin.count(old_string_buf, old_extern_string_buf, *Lockfile.StringBuilder, builder); + if (old.alias_map.get(this.meta.id)) |alias| { + builder.count(old.str(alias)); + } + const old_dependencies: []const Dependency = this.dependencies.get(old.buffers.dependencies.items); const old_resolutions: []const PackageID = this.resolutions.get(old.buffers.resolutions.items); @@ -1934,6 +1941,10 @@ pub const Package = extern struct { package_id_mapping[this.meta.id] = new_package.meta.id; + if (old.alias_map.get(this.meta.id)) |alias| { + try new.alias_map.put(new.allocator, new_package.meta.id, builder.append(String, old.str(alias))); + } + for (old_dependencies) |dependency, i| { dependencies[i] = try dependency.clone( old_string_buf, @@ -3092,6 +3103,7 @@ pub fn deinit(this: *Lockfile) void { this.unique_packages.deinit(this.allocator); this.string_pool.deinit(); this.scripts.deinit(this.allocator); + this.alias_map.deinit(this.allocator); this.workspace_paths.deinit(this.allocator); } |