Skip to content

fix: deduplicate cookbook manifest files by path - #46

Open
tas50 wants to merge 1 commit into
mainfrom
fix/dedupe-cookbook-manifest
Open

fix: deduplicate cookbook manifest files by path#46
tas50 wants to merge 1 commit into
mainfrom
fix/dedupe-cookbook-manifest

Conversation

@tas50

@tas50 tas50 commented Sep 8, 2026

Copy link
Copy Markdown
Collaborator

Cookbook.AllFiles() concatenated the flat all_files manifest and all nine per-segment slices, on the strength of a comment asserting that a server populates "one shape or the other". Nothing guarantees that.

When both are populated, every file comes back twice — and Download turns each entry into a job handed to parallelForEach:

jobs[i] = fileDownload{url: ref.URL, dest: dest, path: ref.Path}

So two goroutines race to os.WriteFile the same destination, and each file is fetched from the bookshelf twice. Measured on a one-file cookbook listed in both shapes: 2 fetches, 2 unsynchronised writes.

Fixed by deduplicating on Path during the merge — all_files wins, and within the per-segment slices the first occurrence does.

Why the existing tests missed it

cinc-zero returns only all_files, so the integration suite can't reach this shape. The new test drives the merged manifest directly.

Test plan

  • TestAllFiles_DedupesByPath — a manifest listing two files in both shapes returns 2 refs, not 4 (failed before: returned 4)
  • TestDownload_FetchesEachFileOnce — counts bookshelf fetches (failed before: 2, want 1)
  • go vet ./... clean
  • go test ./... -race -count=2 — the race detector is the point here
  • cd integration && go test ./...
  • No public surface change, so no README Status update needed

@tas50
tas50 force-pushed the fix/dedupe-cookbook-manifest branch 3 times, most recently from eaafaea to 0642bd2 Compare September 8, 2026 16:53
AllFiles concatenated the flat all_files manifest and all nine per-segment
slices on the assumption that a server populates one shape or the other.
Nothing guarantees that. When both are populated every file is returned
twice, and Download turns each entry into a job: two goroutines then race
to os.WriteFile the same destination, and each file is fetched from the
bookshelf twice.

Deduplicate by path during the merge. all_files wins, and within the
per-segment slices the first occurrence does.

cinc-zero returns only all_files, so the integration suite cannot reach
this; the new test drives the merged shape directly.

Signed-off-by: Tim Smith <tim@mondoo.com>
@tas50
tas50 force-pushed the fix/dedupe-cookbook-manifest branch from 0642bd2 to 8680416 Compare September 10, 2026 16:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant