diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2019-02-11 20:31:03 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-02-11 20:31:03 +0100 |
commit | b7a3685cbae421bfd882c7c592b1721071cde984 (patch) | |
tree | afd620f98d18bdbb35cd584758332ad0dae62670 /libpod/runtime_ctr.go | |
parent | 112a5ab20cd6a07bcfcccadd0c0b851927a16f05 (diff) | |
parent | 233ba5bd894aac77db1bb2e41b0ef464f865d2a0 (diff) | |
download | podman-b7a3685cbae421bfd882c7c592b1721071cde984.tar.gz podman-b7a3685cbae421bfd882c7c592b1721071cde984.tar.bz2 podman-b7a3685cbae421bfd882c7c592b1721071cde984.zip |
Merge pull request #2281 from rhatdan/deleteContainer
Remove container from storage on --force
Diffstat (limited to 'libpod/runtime_ctr.go')
-rw-r--r-- | libpod/runtime_ctr.go | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/libpod/runtime_ctr.go b/libpod/runtime_ctr.go index 9afdef7b6..4f8192198 100644 --- a/libpod/runtime_ctr.go +++ b/libpod/runtime_ctr.go @@ -10,7 +10,9 @@ import ( "strings" "time" + "github.com/containers/libpod/libpod/image" "github.com/containers/libpod/pkg/rootless" + "github.com/containers/storage" "github.com/containers/storage/pkg/stringid" spec "github.com/opencontainers/runtime-spec/specs-go" "github.com/pkg/errors" @@ -564,3 +566,16 @@ func (r *Runtime) Export(name string, path string) error { return ctr.Export(path) } + +// RemoveContainersFromStorage attempt to remove containers from storage that do not exist in libpod database +func (r *Runtime) RemoveContainersFromStorage(ctrs []string) { + for _, i := range ctrs { + // if the container does not exist in database, attempt to remove it from storage + if _, err := r.LookupContainer(i); err != nil && errors.Cause(err) == image.ErrNoSuchCtr { + r.storageService.UnmountContainerImage(i, true) + if err := r.storageService.DeleteContainer(i); err != nil && errors.Cause(err) != storage.ErrContainerUnknown { + logrus.Errorf("Failed to remove container %q from storage: %s", i, err) + } + } + } +} |