From 91b86d9030e49558708ff02d7235911792ba49d2 Mon Sep 17 00:00:00 2001 From: Xiaoxuan Wang Date: Tue, 12 Sep 2023 07:59:01 +0000 Subject: [PATCH] moved loadFile function Signed-off-by: Xiaoxuan Wang --- content/oci/deletableOci.go | 21 ++++++++++++++++++++- content/oci/readonlyoci.go | 19 ------------------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/content/oci/deletableOci.go b/content/oci/deletableOci.go index 375103bc..5bb0a799 100644 --- a/content/oci/deletableOci.go +++ b/content/oci/deletableOci.go @@ -294,7 +294,7 @@ func (ds *DeletableStore) loadIndexFile(ctx context.Context) error { return fmt.Errorf("failed to decode index file: %w", err) } ds.index = &index - return loadIndexWithMemoryWithDelete(ctx, ds.index, ds.storage, ds.tagResolver, ds.graph) + return loadIndexInDeletableMemory(ctx, ds.index, ds.storage, ds.tagResolver, ds.graph) } // SaveIndex writes the `index.json` file to the file system. @@ -348,3 +348,22 @@ func (ds *DeletableStore) writeIndexFile() error { } return os.WriteFile(ds.indexPath, indexJSON, 0666) } + +// loadIndexInDeletableMemory loads index into 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 { + return err + } + if ref := desc.Annotations[ocispec.AnnotationRefName]; ref != "" { + if err := tagger.Tag(ctx, desc, ref); err != nil { + return err + } + } + plain := descriptor.Plain(desc) + if err := graph.IndexAll(ctx, fetcher, plain); err != nil { + return err + } + } + return nil +} diff --git a/content/oci/readonlyoci.go b/content/oci/readonlyoci.go index 8dd33b3b..eb94f61c 100644 --- a/content/oci/readonlyoci.go +++ b/content/oci/readonlyoci.go @@ -186,25 +186,6 @@ func loadIndex(ctx context.Context, index *ocispec.Index, fetcher content.Fetche return nil } -// loadIndex loads index into memory. -func loadIndexWithMemoryWithDelete(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 { - return err - } - if ref := desc.Annotations[ocispec.AnnotationRefName]; ref != "" { - if err := tagger.Tag(ctx, desc, ref); err != nil { - return err - } - } - plain := descriptor.Plain(desc) - if err := graph.IndexAll(ctx, fetcher, plain); err != nil { - return err - } - } - return nil -} - // resolveBlob returns a descriptor describing the blob identified by dgst. func resolveBlob(fsys fs.FS, dgst string) (ocispec.Descriptor, error) { path, err := blobPath(digest.Digest(dgst))