Skip to content

Commit

Permalink
removed storage changes
Browse files Browse the repository at this point in the history
Signed-off-by: Xiaoxuan Wang <wangxiaoxuan119@gmail.com>
  • Loading branch information
wangxiaoxuan273 committed Jan 3, 2024
1 parent cd7c686 commit f123008
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
23 changes: 14 additions & 9 deletions content/oci/oci.go
Original file line number Diff line number Diff line change
Expand Up @@ -485,17 +485,22 @@ func (s *Store) GC(ctx context.Context) error {
return err
}

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

View check run for this annotation

Codecov / codecov/patch

content/oci/oci.go#L485-L486

Added lines #L485 - L486 were not covered by tests
// skip the directories
if !info.IsDir() {
alg := filepath.Base(filepath.Dir(path))
blobDigest, err := digest.Parse(fmt.Sprintf("%s:%s", alg, info.Name()))
if info.IsDir() {
return nil
}
alg := filepath.Base(filepath.Dir(path))
blobDigest, err := digest.Parse(fmt.Sprintf("%s:%s", alg, info.Name()))
if err != nil {
return err
}

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

View check run for this annotation

Codecov / codecov/patch

content/oci/oci.go#L494-L495

Added lines #L494 - L495 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 {
return err
}
if exists := s.graph.Exists(blobDigest); !exists {
// remove the blob from storage if it does not exist in Store
if err := s.storage.deleteByDigest(ctx, blobDigest); err != nil {
return err
if errors.Is(err, fs.ErrNotExist) {
return fmt.Errorf("%s: %w", blobDigest, errdef.ErrNotFound)
}
return err

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

View check run for this annotation

Codecov / codecov/patch

content/oci/oci.go#L500-L503

Added lines #L500 - L503 were not covered by tests
}
}
return nil
Expand Down
11 changes: 3 additions & 8 deletions content/oci/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ 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 @@ -110,19 +109,15 @@ 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 {
return s.deleteByDigest(ctx, target.Digest)
}

func (s *Storage) deleteByDigest(ctx context.Context, digest digest.Digest) error {
path, err := blobPath(digest)
path, err := blobPath(target.Digest)
if err != nil {
return fmt.Errorf("%s: %w", digest, errdef.ErrInvalidDigest)
return fmt.Errorf("%s: %s: %w", target.Digest, target.MediaType, errdef.ErrInvalidDigest)
}
targetPath := filepath.Join(s.root, path)
err = os.Remove(targetPath)
if err != nil {
if errors.Is(err, fs.ErrNotExist) {
return fmt.Errorf("%s: %w", digest, errdef.ErrNotFound)
return fmt.Errorf("%s: %s: %w", target.Digest, target.MediaType, errdef.ErrNotFound)
}
return err
}
Expand Down

0 comments on commit f123008

Please sign in to comment.