From 73a677f2a51536ae42cb8317e8165d731804eb76 Mon Sep 17 00:00:00 2001 From: Xiaoxuan Wang Date: Wed, 11 Sep 2024 15:23:01 +0800 Subject: [PATCH] refinement Signed-off-by: Xiaoxuan Wang --- cmd/oras/root/manifest/index/update.go | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/cmd/oras/root/manifest/index/update.go b/cmd/oras/root/manifest/index/update.go index b2a40354b..66ab215b2 100644 --- a/cmd/oras/root/manifest/index/update.go +++ b/cmd/oras/root/manifest/index/update.go @@ -76,7 +76,7 @@ Example - update an index and tag the updated index as 'v2.1.0' and 'v2': } option.ApplyFlags(&opts, cmd.Flags()) cmd.Flags().StringArrayVarP(&opts.addArguments, "add", "", nil, "add manifests to the index") - cmd.Flags().StringArrayVarP(&opts.mergeArguments, "merge", "", nil, "merge the manifests of another index") + cmd.Flags().StringArrayVarP(&opts.mergeArguments, "merge", "", nil, "add all the manifests of another index to the index") cmd.Flags().StringArrayVarP(&opts.removeArguments, "remove", "", nil, "manifests to remove from the index") cmd.Flags().StringArrayVarP(&opts.tags, "tag", "", nil, "tags for the updated index") return oerrors.Command(cmd, &opts.Target) @@ -215,23 +215,23 @@ func removeManifestsFromIndex(ctx context.Context, manifests []ocispec.Descripto return removeManifests(manifests, digestSet, opts.Printer, opts.Reference) } -func removeManifests(manifests []ocispec.Descriptor, digestSet map[digest.Digest]bool, printer *output.Printer, indexRef string) ([]ocispec.Descriptor, error) { - newManifests := []ocispec.Descriptor{} - for i := 0; i < len(manifests); i++ { - if _, exists := digestSet[manifests[i].Digest]; exists { - digest := manifests[i].Digest +func removeManifests(originalManifests []ocispec.Descriptor, digestSet map[digest.Digest]bool, printer *output.Printer, indexRef string) ([]ocispec.Descriptor, error) { + manifests := []ocispec.Descriptor{} + for _, m := range originalManifests { + if _, exists := digestSet[m.Digest]; exists { + digest := m.Digest digestSet[digest] = true printUpdateStatus(status.IndexPromptRemoved, string(digest), "", printer) } else { - newManifests = append(newManifests, manifests[i]) + manifests = append(manifests, m) } } - for key, val := range digestSet { - if !val { - return nil, fmt.Errorf("%s does not exist in the index %s", key, indexRef) + for digest, visited := range digestSet { + if !visited { + return nil, fmt.Errorf("%s does not exist in the index %s", digest, indexRef) } } - return newManifests, nil + return manifests, nil } func printUpdateStatus(verb string, reference string, resolvedDigest string, printer *output.Printer) {