diff --git a/content/oci/storage.go b/content/oci/storage.go index 6acf5b34..efb9f3d8 100644 --- a/content/oci/storage.go +++ b/content/oci/storage.go @@ -20,6 +20,7 @@ import ( "errors" "fmt" "io" + "io/fs" "os" "path/filepath" "sync" @@ -113,7 +114,14 @@ func (s *Storage) Delete(ctx context.Context, target ocispec.Descriptor) error { return fmt.Errorf("%s: %s: %w", target.Digest, target.MediaType, errdef.ErrInvalidDigest) } targetPath := filepath.Join(s.root, path) - return os.Remove(targetPath) + 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 err + } + return nil } // ingest write the content into a temporary ingest file. diff --git a/content/oci/storage_test.go b/content/oci/storage_test.go index 514f354c..244acb21 100644 --- a/content/oci/storage_test.go +++ b/content/oci/storage_test.go @@ -412,4 +412,8 @@ func TestStorage_Delete(t *testing.T) { if exists { t.Errorf("Storage.Exists() = %v, want %v", exists, false) } + err = s.Delete(ctx, desc) + if !errors.Is(err, errdef.ErrNotFound) { + t.Fatalf("got error = %v, want %v", err, errdef.ErrNotFound) + } }