Merge pull request #1451 from runcom/force-delete-not-exists

Ignore error when force deleting a non-existing container
This commit is contained in:
Michael Crosby 2017-05-18 09:44:26 -07:00 committed by GitHub
commit 9a827e90d2
2 changed files with 10 additions and 1 deletions

View File

@ -50,6 +50,7 @@ status of "ubuntu01" as "stopped" the following will delete resources held for
}
id := context.Args().First()
force := context.Bool("force")
container, err := getContainer(context)
if err != nil {
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 {
fmt.Fprintf(os.Stderr, "remove %s: %v\n", path, e)
}
if force {
return nil
}
}
return err
}
@ -72,7 +76,7 @@ status of "ubuntu01" as "stopped" the following will delete resources held for
case libcontainer.Created:
return killContainer(container)
default:
if context.Bool("force") {
if force {
return killContainer(container)
} else {
return fmt.Errorf("cannot delete container %s that is not stopped: %s\n", id, s)

View File

@ -46,3 +46,8 @@ function teardown() {
runc state test_busybox
[ "$status" -ne 0 ]
}
@test "runc delete --force ignore not exist" {
runc delete --force notexists
[ "$status" -eq 0 ]
}