-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
specifying --force,podman exit with 0 #14782
Changes from 1 commit
57bcd20
a197ff9
f8d2145
ef3546f
e1c9286
cab23bb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,9 +2,9 @@ package images | |
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/containers/podman/v4/cmd/podman/common" | ||
"github.com/containers/podman/v4/cmd/podman/registry" | ||
"github.com/containers/podman/v4/libpod/define" | ||
"github.com/containers/podman/v4/pkg/domain/entities" | ||
"github.com/containers/podman/v4/pkg/errorhandling" | ||
"github.com/pkg/errors" | ||
|
@@ -82,6 +82,9 @@ func rm(cmd *cobra.Command, args []string) error { | |
} | ||
} | ||
registry.SetExitCode(report.ExitCode) | ||
if imageOpts.Force && registry.GetExitCode() == 1 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should only happen if the error is image does not exist, and this is the only error returned. |
||
registry.SetExitCode(define.ExecErrorCodeIgnore) | ||
} | ||
} | ||
|
||
return errorhandling.JoinErrors(rmErrors) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,6 +71,9 @@ func networkRm(cmd *cobra.Command, args []string) error { | |
fmt.Println(r.Name) | ||
} else { | ||
setExitCode(r.Err) | ||
if networkRmOptions.Force && registry.GetExitCode() == 1 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should only happen if the error is network does not exist, and this is the only error returned. |
||
registry.SetExitCode(define.ExecErrorCodeIgnore) | ||
} | ||
errs = append(errs, r.Err) | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -94,6 +94,9 @@ func removePods(namesOrIDs []string, rmOptions entities.PodRmOptions, printIDs b | |
responses, err := registry.ContainerEngine().PodRm(context.Background(), namesOrIDs, rmOptions) | ||
if err != nil { | ||
setExitCode(err) | ||
if rmOptions.Force && registry.GetExitCode() == 1 { | ||
registry.SetExitCode(define.ExecErrorCodeIgnore) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should only happen if the error is pod does not exist, and this is the only error returned. |
||
} | ||
return err | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -106,6 +106,9 @@ func Execute() { | |||
fmt.Fprintln(os.Stderr, "Cannot connect to Podman. Please verify your connection to the Linux system using `podman system connection list`, or try `podman machine init` and `podman machine start` to manage a new Linux VM") | ||||
} | ||||
} | ||||
if registry.GetExitCode() == define.ExecErrorCodeIgnore { | ||||
registry.SetExitCode(0) | ||||
} | ||||
Comment on lines
+109
to
+111
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do not use a special code for this, this will fail when a container exits with 128. Just set the exit code to 0 when you change it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I also think definition 128 is not good, but any error will make the return value not 0 Line 100 in 3426d56
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you could make the setExitCode function return the error and then set it to nil if it should not error Or maybe more easy make --force imply --ignore, that should work al tleast for the commands who have --ignore. |
||||
fmt.Fprintln(os.Stderr, formatError(err)) | ||||
} | ||||
os.Exit(registry.GetExitCode()) | ||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -73,6 +73,9 @@ func rm(cmd *cobra.Command, args []string) error { | |
fmt.Println(r.Id) | ||
} else { | ||
setExitCode(r.Err) | ||
if rmOptions.Force && registry.GetExitCode() == 1 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should only happen if the error is volume does not exist, and this is the only error returned. |
||
registry.SetExitCode(define.ExecErrorCodeIgnore) | ||
} | ||
errs = append(errs, r.Err) | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should only happen if the error is container does not exist, and this is the only error returned.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I recommend moving this into setExitCode() this will make the code much cleaner, same for the other places.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem with that is the NOEXIST errors are all different.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How are they all different? The setExitCode() already take care of setting this, so all what needs to be done is check if --force is set
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am saying the current code is incorrect since errors other then NOTEXIST should be reported --force rm should only not fail if the Object does not exist.