Skip to content

Commit

Permalink
moved loadFile function
Browse files Browse the repository at this point in the history
Signed-off-by: Xiaoxuan Wang <[email protected]>
  • Loading branch information
wangxiaoxuan273 committed Sep 12, 2023
1 parent cce32a1 commit fb078a0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
21 changes: 20 additions & 1 deletion content/oci/deletableOci.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
19 changes: 0 additions & 19 deletions content/oci/readonlyoci.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit fb078a0

Please sign in to comment.