Merge pull request #703 from crosbymichael/delete
Remove container root dir from an aborted start
This commit is contained in:
commit
8fa5343b00
16
delete.go
16
delete.go
|
@ -1,6 +1,12 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import "github.com/codegangsta/cli"
|
import (
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
|
"github.com/codegangsta/cli"
|
||||||
|
"github.com/opencontainers/runc/libcontainer"
|
||||||
|
)
|
||||||
|
|
||||||
var deleteCommand = cli.Command{
|
var deleteCommand = cli.Command{
|
||||||
Name: "delete",
|
Name: "delete",
|
||||||
|
@ -17,6 +23,14 @@ status of "ubuntu01" as "destroyed" the following will delete resources held for
|
||||||
Action: func(context *cli.Context) {
|
Action: func(context *cli.Context) {
|
||||||
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 there was an aborted start or something of the sort then the container's directory could exist but
|
||||||
|
// libcontainer does not see it because the state.json file inside that directory was never created.
|
||||||
|
path := filepath.Join(context.GlobalString("root"), context.Args().First())
|
||||||
|
if err := os.RemoveAll(path); err == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
fatal(err)
|
fatal(err)
|
||||||
}
|
}
|
||||||
destroy(container)
|
destroy(container)
|
||||||
|
|
Loading…
Reference in New Issue