Skip to content

Commit

Permalink
fix: Allow to delete images when names of images are short digest ids…
Browse files Browse the repository at this point in the history
… of another images

Fixed not to run `canonicalRef.String()` when canonicalRef is nil.

    ```
    canonicalRef, err := referenceutil.ParseAny(req)
    ```

Also, fixed not to run TestIssue3016 on windows.

Signed-off-by: Hayato Kiwata <[email protected]>
  • Loading branch information
haytok committed Oct 17, 2024
1 parent 3580577 commit 4b228bb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
3 changes: 3 additions & 0 deletions cmd/nerdctl/image/image_remove_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,9 @@ func TestIssue3016(t *testing.T) {
testCase.SubTests = []*test.Case{
{
Description: "Issue #3016 - Tags created using the short digest ids of container images cannot be deleted using the nerdctl rmi command.",
Require: test.Require(
test.Not(test.Windows),
),
Setup: func(data test.Data, helpers test.Helpers) {
helpers.Ensure("pull", alpineImageName)
helpers.Ensure("pull", busyboxImageName)
Expand Down
6 changes: 4 additions & 2 deletions pkg/idutil/imagewalker/imagewalker.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,12 @@ type ImageWalker struct {
// Returns the number of the found entries.
func (w *ImageWalker) Walk(ctx context.Context, req string) (int, error) {
var filters []string
var canonicalRefStr string

canonicalRef, err := referenceutil.ParseAny(req)
if err == nil {
filters = append(filters, fmt.Sprintf("name==%s", canonicalRef.String()))
canonicalRefStr = canonicalRef.String()
filters = append(filters, fmt.Sprintf("name==%s", canonicalRefStr))
}
filters = append(filters,
fmt.Sprintf("name==%s", req),
Expand All @@ -75,7 +77,7 @@ func (w *ImageWalker) Walk(ctx context.Context, req string) (int, error) {
for i, image := range images {
uniqueImages[image.Target.Digest] = true
// to get target image index for `nerdctl rmi <short digest ids of another images>`.
if image.Name == canonicalRef.String() || image.Name == req {
if (canonicalRefStr != "" && image.Name == canonicalRefStr) || image.Name == req {
nameMatchIndex = i
}
}
Expand Down

0 comments on commit 4b228bb

Please sign in to comment.