Skip to content

Commit

Permalink
Ignore error when force deleting a non-existing container
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
runcom committed May 16, 2017
1 parent c128781 commit c6a7477
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
6 changes: 5 additions & 1 deletion delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}
Expand All @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions tests/integration/delete.bats
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,7 @@ function teardown() {
runc state test_busybox
[ "$status" -ne 0 ]
}

@test "runc delete --force ignore not exist" {
runc delete --force notexists
}

0 comments on commit c6a7477

Please sign in to comment.