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>
This commit is contained in:
Giuseppe Scrivano 2025-04-29 21:54:01 +02:00
parent 719ebe0f4c
commit c9260b973a
No known key found for this signature in database
GPG Key ID: 67E38F7A8BA21772
4 changed files with 13 additions and 9 deletions

View File

@ -176,7 +176,7 @@ func applyDiffUsingStagingDirectory(flags *mflag.FlagSet, action string, m stora
file: tar, file: tar,
} }
differ, err := chunked.GetDiffer(context.Background(), m, digesterCompressed.Digest(), size, metadata, &fetcher) differ, err := chunked.NewDiffer(context.Background(), m, digesterCompressed.Digest(), size, metadata, &fetcher)
if err != nil { if err != nil {
return 1, err return 1, err
} }

View File

@ -80,7 +80,7 @@ type chunkedDiffer struct {
convertToZstdChunked bool convertToZstdChunked bool
// Chunked metadata // Chunked metadata
// This is usually set in GetDiffer, but if convertToZstdChunked, it is only computed in chunkedDiffer.ApplyDiff // This is usually set in NewDiffer, but if convertToZstdChunked, it is only computed in chunkedDiffer.ApplyDiff
// ========== // ==========
// tocDigest is the digest of the TOC document when the layer // tocDigest is the digest of the TOC document when the layer
// is partially pulled, or "" if not relevant to consumers. // is partially pulled, or "" if not relevant to consumers.
@ -95,7 +95,7 @@ type chunkedDiffer struct {
skipValidation bool skipValidation bool
// Long-term caches // Long-term caches
// This is set in GetDiffer, when the caller must not hold any storage locks, and later consumed in .ApplyDiff() // This is set in NewDiffer, when the caller must not hold any storage locks, and later consumed in .ApplyDiff()
// ========== // ==========
layersCache *layersCache layersCache *layersCache
copyBuffer []byte copyBuffer []byte
@ -200,10 +200,11 @@ func (c *chunkedDiffer) Close() error {
return nil return nil
} }
// GetDiffer returns a differ than can be used with [Store.PrepareStagedLayer]. // NewDiffer returns a differ than can be used with [Store.PrepareStagedLayer].
// If it returns an error that matches ErrFallbackToOrdinaryLayerDownload, the caller can // If it returns an error that matches ErrFallbackToOrdinaryLayerDownload, the caller can
// retry the operation with a different method. // retry the operation with a different method.
func GetDiffer(ctx context.Context, store storage.Store, blobDigest digest.Digest, blobSize int64, annotations map[string]string, iss ImageSourceSeekable) (graphdriver.Differ, error) { // The caller must call Close() on the returned Differ.
func NewDiffer(ctx context.Context, store storage.Store, blobDigest digest.Digest, blobSize int64, annotations map[string]string, iss ImageSourceSeekable) (graphdriver.Differ, error) {
pullOptions := parsePullOptions(store) pullOptions := parsePullOptions(store)
if !pullOptions.enablePartialImages { if !pullOptions.enablePartialImages {
@ -266,7 +267,7 @@ func (e errFallbackCanConvert) Unwrap() error {
return e.err return e.err
} }
// getProperDiffer is an implementation detail of GetDiffer. // getProperDiffer is an implementation detail of NewDiffer.
// It returns a “proper” differ (not a convert_images one) if possible. // It returns a “proper” differ (not a convert_images one) if possible.
// May return an error matching ErrFallbackToOrdinaryLayerDownload if a fallback to an alternative // May return an error matching ErrFallbackToOrdinaryLayerDownload if a fallback to an alternative
// (either makeConvertFromRawDiffer, or a non-partial pull) is permissible. // (either makeConvertFromRawDiffer, or a non-partial pull) is permissible.
@ -1873,7 +1874,7 @@ func (c *chunkedDiffer) ApplyDiff(dest string, options *archive.TarOptions, diff
} }
output.UncompressedDigest = digester.Digest() output.UncompressedDigest = digester.Digest()
default: default:
// We are checking for this earlier in GetDiffer, so this should not be reachable. // We are checking for this earlier in NewDiffer, so this should not be reachable.
return output, fmt.Errorf(`internal error: layer's UncompressedDigest is unknown and "insecure_allow_unpredictable_image_contents" is not set`) return output, fmt.Errorf(`internal error: layer's UncompressedDigest is unknown and "insecure_allow_unpredictable_image_contents" is not set`)
} }
} }

View File

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

View File

@ -365,6 +365,8 @@ type Store interface {
// PrepareStagedLayer applies a diff to a layer. // PrepareStagedLayer applies a diff to a layer.
// It is the caller responsibility to clean the staging directory if it is not // It is the caller responsibility to clean the staging directory if it is not
// successfully applied with ApplyStagedLayer. // successfully applied with ApplyStagedLayer.
// The caller must ensure [Store.ApplyStagedLayer] or [Store.CleanupStagedLayer] is called eventually
// with the returned [drivers.DriverWithDifferOutput] object.
PrepareStagedLayer(options *drivers.ApplyDiffWithDifferOpts, differ drivers.Differ) (*drivers.DriverWithDifferOutput, error) PrepareStagedLayer(options *drivers.ApplyDiffWithDifferOpts, differ drivers.Differ) (*drivers.DriverWithDifferOutput, error)
// ApplyStagedLayer combines the functions of creating a layer and using the staging // ApplyStagedLayer combines the functions of creating a layer and using the staging