From fb078a08e511f3df31c2d0c75c7ce9dd00146cb1 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..4a6df80c 100644 --- a/content/oci/deletableOci.go +++ b/content/oci/deletableOci.go @@ -294,7 +294,26 @@ 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 loadIndexWithDeletableMemory(ctx, ds.index, ds.storage, ds.tagResolver, ds.graph) +} + +// loadIndex loads index into memory. +func loadIndexWithDeletableMemory(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 } // SaveIndex writes the `index.json` file to the file system. 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))