summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Heon <matthew.heon@gmail.com>2018-01-12 13:14:06 -0500
committerAtomic Bot <atomic-devel@projectatomic.io>2018-01-16 14:58:06 +0000
commitd90355ebe8c62b7ab9ee7638812808e3a8bd7aac (patch)
tree768b43debb22b77d75dcc08b098f303606c7b6db
parent20df2196f2158d8656d1b38580d816567843a5e0 (diff)
downloadpodman-d90355ebe8c62b7ab9ee7638812808e3a8bd7aac.tar.gz
podman-d90355ebe8c62b7ab9ee7638812808e3a8bd7aac.tar.bz2
podman-d90355ebe8c62b7ab9ee7638812808e3a8bd7aac.zip
Prevent containers with dependencies from being removed
Signed-off-by: Matthew Heon <matthew.heon@gmail.com> Closes: #220 Approved by: rhatdan
-rw-r--r--libpod/runtime_ctr.go11
1 files changed, 11 insertions, 0 deletions
diff --git a/libpod/runtime_ctr.go b/libpod/runtime_ctr.go
index 66dcb2f95..c1078e504 100644
--- a/libpod/runtime_ctr.go
+++ b/libpod/runtime_ctr.go
@@ -3,6 +3,7 @@ package libpod
import (
"os"
"path/filepath"
+ "strings"
"time"
spec "github.com/opencontainers/runtime-spec/specs-go"
@@ -124,6 +125,16 @@ func (r *Runtime) removeContainer(c *Container, force bool) error {
return errors.Wrapf(ErrCtrStateInvalid, "container %s is paused, cannot remove until unpaused", c.ID())
}
+ // Check that no other containers depend on the container
+ deps, err := r.state.ContainerInUse(c)
+ if err != nil {
+ return err
+ }
+ if len(deps) != 0 {
+ depsStr := strings.Join(deps, ", ")
+ return errors.Wrapf(ErrCtrExists, "container %s has dependent containers which must be removed before it: %s", c.ID(), depsStr)
+ }
+
// Check that the container's in a good state to be removed
if c.state.State == ContainerStateRunning && force {
if err := r.ociRuntime.stopContainer(c, c.StopTimeout()); err != nil {