summaryrefslogtreecommitdiff
path: root/libpod
diff options
context:
space:
mode:
authorMatthew Heon <matthew.heon@pm.me>2019-10-23 16:34:32 -0400
committerMatthew Heon <matthew.heon@pm.me>2019-10-23 16:34:32 -0400
commit84eea2b2c09385078d7b147954ec9be3da608214 (patch)
tree58fae8694c4c9f167ae9d8ce1ef2c6c52f161c5e /libpod
parent2e6c9aa4901b30653d814f4984663cf07fc5e57f (diff)
downloadpodman-84eea2b2c09385078d7b147954ec9be3da608214.tar.gz
podman-84eea2b2c09385078d7b147954ec9be3da608214.tar.bz2
podman-84eea2b2c09385078d7b147954ec9be3da608214.zip
Return a better error for volume name conflicts
When you try and create a new volume with the name of a volume that already exists, you presently get a thoroughly unhelpful error from `mkdir` as the volume attempts to create the directory it will be mounted at. An EEXIST out of mkdir is not particularly helpful to Podman users - it doesn't explain that the name is already taken by another volume. The solution here is potentially racy as the runtime is not locked, so someone else could take the name while we're still getting things set up, but that's a narrow timing window, and we will still return an error - just an error that's not as good as this one. Signed-off-by: Matthew Heon <matthew.heon@pm.me>
Diffstat (limited to 'libpod')
-rw-r--r--libpod/runtime_volume_linux.go9
1 files changed, 9 insertions, 0 deletions
diff --git a/libpod/runtime_volume_linux.go b/libpod/runtime_volume_linux.go
index ba4fff4be..5b05acea4 100644
--- a/libpod/runtime_volume_linux.go
+++ b/libpod/runtime_volume_linux.go
@@ -48,6 +48,15 @@ func (r *Runtime) newVolume(ctx context.Context, options ...VolumeCreateOption)
}
volume.config.CreatedTime = time.Now()
+ // Check if volume with given name exists.
+ exists, err := r.state.HasVolume(volume.config.Name)
+ if err != nil {
+ return nil, errors.Wrapf(err, "error checking if volume with name %s exists", volume.config.Name)
+ }
+ if exists {
+ return nil, errors.Wrapf(define.ErrVolumeExists, "volume with name %s already exists", volume.config.Name)
+ }
+
if volume.config.Driver == define.VolumeDriverLocal {
logrus.Debugf("Validating options for local driver")
// Validate options