summaryrefslogtreecommitdiff
path: root/cmd/podman
diff options
context:
space:
mode:
authorumohnani8 <umohnani@redhat.com>2018-07-06 11:55:02 -0400
committerAtomic Bot <atomic-devel@projectatomic.io>2018-07-12 18:56:33 +0000
commit4f188aa191f1d28be19af64317bd8512f5c0cac0 (patch)
treece729820a0ea0b22547ac9ef2dc62e99f15c7c3b /cmd/podman
parenta1f3d44497cbdc393063164b60a1875edf4e1548 (diff)
downloadpodman-4f188aa191f1d28be19af64317bd8512f5c0cac0.tar.gz
podman-4f188aa191f1d28be19af64317bd8512f5c0cac0.tar.bz2
podman-4f188aa191f1d28be19af64317bd8512f5c0cac0.zip
podman rmi should only untag image if parent of another
podman rmi was deleting an image even if it was a parent of another image. This fix just untags the image instead. This also fixes podman rmi to remove intermediate images of an image when the image is removed. Signed-off-by: umohnani8 <umohnani@redhat.com> Closes: #1055 Approved by: mheon
Diffstat (limited to 'cmd/podman')
-rw-r--r--cmd/podman/images.go28
1 files changed, 9 insertions, 19 deletions
diff --git a/cmd/podman/images.go b/cmd/podman/images.go
index fdf2eb02c..092326b1f 100644
--- a/cmd/podman/images.go
+++ b/cmd/podman/images.go
@@ -7,7 +7,8 @@ import (
"strings"
"time"
- "github.com/containers/storage"
+ "github.com/sirupsen/logrus"
+
"github.com/docker/go-units"
digest "github.com/opencontainers/go-digest"
"github.com/pkg/errors"
@@ -259,12 +260,16 @@ func sortImagesOutput(sortBy string, imagesOutput imagesSorted) imagesSorted {
}
// getImagesTemplateOutput returns the images information to be printed in human readable format
-func getImagesTemplateOutput(ctx context.Context, runtime *libpod.Runtime, images []*image.Image, opts imagesOptions, storageLayers []storage.Layer) (imagesOutput imagesSorted) {
+func getImagesTemplateOutput(ctx context.Context, runtime *libpod.Runtime, images []*image.Image, opts imagesOptions) (imagesOutput imagesSorted) {
for _, img := range images {
// If all is false and the image doesn't have a name, check to see if the top layer of the image is a parent
// to another image's top layer. If it is, then it is an intermediate image so don't print out if the --all flag
// is not set.
- if !opts.all && len(img.Names()) == 0 && !layerIsLeaf(storageLayers, img.TopLayer()) {
+ isParent, err := img.IsParent()
+ if err != nil {
+ logrus.Errorf("error checking if image is a parent %q: %v", img.ID(), err)
+ }
+ if !opts.all && len(img.Names()) == 0 && isParent {
continue
}
createdTime := img.Created()
@@ -325,17 +330,13 @@ func generateImagesOutput(ctx context.Context, runtime *libpod.Runtime, images [
return nil
}
var out formats.Writer
- storageLayers, err := runtime.GetLayers()
- if err != nil {
- return errors.Wrap(err, "error getting layers from store")
- }
switch opts.format {
case formats.JSONString:
imagesOutput := getImagesJSONOutput(ctx, runtime, images)
out = formats.JSONStructArray{Output: imagesToGeneric([]imagesTemplateParams{}, imagesOutput)}
default:
- imagesOutput := getImagesTemplateOutput(ctx, runtime, images, opts, storageLayers)
+ imagesOutput := getImagesTemplateOutput(ctx, runtime, images, opts)
out = formats.StdoutTemplateArray{Output: imagesToGeneric(imagesOutput, []imagesJSONParams{}), Template: opts.outputformat, Fields: imagesOutput[0].HeaderMap()}
}
return formats.Writer(out).Out()
@@ -391,14 +392,3 @@ func CreateFilterFuncs(ctx context.Context, r *libpod.Runtime, c *cli.Context, i
}
return filterFuncs, nil
}
-
-// layerIsLeaf goes through the layers in the store and checks if "layer" is
-// the parent of any other layer in store.
-func layerIsLeaf(storageLayers []storage.Layer, layer string) bool {
- for _, storeLayer := range storageLayers {
- if storeLayer.Parent == layer {
- return false
- }
- }
- return true
-}