Skip to content

Commit

Permalink
deleting of blobs in shared directory behavior
Browse files Browse the repository at this point in the history
Signed-off-by: Philippe Vlérick <[email protected]>
  • Loading branch information
Pvlerick committed Oct 11, 2023
1 parent 0e68a62 commit 2c1a15c
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions oci/layout/oci_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,20 @@ func (ref ociReference) getBlobsToDelete(blobsUsedByDescriptorToDelete map[diges
return blobsToDelete, nil
}

// This transport never generates layouts where blobs for an image are both in the local blobs directory
// and the shared one; it’s either one or the other, depending on how OCISharedBlobDirPath is set.
//
// But we can’t correctly compute use counts for OCISharedBlobDirPath (because we don't know what
// the other layouts sharing that directory are, and we might not even have permission to read them),
// so we can’t really delete any blobs in that case.
// Checking the _local_ blobs directory, and deleting blobs from there, doesn't really hurt,
// in case the layout was created using some other tool or without OCISharedBlobDirPath set, so let's silently
// check for local blobs (but we should make no noise if the blobs are actually in the shared directory).
//
// So, NOTE: the blobPath() call below hard-codes "" even in calls where OCISharedBlobDirPath is set
func (ref ociReference) deleteBlobs(blobsToDelete *set.Set[digest.Digest]) error {
for _, digest := range blobsToDelete.Values() {
blobPath, err := ref.blobPath(digest, "") //Only delete in the local directory, not in the shared blobs path
blobPath, err := ref.blobPath(digest, "") //Only delete in the local directory, see comment above
if err != nil {
return err
}
Expand All @@ -173,13 +184,8 @@ func deleteBlob(blobPath string) error {
logrus.Debug(fmt.Sprintf("Deleting blob at %q", blobPath))

err := os.Remove(blobPath)
if err != nil {
if os.IsNotExist(err) {
logrus.Info(fmt.Sprintf("Blob at %q not found; it was either previously deleted or is in the shared blobs directory", blobPath))
return nil
} else {
return err
}
if err != nil && !os.IsNotExist(err) {
return err
} else {
return nil
}
Expand Down

0 comments on commit 2c1a15c

Please sign in to comment.