summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorumohnani8 <umohnani@redhat.com>2018-07-27 16:11:47 -0400
committerAtomic Bot <atomic-devel@projectatomic.io>2018-07-28 01:40:28 +0000
commit87d8edb4c10e53e6e9833ff8b64c3c0041f1823b (patch)
treecc0f7c1b71844e97f13e7003b6d2d4c5d6a9652a
parentbd7566f170d6c6f595a4e1376cabb83a62479584 (diff)
downloadpodman-87d8edb4c10e53e6e9833ff8b64c3c0041f1823b.tar.gz
podman-87d8edb4c10e53e6e9833ff8b64c3c0041f1823b.tar.bz2
podman-87d8edb4c10e53e6e9833ff8b64c3c0041f1823b.zip
podman rmi shouldn't delete named referenced images
If an image is created from another and it is deleted, only delete the actual image and not the parent images if the parent images have names/references. Signed-off-by: umohnani8 <umohnani@redhat.com> Closes: #1174 Approved by: mheon
-rw-r--r--libpod/image/image.go2
-rw-r--r--test/e2e/rmi_test.go35
2 files changed, 36 insertions, 1 deletions
diff --git a/libpod/image/image.go b/libpod/image/image.go
index 0e236503d..112eeb015 100644
--- a/libpod/image/image.go
+++ b/libpod/image/image.go
@@ -363,7 +363,7 @@ func (i *Image) Remove(force bool) error {
}
// Do not remove if image is a base image and is not untagged, or if
// the image has more children.
- if (nextParent == nil && len(parent.Names()) > 0) || len(children) > 0 {
+ if len(children) > 0 || len(parent.Names()) > 0 {
return nil
}
id := parent.ID()
diff --git a/test/e2e/rmi_test.go b/test/e2e/rmi_test.go
index 2d096d7ba..0fdfa6797 100644
--- a/test/e2e/rmi_test.go
+++ b/test/e2e/rmi_test.go
@@ -141,6 +141,41 @@ var _ = Describe("Podman rmi", func() {
Expect(session.ExitCode()).To(Not(Equal(0)))
})
+ It("podman rmi image that is created from another named imaged", func() {
+ session := podmanTest.Podman([]string{"rmi", "-fa"})
+ session.WaitWithDefaultTimeout()
+ Expect(session.ExitCode()).To(Equal(0))
+
+ session = podmanTest.Podman([]string{"run", "--name", "c_test1", ALPINE, "true"})
+ session.WaitWithDefaultTimeout()
+ Expect(session.ExitCode()).To(Equal(0))
+
+ session = podmanTest.Podman([]string{"commit", "-q", "c_test1", "test1"})
+ session.WaitWithDefaultTimeout()
+ Expect(session.ExitCode()).To(Equal(0))
+
+ session = podmanTest.Podman([]string{"run", "--name", "c_test2", "test1", "true"})
+ session.WaitWithDefaultTimeout()
+ Expect(session.ExitCode()).To(Equal(0))
+
+ session = podmanTest.Podman([]string{"commit", "-q", "c_test2", "test2"})
+ session.WaitWithDefaultTimeout()
+ Expect(session.ExitCode()).To(Equal(0))
+
+ session = podmanTest.Podman([]string{"rm", "-a"})
+ session.WaitWithDefaultTimeout()
+ Expect(session.ExitCode()).To(Equal(0))
+
+ session = podmanTest.Podman([]string{"rmi", "test2"})
+ session.WaitWithDefaultTimeout()
+ Expect(session.ExitCode()).To(Equal(0))
+
+ session = podmanTest.Podman([]string{"images", "-q"})
+ session.WaitWithDefaultTimeout()
+ Expect(session.ExitCode()).To(Equal(0))
+ Expect(len(session.OutputToStringArray())).To(Equal(2))
+ })
+
It("podman rmi with cached images", func() {
session := podmanTest.Podman([]string{"rmi", "-fa"})
session.WaitWithDefaultTimeout()