mirror of
https://github.com/opencontainers/runc.git
synced 2026-07-11 06:03:57 +08:00
Ignore error when force deleting a non-existing container
This patch mimics the behavior of "rm -rf" so that if a container doesn't exist and you force delete it, it won't error out. Signed-off-by: Antonio Murdaca <runcom@redhat.com>
This commit is contained in:
@@ -50,6 +50,7 @@ status of "ubuntu01" as "stopped" the following will delete resources held for
|
|||||||
}
|
}
|
||||||
|
|
||||||
id := context.Args().First()
|
id := context.Args().First()
|
||||||
|
force := context.Bool("force")
|
||||||
container, err := getContainer(context)
|
container, err := getContainer(context)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if lerr, ok := err.(libcontainer.Error); ok && lerr.Code() == libcontainer.ContainerNotExists {
|
if lerr, ok := err.(libcontainer.Error); ok && lerr.Code() == libcontainer.ContainerNotExists {
|
||||||
@@ -59,6 +60,9 @@ status of "ubuntu01" as "stopped" the following will delete resources held for
|
|||||||
if e := os.RemoveAll(path); e != nil {
|
if e := os.RemoveAll(path); e != nil {
|
||||||
fmt.Fprintf(os.Stderr, "remove %s: %v\n", path, e)
|
fmt.Fprintf(os.Stderr, "remove %s: %v\n", path, e)
|
||||||
}
|
}
|
||||||
|
if force {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -72,7 +76,7 @@ status of "ubuntu01" as "stopped" the following will delete resources held for
|
|||||||
case libcontainer.Created:
|
case libcontainer.Created:
|
||||||
return killContainer(container)
|
return killContainer(container)
|
||||||
default:
|
default:
|
||||||
if context.Bool("force") {
|
if force {
|
||||||
return killContainer(container)
|
return killContainer(container)
|
||||||
} else {
|
} else {
|
||||||
return fmt.Errorf("cannot delete container %s that is not stopped: %s\n", id, s)
|
return fmt.Errorf("cannot delete container %s that is not stopped: %s\n", id, s)
|
||||||
|
|||||||
@@ -46,3 +46,8 @@ function teardown() {
|
|||||||
runc state test_busybox
|
runc state test_busybox
|
||||||
[ "$status" -ne 0 ]
|
[ "$status" -ne 0 ]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@test "runc delete --force ignore not exist" {
|
||||||
|
runc delete --force notexists
|
||||||
|
[ "$status" -eq 0 ]
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user