From cd36ca24dac4156f8840f6d7494068f8f7ca0dde Mon Sep 17 00:00:00 2001 From: Giuseppe Scrivano Date: Fri, 16 Feb 2024 09:02:57 +0100 Subject: [PATCH] storage: use the new ApplyStagedLayer interface Signed-off-by: Giuseppe Scrivano --- storage/storage_dest.go | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/storage/storage_dest.go b/storage/storage_dest.go index c3a520c8aa..2c613edf63 100644 --- a/storage/storage_dest.go +++ b/storage/storage_dest.go @@ -172,7 +172,7 @@ func (s *storageImageDestination) Close() error { } for _, v := range s.lockProtected.diffOutputs { if v.Target != "" { - _ = s.imageRef.transport.store.CleanupStagingDirectory(v.Target) + _ = s.imageRef.transport.store.CleanupStagedLayer(v) } } return os.RemoveAll(s.directory) @@ -770,11 +770,6 @@ func (s *storageImageDestination) createNewLayer(index int, layerDigest digest.D untrustedUncompressedDigest = d } - layer, err := s.imageRef.transport.store.CreateLayer(newLayerID, parentLayer, nil, "", false, nil) - if err != nil { - return nil, err - } - flags := make(map[string]interface{}) if untrustedUncompressedDigest != "" { flags[expectedLayerDiffIDFlag] = untrustedUncompressedDigest @@ -783,8 +778,16 @@ func (s *storageImageDestination) createNewLayer(index int, layerDigest digest.D options := &graphdriver.ApplyDiffWithDifferOpts{ Flags: flags, } - if err := s.imageRef.transport.store.ApplyDiffFromStagingDirectory(layer.ID, diffOutput.Target, diffOutput, options); err != nil { - _ = s.imageRef.transport.store.Delete(layer.ID) + + args := storage.ApplyStagedLayerOptions{ + ID: newLayerID, + ParentLayer: parentLayer, + + DiffOutput: diffOutput, + DiffOptions: options, + } + layer, err := s.imageRef.transport.store.ApplyStagedLayer(args) + if err != nil && !errors.Is(err, storage.ErrDuplicateID) { return nil, err } return layer, nil