diff options
author | Daniel J Walsh <dwalsh@redhat.com> | 2019-02-09 05:33:14 -0700 |
---|---|---|
committer | Daniel J Walsh <dwalsh@redhat.com> | 2019-02-09 05:33:14 -0700 |
commit | 233ba5bd894aac77db1bb2e41b0ef464f865d2a0 (patch) | |
tree | e937c8b78b0bc53374fa45f94e909582ed2c402c /libpod/runtime_ctr.go | |
parent | 1fd9be022fc1484c9bdebfc41008d2344237073c (diff) | |
download | podman-233ba5bd894aac77db1bb2e41b0ef464f865d2a0.tar.gz podman-233ba5bd894aac77db1bb2e41b0ef464f865d2a0.tar.bz2 podman-233ba5bd894aac77db1bb2e41b0ef464f865d2a0.zip |
Remove container from storage on --force
Currently we can get into a state where a container exists in
storage but does not exist in libpod. If the user forces a
removal of this container, then we should remove it from storage
even if the container is owned by another tool.
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
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) + } + } + } +} |