diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2019-05-12 19:12:24 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-05-12 19:12:24 +0200 |
commit | d2571c7fd49d22e822a6f3b3796488218c9f9e46 (patch) | |
tree | 97480044298e621107090f1c5f11f4df9d433d76 /libpod/container_internal.go | |
parent | 9ae32214f466e2150b7bc383585f60694b53c4b3 (diff) | |
parent | c9c00ecd532fea4722b020f318daa1e34bc46fd0 (diff) | |
download | podman-d2571c7fd49d22e822a6f3b3796488218c9f9e46.tar.gz podman-d2571c7fd49d22e822a6f3b3796488218c9f9e46.tar.bz2 podman-d2571c7fd49d22e822a6f3b3796488218c9f9e46.zip |
Merge pull request #3105 from mheon/use_ctr_remove_funcs
Use standard remove functions for removing pod ctrs
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 +} |