summaryrefslogtreecommitdiff
path: root/libpod
diff options
context:
space:
mode:
authorPaul Holzinger <paul.holzinger@web.de>2020-08-03 22:21:24 +0200
committerPaul Holzinger <paul.holzinger@web.de>2020-08-04 11:39:27 +0200
commit97b2b079532ba983820e259b96ede027b846888b (patch)
treed11b7e2133d8bd8298c26440989531d49703592e /libpod
parent1709335cf04e947117d4ae4dca72f24f4095511b (diff)
downloadpodman-97b2b079532ba983820e259b96ede027b846888b.tar.gz
podman-97b2b079532ba983820e259b96ede027b846888b.tar.bz2
podman-97b2b079532ba983820e259b96ede027b846888b.zip
Improve error message when creating a pod/ctr with the same name
Check if there is an pod or container an return the appropriate error message instead of blindly return 'container exists' with `podman create` and 'pod exists' with `podman pod create`. Signed-off-by: Paul Holzinger <paul.holzinger@web.de>
Diffstat (limited to 'libpod')
-rw-r--r--libpod/boltdb_state.go12
-rw-r--r--libpod/boltdb_state_internal.go12
2 files changed, 20 insertions, 4 deletions
diff --git a/libpod/boltdb_state.go b/libpod/boltdb_state.go
index e98a6e907..2575f0e86 100644
--- a/libpod/boltdb_state.go
+++ b/libpod/boltdb_state.go
@@ -2347,11 +2347,19 @@ func (s *BoltState) AddPod(pod *Pod) error {
// Check if we already have something with the given ID and name
idExist := idsBkt.Get(podID)
if idExist != nil {
- return errors.Wrapf(define.ErrPodExists, "ID %s is in use", pod.ID())
+ err = define.ErrPodExists
+ if allPodsBkt.Get(idExist) == nil {
+ err = define.ErrCtrExists
+ }
+ return errors.Wrapf(err, "ID \"%s\" is in use", pod.ID())
}
nameExist := namesBkt.Get(podName)
if nameExist != nil {
- return errors.Wrapf(define.ErrPodExists, "name %s is in use", pod.Name())
+ err = define.ErrPodExists
+ if allPodsBkt.Get(nameExist) == nil {
+ err = define.ErrCtrExists
+ }
+ return errors.Wrapf(err, "name \"%s\" is in use", pod.Name())
}
// We are good to add the pod
diff --git a/libpod/boltdb_state_internal.go b/libpod/boltdb_state_internal.go
index ddbd40da8..9be753d26 100644
--- a/libpod/boltdb_state_internal.go
+++ b/libpod/boltdb_state_internal.go
@@ -586,11 +586,19 @@ func (s *BoltState) addContainer(ctr *Container, pod *Pod) error {
// Check if we already have a container with the given ID and name
idExist := idsBucket.Get(ctrID)
if idExist != nil {
- return errors.Wrapf(define.ErrCtrExists, "ID %s is in use", ctr.ID())
+ err = define.ErrCtrExists
+ if allCtrsBucket.Get(idExist) == nil {
+ err = define.ErrPodExists
+ }
+ return errors.Wrapf(err, "ID \"%s\" is in use", ctr.ID())
}
nameExist := namesBucket.Get(ctrName)
if nameExist != nil {
- return errors.Wrapf(define.ErrCtrExists, "name %s is in use", ctr.Name())
+ err = define.ErrCtrExists
+ if allCtrsBucket.Get(nameExist) == nil {
+ err = define.ErrPodExists
+ }
+ return errors.Wrapf(err, "name \"%s\" is in use", ctr.Name())
}
// No overlapping containers