From f55c48ad3a5646ba41b7e64cdafecc15c0e95346 Mon Sep 17 00:00:00 2001 From: Daniel J Walsh Date: Tue, 8 Aug 2023 09:33:09 -0400 Subject: [PATCH] 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 --- cmd/podman/containers/stop.go | 4 ++++ docs/source/markdown/podman-rm.1.md.in | 2 ++ docs/source/markdown/podman-stop.1.md.in | 2 ++ test/system/050-stop.bats | 7 +++++++ 4 files changed, 15 insertions(+) diff --git a/cmd/podman/containers/stop.go b/cmd/podman/containers/stop.go index 9b7f012280..344f56c4f9 100644 --- a/cmd/podman/containers/stop.go +++ b/cmd/podman/containers/stop.go @@ -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] diff --git a/docs/source/markdown/podman-rm.1.md.in b/docs/source/markdown/podman-rm.1.md.in index 30c53922a4..a51a163c2e 100644 --- a/docs/source/markdown/podman-rm.1.md.in +++ b/docs/source/markdown/podman-rm.1.md.in @@ -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. diff --git a/docs/source/markdown/podman-stop.1.md.in b/docs/source/markdown/podman-stop.1.md.in index 4a6f09c744..d0c025afe2 100644 --- a/docs/source/markdown/podman-stop.1.md.in +++ b/docs/source/markdown/podman-stop.1.md.in @@ -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. diff --git a/test/system/050-stop.bats b/test/system/050-stop.bats index a21a036c2d..ecc3141026 100644 --- a/test/system/050-stop.bats +++ b/test/system/050-stop.bats @@ -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" }