podman stop --cidfile missing --ignore

Podman should ignore failures to find a cidfile when stoping the
container if the user specified --ignore

Fixes: https://github.com/containers/podman/issues/19546

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
This commit is contained in:
Daniel J Walsh
2023-08-08 09:33:09 -04:00
parent 331d618a8a
commit f55c48ad3a
4 changed files with 15 additions and 0 deletions

View File

@ -2,6 +2,7 @@ package containers
import (
"context"
"errors"
"fmt"
"os"
"strings"
@ -110,6 +111,9 @@ func stop(cmd *cobra.Command, args []string) error {
for _, cidFile := range stopCidFiles {
content, err := os.ReadFile(cidFile)
if err != nil {
if stopOptions.Ignore && errors.Is(err, os.ErrNotExist) {
continue
}
return fmt.Errorf("reading CIDFile: %w", err)
}
id := strings.Split(string(content), "\n")[0]

View File

@ -20,6 +20,8 @@ Remove all containers. Can be used in conjunction with **-f** as well.
@@option cidfile.read
Command does not fail when *file* is missing and user specified --ignore.
#### **--depend**
Remove selected container and recursively remove all containers that depend on it.

View File

@ -23,6 +23,8 @@ Stop all running containers. This does not include paused containers.
@@option cidfile.read
Command does not fail when *file* is missing and user specified --ignore.
#### **--filter**, **-f**=*filter*
Filter what containers are going to be stopped.

View File

@ -85,6 +85,13 @@ load helpers
run_podman stop --ignore $name
is "$output" "" "podman stop nonexistent container, with --ignore"
nosuchfile=$PODMAN_TMPDIR/no-such-file
run_podman 125 stop --cidfile=$nosuchfile
is "$output" "Error: reading CIDFile: open $nosuchfile: no such file or directory" "podman stop with missing cidfile, without --ignore"
run_podman stop --cidfile=$nosuchfile --ignore
is "$output" "" "podman stop with missing cidfile, with --ignore"
}