summaryrefslogtreecommitdiff
path: root/pkg/domain/infra/abi/containers.go
diff options
context:
space:
mode:
authorDaniel J Walsh <dwalsh@redhat.com>2021-01-18 14:49:53 -0500
committerDaniel J Walsh <dwalsh@redhat.com>2021-01-20 07:37:13 -0500
commite7df73efadd36e2489954ee9a766a3fbfe4eafeb (patch)
tree4d27e452a26e4b6d6f942c80da75940ee57d5582 /pkg/domain/infra/abi/containers.go
parent7d024a2fc8c675e4d34e3b34b56b6217a48ef9ce (diff)
downloadpodman-e7df73efadd36e2489954ee9a766a3fbfe4eafeb.tar.gz
podman-e7df73efadd36e2489954ee9a766a3fbfe4eafeb.tar.bz2
podman-e7df73efadd36e2489954ee9a766a3fbfe4eafeb.zip
Fix handling of container remove
I found several problems with container remove podman-remote rm --all Was not handled podman-remote rm --ignore Was not handled Return better errors when attempting to remove an --external container. Currently we return the container does not exists, as opposed to container is an external container that is being used. This patch also consolidates the tunnel code to use the same code for removing the container, as the local API, removing duplication of code and potential problems. Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
Diffstat (limited to 'pkg/domain/infra/abi/containers.go')
-rw-r--r--pkg/domain/infra/abi/containers.go30
1 files changed, 15 insertions, 15 deletions
diff --git a/pkg/domain/infra/abi/containers.go b/pkg/domain/infra/abi/containers.go
index a8f4d44a8..48a32817d 100644
--- a/pkg/domain/infra/abi/containers.go
+++ b/pkg/domain/infra/abi/containers.go
@@ -264,30 +264,30 @@ func (ic *ContainerEngine) ContainerRm(ctx context.Context, namesOrIds []string,
reports := []*entities.RmReport{}
names := namesOrIds
- for _, cidFile := range options.CIDFiles {
- content, err := ioutil.ReadFile(cidFile)
- if err != nil {
- return nil, errors.Wrap(err, "error reading CIDFile")
- }
- id := strings.Split(string(content), "\n")[0]
- names = append(names, id)
- }
-
// Attempt to remove named containers directly from storage, if container is defined in libpod
// this will fail and code will fall through to removing the container from libpod.`
tmpNames := []string{}
for _, ctr := range names {
report := entities.RmReport{Id: ctr}
- if err := ic.Libpod.RemoveStorageContainer(ctr, options.Force); err != nil {
+ report.Err = ic.Libpod.RemoveStorageContainer(ctr, options.Force)
+ switch errors.Cause(report.Err) {
+ case nil:
// remove container names that we successfully deleted
- tmpNames = append(tmpNames, ctr)
- } else {
reports = append(reports, &report)
+ case define.ErrNoSuchCtr:
+ // There is still a potential this is a libpod container
+ tmpNames = append(tmpNames, ctr)
+ default:
+ if _, err := ic.Libpod.LookupContainer(ctr); errors.Cause(err) == define.ErrNoSuchCtr {
+ // remove container failed, but not a libpod container
+ reports = append(reports, &report)
+ continue
+ }
+ // attempt to remove as a libpod container
+ tmpNames = append(tmpNames, ctr)
}
}
- if len(tmpNames) < len(names) {
- names = tmpNames
- }
+ names = tmpNames
ctrs, err := getContainersByContext(options.All, options.Latest, names, ic.Libpod)
if err != nil && !(options.Ignore && errors.Cause(err) == define.ErrNoSuchCtr) {