Skip to content

Commit 9a827e9

Browse files
Merge pull request opencontainers#1451 from runcom/force-delete-not-exists
Ignore error when force deleting a non-existing container
2 parents c128781 + d1a7436 commit 9a827e9

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

delete.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ status of "ubuntu01" as "stopped" the following will delete resources held for
5050
}
5151

5252
id := context.Args().First()
53+
force := context.Bool("force")
5354
container, err := getContainer(context)
5455
if err != nil {
5556
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
5960
if e := os.RemoveAll(path); e != nil {
6061
fmt.Fprintf(os.Stderr, "remove %s: %v\n", path, e)
6162
}
63+
if force {
64+
return nil
65+
}
6266
}
6367
return err
6468
}
@@ -72,7 +76,7 @@ status of "ubuntu01" as "stopped" the following will delete resources held for
7276
case libcontainer.Created:
7377
return killContainer(container)
7478
default:
75-
if context.Bool("force") {
79+
if force {
7680
return killContainer(container)
7781
} else {
7882
return fmt.Errorf("cannot delete container %s that is not stopped: %s\n", id, s)

tests/integration/delete.bats

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,8 @@ function teardown() {
4646
runc state test_busybox
4747
[ "$status" -ne 0 ]
4848
}
49+
50+
@test "runc delete --force ignore not exist" {
51+
runc delete --force notexists
52+
[ "$status" -eq 0 ]
53+
}

0 commit comments

Comments
 (0)