diff --git a/content/oci/deletableoci.go b/content/oci/deletableoci.go index 34616afbf..b1098aa9b 100644 --- a/content/oci/deletableoci.go +++ b/content/oci/deletableoci.go @@ -3,7 +3,9 @@ Copyright The ORAS Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at + http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -97,6 +99,7 @@ func NewDeletableStoreWithContext(ctx context.Context, root string) (*DeletableS func (ds *DeletableStore) Fetch(ctx context.Context, target ocispec.Descriptor) (io.ReadCloser, error) { ds.lock.RLock() defer ds.lock.RUnlock() + return ds.storage.Fetch(ctx, target) } @@ -104,6 +107,7 @@ func (ds *DeletableStore) Fetch(ctx context.Context, target ocispec.Descriptor) func (ds *DeletableStore) Push(ctx context.Context, expected ocispec.Descriptor, reader io.Reader) error { ds.lock.Lock() defer ds.lock.Unlock() + if err := ds.storage.Push(ctx, expected, reader); err != nil { return err } @@ -121,6 +125,7 @@ func (ds *DeletableStore) Push(ctx context.Context, expected ocispec.Descriptor, func (ds *DeletableStore) Delete(ctx context.Context, target ocispec.Descriptor) error { ds.lock.Lock() defer ds.lock.Unlock() + resolvers := ds.tagResolver.Map() for reference, desc := range resolvers { if content.Equal(desc, target) { @@ -143,6 +148,7 @@ func (ds *DeletableStore) Delete(ctx context.Context, target ocispec.Descriptor) func (ds *DeletableStore) Exists(ctx context.Context, target ocispec.Descriptor) (bool, error) { ds.lock.RLock() defer ds.lock.RUnlock() + return ds.storage.Exists(ctx, target) } @@ -152,6 +158,7 @@ func (ds *DeletableStore) Exists(ctx context.Context, target ocispec.Descriptor) func (ds *DeletableStore) Tag(ctx context.Context, desc ocispec.Descriptor, reference string) error { ds.lock.Lock() defer ds.lock.Unlock() + if err := validateReference(reference); err != nil { return err } @@ -191,6 +198,7 @@ func (ds *DeletableStore) tag(ctx context.Context, desc ocispec.Descriptor, refe func (ds *DeletableStore) Resolve(ctx context.Context, reference string) (ocispec.Descriptor, error) { ds.lock.RLock() defer ds.lock.RUnlock() + if reference == "" { return ocispec.Descriptor{}, errdef.ErrMissingReference } @@ -215,6 +223,7 @@ func (ds *DeletableStore) Resolve(ctx context.Context, reference string) (ocispe func (ds *DeletableStore) Predecessors(ctx context.Context, node ocispec.Descriptor) ([]ocispec.Descriptor, error) { ds.lock.RLock() defer ds.lock.RUnlock() + return ds.graph.Predecessors(ctx, node) } @@ -228,6 +237,7 @@ func (ds *DeletableStore) Predecessors(ctx context.Context, node ocispec.Descrip func (ds *DeletableStore) Tags(ctx context.Context, last string, fn func(tags []string) error) error { ds.lock.RLock() defer ds.lock.RUnlock() + return listTags(ctx, ds.tagResolver, last, fn) } @@ -249,6 +259,7 @@ 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 { @@ -275,6 +286,7 @@ 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) @@ -291,6 +303,7 @@ func (ds *DeletableStore) loadIndexFile(ctx context.Context) error { func (ds *DeletableStore) SaveIndex() error { ds.lock.Lock() defer ds.lock.Unlock() + return ds.saveIndex() } diff --git a/content/oci/deletableoci_test.go b/content/oci/deletableoci_test.go index df3b8ff14..19d802eb8 100644 --- a/content/oci/deletableoci_test.go +++ b/content/oci/deletableoci_test.go @@ -11,8 +11,6 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Package oci provides access to an OCI content store. -// Reference: https://github.com/opencontainers/image-spec/blob/v1.1.0-rc4/image-layout.md package oci import (