diff options
author | Matthew Heon <matthew.heon@pm.me> | 2019-05-10 12:42:14 -0400 |
---|---|---|
committer | Matthew Heon <matthew.heon@pm.me> | 2019-05-10 14:14:29 -0400 |
commit | 5cbb3e7e9d14ff8e09e3a36c974d73e9c1a5b9a9 (patch) | |
tree | c669b0dcd63bc34371a990efd1dd8b66d732d5da /libpod/container_internal.go | |
parent | 627dbd49c5a80146e5806797243b63d0bd157760 (diff) | |
download | podman-5cbb3e7e9d14ff8e09e3a36c974d73e9c1a5b9a9.tar.gz podman-5cbb3e7e9d14ff8e09e3a36c974d73e9c1a5b9a9.tar.bz2 podman-5cbb3e7e9d14ff8e09e3a36c974d73e9c1a5b9a9.zip |
Use standard remove functions for removing pod ctrs
Instead of rewriting the logic, reuse the standard logic we use
for removing containers, which is much better tested.
Signed-off-by: Matthew Heon <matthew.heon@pm.me>
Diffstat (limited to 'libpod/container_internal.go')
-rw-r--r-- | libpod/container_internal.go | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/libpod/container_internal.go b/libpod/container_internal.go index e6ffaa6d7..fc33a1bbc 100644 --- a/libpod/container_internal.go +++ b/libpod/container_internal.go @@ -1490,3 +1490,25 @@ func (c *Container) copyWithTarFromImage(src, dest string) error { } return a.CopyWithTar(source, dest) } + +// checkReadyForRemoval checks whether the given container is ready to be +// removed. +// These checks are only used if force-remove is not specified. +// If it is, we'll remove the container anyways. +// Returns nil if safe to remove, or an error describing why it's unsafe if not. +func (c *Container) checkReadyForRemoval() error { + if c.state.State == ContainerStateUnknown { + return errors.Wrapf(ErrCtrStateInvalid, "container %s is in invalid state", c.ID()) + } + + if c.state.State == ContainerStateRunning || + c.state.State == ContainerStatePaused { + return errors.Wrapf(ErrCtrStateInvalid, "cannot remove container %s as it is %s - running or paused containers cannot be removed", c.ID(), c.state.State.String()) + } + + if len(c.state.ExecSessions) != 0 { + return errors.Wrapf(ErrCtrStateInvalid, "cannot remove container %s as it has active exec sessions", c.ID()) + } + + return nil +} |