authorgravatar for der.teufel.mail@gmail.comKrzysztof Wolicki <der.teufel.mail@gmail.com> 2024-09-24 22:38:13+02:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2024-09-24 13:38:13-07:00
log4d09fb491f1a2e3c4404807c5f4b2c2e114f911b
tree24a448890700074276eb75159ea3fc7c5a33b9d7
parent5e4da1ff30d673d96809497e9bce555edef813a7
signaturebadge-check Signed by PGP key B5690EEEBB952194

fetch: fix mutating unrelated fields when saving (#19816)

closes #19725

2 files changed, 21 insertions(+), 1 deletions(-)

src/Package/Manifest.zig+7
......@@ -18,8 +18,10 @@ pub const MultiHashHexDigest = [multihash_hex_digest_len]u8;
1818pub const Dependency = struct {
1919 location: Location,
2020 location_tok: Ast.TokenIndex,
21 location_node: Ast.Node.Index,
2122 hash: ?[]const u8,
2223 hash_tok: Ast.TokenIndex,
24 hash_node: Ast.Node.Index,
2325 node: Ast.Node.Index,
2426 name_tok: Ast.TokenIndex,
2527 lazy: bool,
......@@ -293,8 +295,10 @@ const Parse = struct {
293295 var dep: Dependency = .{
294296 .location = undefined,
295297 .location_tok = 0,
298 .location_node = undefined,
296299 .hash = null,
297300 .hash_tok = 0,
301 .hash_node = undefined,
298302 .node = node,
299303 .name_tok = 0,
300304 .lazy = false,
......@@ -320,6 +324,7 @@ const Parse = struct {
320324 };
321325 has_location = true;
322326 dep.location_tok = main_tokens[field_init];
327 dep.location_node = field_init;
323328 } else if (mem.eql(u8, field_name, "path")) {
324329 if (has_location) {
325330 return fail(p, main_tokens[field_init], "dependency should specify only one of 'url' and 'path' fields.", .{});
......@@ -332,12 +337,14 @@ const Parse = struct {
332337 };
333338 has_location = true;
334339 dep.location_tok = main_tokens[field_init];
340 dep.location_node = field_init;
335341 } else if (mem.eql(u8, field_name, "hash")) {
336342 dep.hash = parseHash(p, field_init) catch |err| switch (err) {
337343 error.ParseFailure => continue,
338344 else => |e| return e,
339345 };
340346 dep.hash_tok = main_tokens[field_init];
347 dep.hash_node = field_init;
341348 } else if (mem.eql(u8, field_name, "lazy")) {
342349 dep.lazy = parseBool(p, field_init) catch |err| switch (err) {
343350 error.ParseFailure => continue,
src/main.zig+14-1
......@@ -7214,8 +7214,21 @@ fn cmdFetch(
72147214 .path => {},
72157215 }
72167216 }
7217
7218 const location_replace = try std.fmt.allocPrint(
7219 arena,
7220 "\"{}\"",
7221 .{std.zig.fmtEscapes(path_or_url)},
7222 );
7223 const hash_replace = try std.fmt.allocPrint(
7224 arena,
7225 "\"{}\"",
7226 .{std.zig.fmtEscapes(&hex_digest)},
7227 );
7228
72177229 warn("overwriting existing dependency named '{s}'", .{name});
7218 try fixups.replace_nodes_with_string.put(gpa, dep.node, new_node_init);
7230 try fixups.replace_nodes_with_string.put(gpa, dep.location_node, location_replace);
7231 try fixups.replace_nodes_with_string.put(gpa, dep.hash_node, hash_replace);
72197232 } else if (manifest.dependencies.count() > 0) {
72207233 // Add fixup for adding another dependency.
72217234 const deps = manifest.dependencies.values();