diff --git a/content/oci/deletableoci.go b/content/oci/deletableoci.go index 5bb0a799..0333693a 100644 --- a/content/oci/deletableoci.go +++ b/content/oci/deletableoci.go @@ -75,7 +75,6 @@ func NewDeletableStoreWithContext(ctx context.Context, root string) (*DeletableS if err != nil { return nil, fmt.Errorf("failed to create storage: %w", err) } - store := &DeletableStore{ AutoSaveIndex: true, root: rootAbs, @@ -84,7 +83,6 @@ func NewDeletableStoreWithContext(ctx context.Context, root string) (*DeletableS tagResolver: resolver.NewMemory(), graph: graph.NewDeletableMemory(), } - if err := ensureDir(filepath.Join(rootAbs, ociBlobsDir)); err != nil { return nil, err } @@ -94,7 +92,6 @@ func NewDeletableStoreWithContext(ctx context.Context, root string) (*DeletableS if err := store.loadIndexFile(ctx); err != nil { return nil, fmt.Errorf("invalid OCI Image Index: %w", err) } - return store, nil } @@ -160,7 +157,6 @@ func (ds *DeletableStore) Tag(ctx context.Context, desc ocispec.Descriptor, refe if err := validateReference(reference); err != nil { return err } - exists, err := ds.storage.Exists(ctx, desc) if err != nil { return err @@ -168,7 +164,6 @@ func (ds *DeletableStore) Tag(ctx context.Context, desc ocispec.Descriptor, refe if !exists { return fmt.Errorf("%s: %s: %w", desc.Digest, desc.MediaType, errdef.ErrNotFound) } - return ds.tag(ctx, desc, reference) } @@ -201,7 +196,6 @@ func (ds *DeletableStore) Resolve(ctx context.Context, reference string) (ocispe if reference == "" { return ocispec.Descriptor{}, errdef.ErrMissingReference } - // attempt resolving manifest desc, err := ds.tagResolver.Resolve(ctx, reference) if err != nil { @@ -211,11 +205,9 @@ func (ds *DeletableStore) Resolve(ctx context.Context, reference string) (ocispe } return ocispec.Descriptor{}, err } - if reference == desc.Digest.String() { return descriptor.Plain(desc), nil } - return desc, nil } @@ -249,7 +241,6 @@ func (ds *DeletableStore) ensureOCILayoutFile() error { if !os.IsNotExist(err) { return fmt.Errorf("failed to open OCI layout file: %w", err) } - layout := ocispec.ImageLayout{ Version: ocispec.ImageLayoutVersion, } @@ -260,7 +251,6 @@ func (ds *DeletableStore) ensureOCILayoutFile() error { return os.WriteFile(layoutFilePath, layoutJSON, 0666) } defer layoutFile.Close() - var layout ocispec.ImageLayout err = json.NewDecoder(layoutFile).Decode(&layout) if err != nil { @@ -277,7 +267,6 @@ func (ds *DeletableStore) loadIndexFile(ctx context.Context) error { if !os.IsNotExist(err) { return fmt.Errorf("failed to open index file: %w", err) } - // write index.json if it does not exist ds.index = &ocispec.Index{ Versioned: specs.Versioned{ @@ -288,7 +277,6 @@ func (ds *DeletableStore) loadIndexFile(ctx context.Context) error { return ds.writeIndexFile() } defer indexFile.Close() - var index ocispec.Index if err := json.NewDecoder(indexFile).Decode(&index); err != nil { return fmt.Errorf("failed to decode index file: %w", err) @@ -349,7 +337,7 @@ func (ds *DeletableStore) writeIndexFile() error { return os.WriteFile(ds.indexPath, indexJSON, 0666) } -// loadIndexInDeletableMemory loads index into memory. +// loadIndexInDeletableMemory loads index into the memory. func loadIndexInDeletableMemory(ctx context.Context, index *ocispec.Index, fetcher content.Fetcher, tagger content.Tagger, graph *graph.DeletableMemory) error { for _, desc := range index.Manifests { if err := tagger.Tag(ctx, deleteAnnotationRefName(desc), desc.Digest.String()); err != nil { diff --git a/content/oci/storage.go b/content/oci/storage.go index a1803e9a..98df6428 100644 --- a/content/oci/storage.go +++ b/content/oci/storage.go @@ -114,7 +114,6 @@ 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) } diff --git a/content/oci/storage_test.go b/content/oci/storage_test.go index c4f8aa95..6c30cba2 100644 --- a/content/oci/storage_test.go +++ b/content/oci/storage_test.go @@ -385,18 +385,15 @@ func TestStorage_Delete(t *testing.T) { Digest: digest.FromBytes(content), Size: int64(len(content)), } - tempDir := t.TempDir() s, err := NewStorage(tempDir) if err != nil { t.Fatal("New() error =", err) } ctx := context.Background() - if err := s.Push(ctx, desc, bytes.NewReader(content)); err != nil { t.Fatal("Storage.Push() error =", err) } - exists, err := s.Exists(ctx, desc) if err != nil { t.Fatal("Storage.Exists() error =", err) @@ -404,7 +401,6 @@ func TestStorage_Delete(t *testing.T) { if !exists { t.Errorf("Storage.Exists() = %v, want %v", exists, true) } - err = s.Delete(ctx, desc) if err != nil { t.Fatal("Storage.Delete() error =", err) diff --git a/internal/graph/deletablememory.go b/internal/graph/deletablememory.go index 1a093edf..49ef64dc 100644 --- a/internal/graph/deletablememory.go +++ b/internal/graph/deletablememory.go @@ -56,7 +56,6 @@ func (m *DeletableMemory) Index(ctx context.Context, fetcher content.Fetcher, no func (m *DeletableMemory) IndexAll(ctx context.Context, fetcher content.Fetcher, node ocispec.Descriptor) error { // track content status tracker := status.NewTracker() - var fn syncutil.GoFunc[ocispec.Descriptor] fn = func(ctx context.Context, region *syncutil.LimitedRegion, desc ocispec.Descriptor) error { // skip the node if other go routine is working on it @@ -64,7 +63,6 @@ func (m *DeletableMemory) IndexAll(ctx context.Context, fetcher content.Fetcher, if !committed { return nil } - successors, err := m.index(ctx, fetcher, desc) if err != nil { if errors.Is(err, errdef.ErrNotFound) { @@ -73,7 +71,6 @@ func (m *DeletableMemory) IndexAll(ctx context.Context, fetcher content.Fetcher, } return err } - if len(successors) > 0 { // traverse and index successors return syncutil.Go(ctx, nil, fn, successors...) @@ -92,7 +89,6 @@ func (m *DeletableMemory) IndexAll(ctx context.Context, fetcher content.Fetcher, func (m *DeletableMemory) Predecessors(_ context.Context, node ocispec.Descriptor) ([]ocispec.Descriptor, error) { m.lock.RLock() defer m.lock.RUnlock() - key := descriptor.FromOCI(node) set, exists := m.predecessors[key] if !exists { @@ -134,7 +130,6 @@ func (m *DeletableMemory) index(ctx context.Context, fetcher content.Fetcher, no // index the successors and predecessors successorSet := set.New[descriptor.Descriptor]() m.successors[nodeKey] = successorSet - for _, successor := range successors { successorKey := descriptor.FromOCI(successor) successorSet.Add(successorKey)