Skip to content

Tolerate a stored blob already copied into the ingest directory - #1027

Open
0z5a wants to merge 1 commit into
apple:mainfrom
0z5a:fix-load-duplicate-stored-blob
Open

0z5a wants to merge 1 commit into
apple:mainfrom
0z5a:fix-load-duplicate-stored-blob

Conversation

@0z5a

@0z5a 0z5a commented Nov 21, 2026

Copy link
Copy Markdown

Fixes #1017.

I started from #1017 and checked it against the code. ImageStore.load(from:) runs an ImportOperation for each descriptor of the layout's index.json, and all of them write into the same ingest directory. When the content store already has a blob, ImportOperation.fetch copies it into that directory with copyItem. If an earlier descriptor in the same load already copied it, the copy fails with NSFileWriteFileExistsError (516 / EEXIST), and the whole load fails.

This change ignores that error in fetch, the same way fetchBlob already ignores it for moveItem. The ingest file is named by its digest, so the copy that is already there has the same content.

How I found it

From the report in #1017. I reproduced it with a unit test before changing anything.

Where this can show up in practice

Loading any OCI layout whose index lists the same image more than once, when that image (or a blob it shares) is already in the store. container image save of two tags of one image writes this, and so does docker save of several tags. The issue has the user-level steps.

Validation

macOS. I added testLoadIndexListingOneImageUnderTwoNames(alreadyStored:) to ImageStoreTests. It takes the scratch layout the existing tests use, adds a second index entry for the same manifest under another name, and loads it into an empty store (alreadyStored: false) and into a store that already has the image (alreadyStored: true).

  • On main (0ac42ce): alreadyStored: true fails with NSCocoaErrorDomain Code=516 ... because an item with the same name already exists (File exists), the error from the issue. alreadyStored: false passes.
  • With this change: both cases pass, and both names resolve to the same digest.
  • Control: swift test --filter 'ImageStoreTests|ImportOperationTests|OCILayout': 20 tests in 3 suites pass. swift format lint with .swift-format-nolint reports nothing on the two changed files.

Not run: make test (the full unit suite), the integration suite, and the Linux build.

Overlap

The open #1024 changes the same copyItem block in fetch (it falls back to the source when the stored blob disappears mid-import). It still rethrows this error while the stored blob exists, so the load in #1017 still fails with it alone. Whichever lands second will need a small rebase.

`ImageStore.load(from:)` runs one `ImportOperation` per descriptor of the
layout's index into a single ingest directory. When the content store
already has a blob, `fetch` copies it into that directory with
`copyItem`, and a second descriptor that reaches the same blob fails
with `NSFileWriteFileExistsError`. This happens when the index lists one
image under two names, as `container image save` and `docker save` of
two tags write it.

Ignore that error, as `fetchBlob` already does for `moveItem`: the file
is named by its digest, so the existing copy has the same content.

Fixes apple#1017

Signed-off-by: Dezhen Lu <dezhen.lu@student.uni-tuebingen.de>

This branch has not been deployed

No deployments
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.

[Bug]: ImageStore.load fails with "item with the same name already exists" when two index descriptors reach a blob already in the content store

1 participant