diff options
Diffstat (limited to 'libpod/runtime_volume.go')
-rw-r--r-- | libpod/runtime_volume.go | 29 |
1 files changed, 10 insertions, 19 deletions
diff --git a/libpod/runtime_volume.go b/libpod/runtime_volume.go index 68c6c107e..d05db936b 100644 --- a/libpod/runtime_volume.go +++ b/libpod/runtime_volume.go @@ -2,8 +2,8 @@ package libpod import ( "context" - "strings" + "github.com/containers/libpod/libpod/define" "github.com/containers/libpod/libpod/events" "github.com/pkg/errors" "github.com/sirupsen/logrus" @@ -26,7 +26,7 @@ func (r *Runtime) RemoveVolume(ctx context.Context, v *Volume, force bool) error defer r.lock.Unlock() if !r.valid { - return ErrRuntimeStopped + return define.ErrRuntimeStopped } if !v.valid { @@ -71,30 +71,21 @@ func (r *Runtime) RemoveVolumes(ctx context.Context, volumes []string, all, forc return deletedVols, nil } -// GetVolume retrieves a volume by its name +// GetVolume retrieves a volume given its full name. func (r *Runtime) GetVolume(name string) (*Volume, error) { r.lock.RLock() defer r.lock.RUnlock() if !r.valid { - return nil, ErrRuntimeStopped + return nil, define.ErrRuntimeStopped } vol, err := r.state.Volume(name) - if err == nil { - return vol, err - } - - vols, err := r.GetAllVolumes() if err != nil { return nil, err } - for _, v := range vols { - if strings.HasPrefix(v.Name(), name) { - return v, nil - } - } - return nil, errors.Errorf("unable to find volume %s", name) + + return vol, nil } // HasVolume checks to see if a volume with the given name exists @@ -103,7 +94,7 @@ func (r *Runtime) HasVolume(name string) (bool, error) { defer r.lock.RUnlock() if !r.valid { - return false, ErrRuntimeStopped + return false, define.ErrRuntimeStopped } return r.state.HasVolume(name) @@ -118,7 +109,7 @@ func (r *Runtime) Volumes(filters ...VolumeFilter) ([]*Volume, error) { defer r.lock.RUnlock() if !r.valid { - return nil, ErrRuntimeStopped + return nil, define.ErrRuntimeStopped } vols, err := r.state.AllVolumes() @@ -147,7 +138,7 @@ func (r *Runtime) GetAllVolumes() ([]*Volume, error) { defer r.lock.RUnlock() if !r.valid { - return nil, ErrRuntimeStopped + return nil, define.ErrRuntimeStopped } return r.state.AllVolumes() @@ -167,7 +158,7 @@ func (r *Runtime) PruneVolumes(ctx context.Context) ([]string, []error) { for _, vol := range vols { if err := r.RemoveVolume(ctx, vol, false); err != nil { - if errors.Cause(err) != ErrVolumeBeingUsed && errors.Cause(err) != ErrVolumeRemoved { + if errors.Cause(err) != define.ErrVolumeBeingUsed && errors.Cause(err) != define.ErrVolumeRemoved { pruneErrors = append(pruneErrors, err) } continue |