Skip to content

Commit

Permalink
resolved comments
Browse files Browse the repository at this point in the history
Signed-off-by: Xiaoxuan Wang <[email protected]>
  • Loading branch information
wangxiaoxuan273 committed Oct 20, 2023
1 parent 053e677 commit d5c8a61
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
13 changes: 13 additions & 0 deletions content/oci/deletableoci.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -97,13 +99,15 @@ 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)
}

// Push pushes the content, matching the expected 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
}
Expand All @@ -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) {
Expand All @@ -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)
}

Expand All @@ -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
}
Expand Down Expand Up @@ -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
}
Expand All @@ -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)
}

Expand All @@ -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)
}

Expand All @@ -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 {
Expand All @@ -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)
Expand All @@ -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()
}

Expand Down
2 changes: 0 additions & 2 deletions content/oci/deletableoci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down

0 comments on commit d5c8a61

Please sign in to comment.