Skip to content

Commit

Permalink
delete by digest
Browse files Browse the repository at this point in the history
Signed-off-by: Xiaoxuan Wang <[email protected]>
  • Loading branch information
wangxiaoxuan273 committed Dec 28, 2023
1 parent 228d818 commit 1613b91
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
6 changes: 1 addition & 5 deletions content/oci/oci.go
Original file line number Diff line number Diff line change
Expand Up @@ -436,11 +436,7 @@ func (s *Store) GC(ctx context.Context) error {
}

Check warning on line 436 in content/oci/oci.go

View check run for this annotation

Codecov / codecov/patch

content/oci/oci.go#L435-L436

Added lines #L435 - L436 were not covered by tests
if exists := s.graph.Exists(blobDigest); !exists {
// remove the blob from storage if it does not exist in Store
err = os.Remove(path)
if err != nil {
if errors.Is(err, fs.ErrNotExist) {
return fmt.Errorf("%s: %w", blobDigest, errdef.ErrNotFound)
}
if err := s.storage.deleteByDigest(ctx, blobDigest); err != nil {
return err
}

Check warning on line 441 in content/oci/oci.go

View check run for this annotation

Codecov / codecov/patch

content/oci/oci.go#L440-L441

Added lines #L440 - L441 were not covered by tests
}
Expand Down
11 changes: 8 additions & 3 deletions content/oci/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"path/filepath"
"sync"

"github.com/opencontainers/go-digest"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"oras.land/oras-go/v2/errdef"
"oras.land/oras-go/v2/internal/ioutil"
Expand Down Expand Up @@ -109,15 +110,19 @@ func (s *Storage) Push(_ context.Context, expected ocispec.Descriptor, content i

// Delete removes the target from the system.
func (s *Storage) Delete(ctx context.Context, target ocispec.Descriptor) error {
path, err := blobPath(target.Digest)
return s.deleteByDigest(ctx, target.Digest)
}

func (s *Storage) deleteByDigest(ctx context.Context, digest digest.Digest) error {
path, err := blobPath(digest)
if err != nil {
return fmt.Errorf("%s: %s: %w", target.Digest, target.MediaType, errdef.ErrInvalidDigest)
return fmt.Errorf("%s: %w", digest, errdef.ErrInvalidDigest)

Check warning on line 119 in content/oci/storage.go

View check run for this annotation

Codecov / codecov/patch

content/oci/storage.go#L119

Added line #L119 was not covered by tests
}
targetPath := filepath.Join(s.root, path)
err = os.Remove(targetPath)
if err != nil {
if errors.Is(err, fs.ErrNotExist) {
return fmt.Errorf("%s: %s: %w", target.Digest, target.MediaType, errdef.ErrNotFound)
return fmt.Errorf("%s: %w", digest, errdef.ErrNotFound)
}
return err
}
Expand Down

0 comments on commit 1613b91

Please sign in to comment.