summaryrefslogtreecommitdiff
path: root/libpod
diff options
context:
space:
mode:
authorNalin Dahyabhai <nalin@redhat.com>2019-04-22 16:41:17 -0400
committerNalin Dahyabhai <nalin@redhat.com>2019-04-25 08:57:58 -0400
commit5c81a117f16fde190acef331f5b88022fe11c550 (patch)
treea8aa0f3baaf59bf05e10479abc5a1d89206a0e80 /libpod
parentb01fdcbbd5344e89c3d9f3462c1df1764277d9fd (diff)
downloadpodman-5c81a117f16fde190acef331f5b88022fe11c550.tar.gz
podman-5c81a117f16fde190acef331f5b88022fe11c550.tar.bz2
podman-5c81a117f16fde190acef331f5b88022fe11c550.zip
images: add context to GetParent/IsParent/Remove/Prune...
Add a context.Context parameter to Image.GetParent(), Image.IsParent(), Image.GetChildren(), Image.Remove(), and Runtime.PruneImages(). Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
Diffstat (limited to 'libpod')
-rw-r--r--libpod/image/image.go16
-rw-r--r--libpod/image/prune.go6
-rw-r--r--libpod/runtime_img.go6
3 files changed, 15 insertions, 13 deletions
diff --git a/libpod/image/image.go b/libpod/image/image.go
index 757d034a2..588809bbc 100644
--- a/libpod/image/image.go
+++ b/libpod/image/image.go
@@ -353,8 +353,8 @@ func (i *Image) TopLayer() string {
// outside the context of images
// TODO: the force param does nothing as of now. Need to move container
// handling logic here eventually.
-func (i *Image) Remove(force bool) error {
- parent, err := i.GetParent()
+func (i *Image) Remove(ctx context.Context, force bool) error {
+ parent, err := i.GetParent(ctx)
if err != nil {
return err
}
@@ -363,11 +363,11 @@ func (i *Image) Remove(force bool) error {
}
i.newImageEvent(events.Remove)
for parent != nil {
- nextParent, err := parent.GetParent()
+ nextParent, err := parent.GetParent(ctx)
if err != nil {
return err
}
- children, err := parent.GetChildren()
+ children, err := parent.GetChildren(ctx)
if err != nil {
return err
}
@@ -1006,8 +1006,8 @@ func splitString(input string) string {
// IsParent goes through the layers in the store and checks if i.TopLayer is
// the parent of any other layer in store. Double check that image with that
// layer exists as well.
-func (i *Image) IsParent() (bool, error) {
- children, err := i.GetChildren()
+func (i *Image) IsParent(ctx context.Context) (bool, error) {
+ children, err := i.GetChildren(ctx)
if err != nil {
return false, err
}
@@ -1015,7 +1015,7 @@ func (i *Image) IsParent() (bool, error) {
}
// GetParent returns the image ID of the parent. Return nil if a parent is not found.
-func (i *Image) GetParent() (*Image, error) {
+func (i *Image) GetParent(ctx context.Context) (*Image, error) {
images, err := i.imageruntime.GetImages()
if err != nil {
return nil, err
@@ -1033,7 +1033,7 @@ func (i *Image) GetParent() (*Image, error) {
}
// GetChildren returns a list of the imageIDs that depend on the image
-func (i *Image) GetChildren() ([]string, error) {
+func (i *Image) GetChildren(ctx context.Context) ([]string, error) {
var children []string
images, err := i.imageruntime.GetImages()
if err != nil {
diff --git a/libpod/image/prune.go b/libpod/image/prune.go
index 5bd3c2c99..a4f8a0c9f 100644
--- a/libpod/image/prune.go
+++ b/libpod/image/prune.go
@@ -1,6 +1,8 @@
package image
import (
+ "context"
+
"github.com/containers/libpod/libpod/events"
"github.com/pkg/errors"
)
@@ -34,14 +36,14 @@ func (ir *Runtime) GetPruneImages(all bool) ([]*Image, error) {
// PruneImages prunes dangling and optionally all unused images from the local
// image store
-func (ir *Runtime) PruneImages(all bool) ([]string, error) {
+func (ir *Runtime) PruneImages(ctx context.Context, all bool) ([]string, error) {
var prunedCids []string
pruneImages, err := ir.GetPruneImages(all)
if err != nil {
return nil, errors.Wrap(err, "unable to get images to prune")
}
for _, p := range pruneImages {
- if err := p.Remove(true); err != nil {
+ if err := p.Remove(ctx, true); err != nil {
return nil, errors.Wrap(err, "failed to prune image")
}
defer p.newImageEvent(events.Prune)
diff --git a/libpod/runtime_img.go b/libpod/runtime_img.go
index 02f925fc6..5e9f65acc 100644
--- a/libpod/runtime_img.go
+++ b/libpod/runtime_img.go
@@ -57,7 +57,7 @@ func (r *Runtime) RemoveImage(ctx context.Context, img *image.Image, force bool)
}
}
- hasChildren, err := img.IsParent()
+ hasChildren, err := img.IsParent(ctx)
if err != nil {
return "", err
}
@@ -82,12 +82,12 @@ func (r *Runtime) RemoveImage(ctx context.Context, img *image.Image, force bool)
// reponames and no force is applied, we error out.
return "", fmt.Errorf("unable to delete %s (must force) - image is referred to in multiple tags", img.ID())
}
- err = img.Remove(force)
+ err = img.Remove(ctx, force)
if err != nil && errors.Cause(err) == storage.ErrImageUsedByContainer {
if errStorage := r.rmStorageContainers(force, img); errStorage == nil {
// Containers associated with the image should be deleted now,
// let's try removing the image again.
- err = img.Remove(force)
+ err = img.Remove(ctx, force)
} else {
err = errStorage
}