Browse code

daemon: cleanupContainer: use state-fields instead of string form

This code only needed to know whether the container was paused; for other
states ("restarting", "running"), it's still used to be included in the
error string.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>

Sebastiaan van Stijn authored on 2025/05/09 02:42:27
Showing 1 changed files
... ...
@@ -88,10 +88,10 @@ func (daemon *Daemon) rmLink(cfg *config.Config, ctr *container.Container, name
88 88
 func (daemon *Daemon) cleanupContainer(ctr *container.Container, config backend.ContainerRmConfig) error {
89 89
 	if ctr.IsRunning() {
90 90
 		if !config.ForceRemove {
91
-			if state := ctr.StateString(); state == "paused" {
92
-				return errdefs.Conflict(fmt.Errorf("cannot remove container %q: container is %s and must be unpaused first", ctr.Name, state))
91
+			if ctr.Paused {
92
+				return errdefs.Conflict(fmt.Errorf("cannot remove container %q: container is paused and must be unpaused first", ctr.Name))
93 93
 			} else {
94
-				return errdefs.Conflict(fmt.Errorf("cannot remove container %q: container is %s: stop the container before removing or force remove", ctr.Name, state))
94
+				return errdefs.Conflict(fmt.Errorf("cannot remove container %q: container is %s: stop the container before removing or force remove", ctr.Name, ctr.StateString()))
95 95
 			}
96 96
 		}
97 97
 		if err := daemon.Kill(ctr); err != nil && !isNotRunning(err) {