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;...@@ -18,8 +18,10 @@ pub const MultiHashHexDigest = [multihash_hex_digest_len]u8;
18pub const Dependency = struct {18pub const Dependency = struct {
19 location: Location,19 location: Location,
20 location_tok: Ast.TokenIndex,20 location_tok: Ast.TokenIndex,
21 location_node: Ast.Node.Index,
21 hash: ?[]const u8,22 hash: ?[]const u8,
22 hash_tok: Ast.TokenIndex,23 hash_tok: Ast.TokenIndex,
24 hash_node: Ast.Node.Index,
23 node: Ast.Node.Index,25 node: Ast.Node.Index,
24 name_tok: Ast.TokenIndex,26 name_tok: Ast.TokenIndex,
25 lazy: bool,27 lazy: bool,
...@@ -293,8 +295,10 @@ const Parse = struct {...@@ -293,8 +295,10 @@ const Parse = struct {
293 var dep: Dependency = .{295 var dep: Dependency = .{
294 .location = undefined,296 .location = undefined,
295 .location_tok = 0,297 .location_tok = 0,
298 .location_node = undefined,
296 .hash = null,299 .hash = null,
297 .hash_tok = 0,300 .hash_tok = 0,
301 .hash_node = undefined,
298 .node = node,302 .node = node,
299 .name_tok = 0,303 .name_tok = 0,
300 .lazy = false,304 .lazy = false,
...@@ -320,6 +324,7 @@ const Parse = struct {...@@ -320,6 +324,7 @@ const Parse = struct {
320 };324 };
321 has_location = true;325 has_location = true;
322 dep.location_tok = main_tokens[field_init];326 dep.location_tok = main_tokens[field_init];
327 dep.location_node = field_init;
323 } else if (mem.eql(u8, field_name, "path")) {328 } else if (mem.eql(u8, field_name, "path")) {
324 if (has_location) {329 if (has_location) {
325 return fail(p, main_tokens[field_init], "dependency should specify only one of 'url' and 'path' fields.", .{});330 return fail(p, main_tokens[field_init], "dependency should specify only one of 'url' and 'path' fields.", .{});
...@@ -332,12 +337,14 @@ const Parse = struct {...@@ -332,12 +337,14 @@ const Parse = struct {
332 };337 };
333 has_location = true;338 has_location = true;
334 dep.location_tok = main_tokens[field_init];339 dep.location_tok = main_tokens[field_init];
340 dep.location_node = field_init;
335 } else if (mem.eql(u8, field_name, "hash")) {341 } else if (mem.eql(u8, field_name, "hash")) {
336 dep.hash = parseHash(p, field_init) catch |err| switch (err) {342 dep.hash = parseHash(p, field_init) catch |err| switch (err) {
337 error.ParseFailure => continue,343 error.ParseFailure => continue,
338 else => |e| return e,344 else => |e| return e,
339 };345 };
340 dep.hash_tok = main_tokens[field_init];346 dep.hash_tok = main_tokens[field_init];
347 dep.hash_node = field_init;
341 } else if (mem.eql(u8, field_name, "lazy")) {348 } else if (mem.eql(u8, field_name, "lazy")) {
342 dep.lazy = parseBool(p, field_init) catch |err| switch (err) {349 dep.lazy = parseBool(p, field_init) catch |err| switch (err) {
343 error.ParseFailure => continue,350 error.ParseFailure => continue,
src/main.zig+14-1
...@@ -7214,8 +7214,21 @@ fn cmdFetch(...@@ -7214,8 +7214,21 @@ fn cmdFetch(
7214 .path => {},7214 .path => {},
7215 }7215 }
7216 }7216 }
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
7217 warn("overwriting existing dependency named '{s}'", .{name});7229 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);
7219 } else if (manifest.dependencies.count() > 0) {7232 } else if (manifest.dependencies.count() > 0) {
7220 // Add fixup for adding another dependency.7233 // Add fixup for adding another dependency.
7221 const deps = manifest.dependencies.values();7234 const deps = manifest.dependencies.values();