Commit 1ca4428324

Andrew Kelley <andrew@ziglang.org>
2023-10-07 07:16:10
fix recursive package fetching logic
For path-relative dependencies, they always need to be added to the hash table at the end. For remote dependencies, they never need to be added.
1 parent ddb7c40
Changed files (1)
src
Package
src/Package/Fetch.zig
@@ -448,14 +448,20 @@ fn queueJobsForDeps(f: *Fetch, hash: Manifest.MultiHashHexDigest) RunError!void
         try f.job_queue.all_fetches.ensureUnusedCapacity(gpa, new_fetches.len);
         try f.job_queue.table.ensureUnusedCapacity(gpa, @intCast(new_fetches.len + 1));
 
-        // It is impossible for there to be a collision here. Consider all three cases:
+        // There are four cases here:
         // * Correct hash is provided by manifest.
-        //   - Redundant jobs are skipped in the loop below.
+        //   - Hash map already has the entry, no need to add it again.
         // * Incorrect hash is provided by manifest.
         //   - Hash mismatch error emitted; `queueJobsForDeps` is not called.
         // * Hash is not provided by manifest.
         //   - Hash missing error emitted; `queueJobsForDeps` is not called.
-        f.job_queue.table.putAssumeCapacityNoClobber(hash, f);
+        // * path-based location is used without a hash.
+        //   - We need to add `hash` to the table now.
+        switch (f.location) {
+            .remote => assert(f.job_queue.table.get(hash) == f),
+            .relative_path => f.job_queue.table.putAssumeCapacityNoClobber(hash, f),
+            .path_or_url => unreachable,
+        }
 
         for (deps) |dep| {
             const new_fetch = &new_fetches[new_fetch_index];