Skip to content

Commit b96445f

Browse files
committed
Fix edge case with previously (failed) ingested content
1 parent 0b7ae64 commit b96445f

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

cmd/bashbrew/oci-builder.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,22 +62,27 @@ func readContentJSON(ctx context.Context, cs content.Provider, desc imagespec.De
6262
}
6363

6464
// given a containerd content store, an io/fs reference to an "OCI image layout", and an OCI descriptor, import the given blob into the content store (with appropriate validation)
65-
func importOCIBlob(ctx context.Context, cs content.Ingester, fs iofs.FS, descriptor imagespec.Descriptor) error {
65+
func importOCIBlob(ctx context.Context, cs content.Store, fs iofs.FS, descriptor imagespec.Descriptor) error {
6666
// https://github.com/opencontainers/image-spec/blob/v1.0.2/image-layout.md#blobs
6767
blob, err := fs.Open(path.Join("blobs", string(descriptor.Digest.Algorithm()), descriptor.Digest.Encoded())) // "blobs/sha256/deadbeefdeadbeefdeadbeef..."
6868
if err != nil {
6969
return err
7070
}
7171
defer blob.Close()
7272

73+
ingestRef := string(descriptor.Digest)
74+
75+
// explicitly "abort" the ref we're about to use in case there's a partial or failed ingest already (which content.WriteBlob will then quietly reuse, over and over)
76+
_ = cs.Abort(ctx, ingestRef)
77+
7378
// WriteBlob does *not* limit reads to the provided size, so let's wrap ourselves in a LimitedReader to prevent reading (much) more than we intend
7479
r := io.LimitReader(
7580
blob,
7681
descriptor.Size+1, // +1 to allow WriteBlob to detect if it reads too much
7782
)
7883

7984
// WriteBlob verifies the digest and the size while ingesting
80-
return content.WriteBlob(ctx, cs, string(descriptor.Digest), r, descriptor)
85+
return content.WriteBlob(ctx, cs, ingestRef, r, descriptor)
8186
}
8287

8388
// this is "docker build" but for "Builder: oci-import"

0 commit comments

Comments
 (0)