diff options
author | Toshiki Sonoda <sonoda.toshiki@fujitsu.com> | 2022-07-26 10:00:52 +0900 |
---|---|---|
committer | Toshiki Sonoda <sonoda.toshiki@fujitsu.com> | 2022-07-27 09:44:48 +0900 |
commit | e4992fb8185bba20fbcf729a77fb4de6f9443278 (patch) | |
tree | af59e0a5878a176b5bb9ac86b8b7cb375e9bc8fb /cmd | |
parent | e9d29d71cb3185fc071ba4d5f353c9eff6ff349a (diff) | |
download | podman-e4992fb8185bba20fbcf729a77fb4de6f9443278.tar.gz podman-e4992fb8185bba20fbcf729a77fb4de6f9443278.tar.bz2 podman-e4992fb8185bba20fbcf729a77fb4de6f9443278.zip |
Fix: Restore a container which name is equal to a image name
If there is a match for both container and image, we restore the container.
Fixes: https://github.com/containers/podman/issues/15055
Signed-off-by: Toshiki Sonoda <sonoda.toshiki@fujitsu.com>
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/podman/containers/restore.go | 51 |
1 files changed, 34 insertions, 17 deletions
diff --git a/cmd/podman/containers/restore.go b/cmd/podman/containers/restore.go index 1e4745354..6106f2bed 100644 --- a/cmd/podman/containers/restore.go +++ b/cmd/podman/containers/restore.go @@ -93,32 +93,49 @@ func init() { } func restore(cmd *cobra.Command, args []string) error { - var errs utils.OutputErrors + var ( + e error + errs utils.OutputErrors + ) podmanStart := time.Now() if rootless.IsRootless() { return fmt.Errorf("restoring a container requires root") } - // Find out if this is an image - inspectOpts := entities.InspectOptions{} - imgData, _, err := registry.ImageEngine().Inspect(context.Background(), args, inspectOpts) - if err != nil { - return err + // Check if the container exists (#15055) + exists := &entities.BoolReport{Value: false} + for _, ctr := range args { + exists, e = registry.ContainerEngine().ContainerExists(registry.GetContext(), ctr, entities.ContainerExistsOptions{}) + if e != nil { + return e + } + if exists.Value { + break + } } - hostInfo, err := registry.ContainerEngine().Info(context.Background()) - if err != nil { - return err - } + if !exists.Value { + // Find out if this is an image + inspectOpts := entities.InspectOptions{} + imgData, _, err := registry.ImageEngine().Inspect(context.Background(), args, inspectOpts) + if err != nil { + return err + } - for i := range imgData { - restoreOptions.CheckpointImage = true - checkpointRuntimeName, found := imgData[i].Annotations[define.CheckpointAnnotationRuntimeName] - if !found { - return fmt.Errorf("image is not a checkpoint: %s", imgData[i].ID) + hostInfo, err := registry.ContainerEngine().Info(context.Background()) + if err != nil { + return err } - if hostInfo.Host.OCIRuntime.Name != checkpointRuntimeName { - return fmt.Errorf("container image \"%s\" requires runtime: \"%s\"", imgData[i].ID, checkpointRuntimeName) + + for i := range imgData { + restoreOptions.CheckpointImage = true + checkpointRuntimeName, found := imgData[i].Annotations[define.CheckpointAnnotationRuntimeName] + if !found { + return fmt.Errorf("image is not a checkpoint: %s", imgData[i].ID) + } + if hostInfo.Host.OCIRuntime.Name != checkpointRuntimeName { + return fmt.Errorf("container image \"%s\" requires runtime: \"%s\"", imgData[i].ID, checkpointRuntimeName) + } } } |