Skip to content

Commit c9260b9

Browse files
committed
chunked: rename GetDiffer to NewDiffer
it is an explicit API breaking change, so that cannot be used by old users (e.g. an older containers/image version) that are not ported to support the new semantic that only one ApplyDiffWithDiffer call is supported for one differ object. Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
1 parent 719ebe0 commit c9260b9

File tree

4 files changed

+13
-9
lines changed

4 files changed

+13
-9
lines changed

cmd/containers-storage/diff.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ func applyDiffUsingStagingDirectory(flags *mflag.FlagSet, action string, m stora
176176
file: tar,
177177
}
178178

179-
differ, err := chunked.GetDiffer(context.Background(), m, digesterCompressed.Digest(), size, metadata, &fetcher)
179+
differ, err := chunked.NewDiffer(context.Background(), m, digesterCompressed.Digest(), size, metadata, &fetcher)
180180
if err != nil {
181181
return 1, err
182182
}

pkg/chunked/storage_linux.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ type chunkedDiffer struct {
8080
convertToZstdChunked bool
8181

8282
// Chunked metadata
83-
// This is usually set in GetDiffer, but if convertToZstdChunked, it is only computed in chunkedDiffer.ApplyDiff
83+
// This is usually set in NewDiffer, but if convertToZstdChunked, it is only computed in chunkedDiffer.ApplyDiff
8484
// ==========
8585
// tocDigest is the digest of the TOC document when the layer
8686
// is partially pulled, or "" if not relevant to consumers.
@@ -95,7 +95,7 @@ type chunkedDiffer struct {
9595
skipValidation bool
9696

9797
// Long-term caches
98-
// This is set in GetDiffer, when the caller must not hold any storage locks, and later consumed in .ApplyDiff()
98+
// This is set in NewDiffer, when the caller must not hold any storage locks, and later consumed in .ApplyDiff()
9999
// ==========
100100
layersCache *layersCache
101101
copyBuffer []byte
@@ -200,10 +200,11 @@ func (c *chunkedDiffer) Close() error {
200200
return nil
201201
}
202202

203-
// GetDiffer returns a differ than can be used with [Store.PrepareStagedLayer].
203+
// NewDiffer returns a differ than can be used with [Store.PrepareStagedLayer].
204204
// If it returns an error that matches ErrFallbackToOrdinaryLayerDownload, the caller can
205205
// retry the operation with a different method.
206-
func GetDiffer(ctx context.Context, store storage.Store, blobDigest digest.Digest, blobSize int64, annotations map[string]string, iss ImageSourceSeekable) (graphdriver.Differ, error) {
206+
// The caller must call Close() on the returned Differ.
207+
func NewDiffer(ctx context.Context, store storage.Store, blobDigest digest.Digest, blobSize int64, annotations map[string]string, iss ImageSourceSeekable) (graphdriver.Differ, error) {
207208
pullOptions := parsePullOptions(store)
208209

209210
if !pullOptions.enablePartialImages {
@@ -266,7 +267,7 @@ func (e errFallbackCanConvert) Unwrap() error {
266267
return e.err
267268
}
268269

269-
// getProperDiffer is an implementation detail of GetDiffer.
270+
// getProperDiffer is an implementation detail of NewDiffer.
270271
// It returns a “proper” differ (not a convert_images one) if possible.
271272
// May return an error matching ErrFallbackToOrdinaryLayerDownload if a fallback to an alternative
272273
// (either makeConvertFromRawDiffer, or a non-partial pull) is permissible.
@@ -1873,7 +1874,7 @@ func (c *chunkedDiffer) ApplyDiff(dest string, options *archive.TarOptions, diff
18731874
}
18741875
output.UncompressedDigest = digester.Digest()
18751876
default:
1876-
// We are checking for this earlier in GetDiffer, so this should not be reachable.
1877+
// We are checking for this earlier in NewDiffer, so this should not be reachable.
18771878
return output, fmt.Errorf(`internal error: layer's UncompressedDigest is unknown and "insecure_allow_unpredictable_image_contents" is not set`)
18781879
}
18791880
}

pkg/chunked/storage_unsupported.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ import (
1111
digest "github.com/opencontainers/go-digest"
1212
)
1313

14-
// GetDiffer returns a differ than can be used with [Store.PrepareStagedLayer].
15-
func GetDiffer(ctx context.Context, store storage.Store, blobDigest digest.Digest, blobSize int64, annotations map[string]string, iss ImageSourceSeekable) (graphdriver.Differ, error) {
14+
// NewDiffer returns a differ than can be used with [Store.PrepareStagedLayer].
15+
// The caller must call Close() on the returned Differ.
16+
func NewDiffer(ctx context.Context, store storage.Store, blobDigest digest.Digest, blobSize int64, annotations map[string]string, iss ImageSourceSeekable) (graphdriver.Differ, error) {
1617
return nil, newErrFallbackToOrdinaryLayerDownload(errors.New("format not supported on this system"))
1718
}

store.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,8 @@ type Store interface {
365365
// PrepareStagedLayer applies a diff to a layer.
366366
// It is the caller responsibility to clean the staging directory if it is not
367367
// successfully applied with ApplyStagedLayer.
368+
// The caller must ensure [Store.ApplyStagedLayer] or [Store.CleanupStagedLayer] is called eventually
369+
// with the returned [drivers.DriverWithDifferOutput] object.
368370
PrepareStagedLayer(options *drivers.ApplyDiffWithDifferOpts, differ drivers.Differ) (*drivers.DriverWithDifferOutput, error)
369371

370372
// ApplyStagedLayer combines the functions of creating a layer and using the staging

0 commit comments

Comments
 (0)