Skip to content

Commit

Permalink
Merge pull request containers#2390 from giuseppe/cleanup-staged-direc…
Browse files Browse the repository at this point in the history
…tory

storage: cleanup staged layer if unused
  • Loading branch information
mtrmac authored May 16, 2024
2 parents 5e7756c + 77d7ff5 commit 4f07d28
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions storage/storage_dest.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,7 @@ func (s *storageImageDestination) Close() error {
al.Release()
}
for _, v := range s.lockProtected.diffOutputs {
if v.Target != "" {
_ = s.imageRef.transport.store.CleanupStagedLayer(v)
}
_ = s.imageRef.transport.store.CleanupStagedLayer(v)
}
return os.RemoveAll(s.directory)
}
Expand Down Expand Up @@ -310,6 +308,12 @@ func (s *storageImageDestination) PutBlobPartial(ctx context.Context, chunkAcces
if err != nil {
return private.UploadedBlob{}, err
}
succeeded := false
defer func() {
if !succeeded {
_ = s.imageRef.transport.store.CleanupStagedLayer(out)
}
}()

if out.TOCDigest == "" && out.UncompressedDigest == "" {
return private.UploadedBlob{}, errors.New("internal error: ApplyDiffWithDiffer succeeded with neither TOCDigest nor UncompressedDigest set")
Expand All @@ -332,6 +336,7 @@ func (s *storageImageDestination) PutBlobPartial(ctx context.Context, chunkAcces
s.lockProtected.diffOutputs[options.LayerIndex] = out
s.lock.Unlock()

succeeded = true
return private.UploadedBlob{
Digest: blobDigest,
Size: srcInfo.Size,
Expand Down

0 comments on commit 4f07d28

Please sign in to comment.