From d78e83f47d487c1680ae0e2a1db42ef9d70caf30 Mon Sep 17 00:00:00 2001 From: Matthew Heon Date: Wed, 24 Jun 2020 14:10:29 -0400 Subject: Add support for dangling filter to volumes The dangling filter determine whether a volume is dangling - IE, it has no containers attached using it. Unlike our other filters, this one is a boolean - must be true or false, not arbitrary values. Signed-off-by: Matthew Heon --- libpod/volume.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'libpod') diff --git a/libpod/volume.go b/libpod/volume.go index 82f389833..b29ac7ddf 100644 --- a/libpod/volume.go +++ b/libpod/volume.go @@ -137,7 +137,7 @@ func (v *Volume) Config() (*VolumeConfig, error) { // VolumeInUse goes through the container dependencies of a volume // and checks if the volume is being used by any container. -func (v *Volume) VolumesInUse() ([]string, error) { +func (v *Volume) VolumeInUse() ([]string, error) { v.lock.Lock() defer v.lock.Unlock() @@ -146,3 +146,13 @@ func (v *Volume) VolumesInUse() ([]string, error) { } return v.runtime.state.VolumeInUse(v) } + +// IsDangling returns whether this volume is dangling (unused by any +// containers). +func (v *Volume) IsDangling() (bool, error) { + ctrs, err := v.VolumeInUse() + if err != nil { + return false, err + } + return len(ctrs) == 0, nil +} -- cgit v1.2.3-54-g00ecf