Skip to content

Commit

Permalink
[NO TESTS NEEDED] Use same function podman-remote rmi as podman
Browse files Browse the repository at this point in the history
Make sure fixes that go into local podman commands also work in
podman-remote, by using the same function.

Since this is just a rewrite of existing code, existing tests should
handle it.

Signed-off-by: Daniel J Walsh <[email protected]>
  • Loading branch information
rhatdan authored and mheon committed Mar 29, 2021
1 parent 3d1aaff commit 62b49e1
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions pkg/api/handlers/compat/images_remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import (
"net/http"

"github.com/containers/podman/v3/libpod"
"github.com/containers/podman/v3/libpod/define"
"github.com/containers/podman/v3/pkg/api/handlers/utils"
"github.com/containers/podman/v3/pkg/domain/entities"
"github.com/containers/podman/v3/pkg/domain/infra/abi"
"github.com/gorilla/schema"
"github.com/pkg/errors"
)
Expand All @@ -30,28 +33,32 @@ func RemoveImage(w http.ResponseWriter, r *http.Request) {
}
}
name := utils.GetName(r)
newImage, err := runtime.ImageRuntime().NewFromLocal(name)
if err != nil {
utils.ImageNotFound(w, name, errors.Wrapf(err, "failed to find image %s", name))
return
imageEngine := abi.ImageEngine{Libpod: runtime}

options := entities.ImageRemoveOptions{
Force: query.Force,
}
report, rmerrors := imageEngine.Remove(r.Context(), []string{name}, options)
if len(rmerrors) > 0 && rmerrors[0] != nil {
err := rmerrors[0]
if errors.Cause(err) == define.ErrNoSuchImage {
utils.ImageNotFound(w, name, errors.Wrapf(err, "failed to find image %s", name))
return
}

results, err := runtime.RemoveImage(r.Context(), newImage, query.Force)
if err != nil {
utils.Error(w, "Something went wrong.", http.StatusInternalServerError, err)
return
}

response := make([]map[string]string, 0, len(results.Untagged)+1)
deleted := make(map[string]string, 1)
deleted["Deleted"] = results.Deleted
response = append(response, deleted)

for _, u := range results.Untagged {
response := make([]map[string]string, 0, len(report.Untagged)+1)
for _, d := range report.Deleted {
deleted := make(map[string]string, 1)
deleted["Deleted"] = d
response = append(response, deleted)
}
for _, u := range report.Untagged {
untagged := make(map[string]string, 1)
untagged["Untagged"] = u
response = append(response, untagged)
}

utils.WriteResponse(w, http.StatusOK, response)
}

0 comments on commit 62b49e1

Please sign in to comment.