mirror of
https://github.com/containers/podman.git
synced 2025-06-24 03:08:13 +08:00
Merge pull request #18462 from Luap99/no-cleanup-twice
libpod: do not Cleanup() more than once
This commit is contained in:
@ -765,6 +765,11 @@ func (c *Container) Cleanup(ctx context.Context) error {
|
||||
return fmt.Errorf("container %s is running or paused, refusing to clean up: %w", c.ID(), define.ErrCtrStateInvalid)
|
||||
}
|
||||
|
||||
// if the container was not created in the oci runtime or was already cleaned up, then do nothing
|
||||
if c.ensureState(define.ContainerStateConfigured, define.ContainerStateExited) {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Handle restart policy.
|
||||
// Returns a bool indicating whether we actually restarted.
|
||||
// If we did, don't proceed to cleanup - just exit.
|
||||
|
@ -126,6 +126,12 @@ var _ = Describe("Podman stop", func() {
|
||||
finalCtrs.WaitWithDefaultTimeout()
|
||||
Expect(finalCtrs).Should(Exit(0))
|
||||
Expect(strings.TrimSpace(finalCtrs.OutputToString())).To(Equal(""))
|
||||
|
||||
// make sure we only have one cleanup event for this container
|
||||
events := podmanTest.Podman([]string{"events", "--since=30s", "--stream=false"})
|
||||
events.WaitWithDefaultTimeout()
|
||||
Expect(events).Should(Exit(0))
|
||||
Expect(strings.Count(events.OutputToString(), "container cleanup")).To(Equal(1), "cleanup event should show up exactly once")
|
||||
})
|
||||
|
||||
It("podman stop all containers -t", func() {
|
||||
|
Reference in New Issue
Block a user