mirror of
https://github.com/containers/podman.git
synced 2025-05-21 00:56:36 +08:00
When retrieving volumes, only use exact names
We should not be fuzzy matching on volume names. Docker doesn't do it, and it doesn't make much sense. Everything requires exact matches for names - only IDs allow partial matches. Fixes #3635 Signed-off-by: Matthew Heon <matthew.heon@pm.me>
This commit is contained in:
@ -2,7 +2,6 @@ package libpod
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/containers/libpod/libpod/define"
|
"github.com/containers/libpod/libpod/define"
|
||||||
"github.com/containers/libpod/libpod/events"
|
"github.com/containers/libpod/libpod/events"
|
||||||
@ -72,7 +71,7 @@ func (r *Runtime) RemoveVolumes(ctx context.Context, volumes []string, all, forc
|
|||||||
return deletedVols, nil
|
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) {
|
func (r *Runtime) GetVolume(name string) (*Volume, error) {
|
||||||
r.lock.RLock()
|
r.lock.RLock()
|
||||||
defer r.lock.RUnlock()
|
defer r.lock.RUnlock()
|
||||||
@ -82,20 +81,11 @@ func (r *Runtime) GetVolume(name string) (*Volume, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
vol, err := r.state.Volume(name)
|
vol, err := r.state.Volume(name)
|
||||||
if err == nil {
|
|
||||||
return vol, err
|
|
||||||
}
|
|
||||||
|
|
||||||
vols, err := r.GetAllVolumes()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
for _, v := range vols {
|
|
||||||
if strings.HasPrefix(v.Name(), name) {
|
return vol, nil
|
||||||
return v, nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil, errors.Errorf("unable to find volume %s", name)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// HasVolume checks to see if a volume with the given name exists
|
// HasVolume checks to see if a volume with the given name exists
|
||||||
|
Reference in New Issue
Block a user