Skip to content

Commit

Permalink
Merge pull request #2 from geaaru/fix-clean-docker-files
Browse files Browse the repository at this point in the history
Avoid exception if files .dockerinit / .dockerenv aren't present
  • Loading branch information
mudler authored Nov 11, 2017
2 parents a5c0400 + bd1bb75 commit 967d131
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions unpack.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,21 +141,27 @@ func Unpack(client *docker.Client, image string, dirname string, fatal bool) err

func prepareRootfs(dirname string, fatal bool) error {

err := os.Remove(dirname + SEPARATOR + ".dockerenv")
if err != nil {
if fatal == true {
return cli.NewExitError("could not remove docker env file", 86)
} else {
jww.WARN.Println(".dockerenv not found, extracting anyway")
_, err := os.Stat(dirname + SEPARATOR + ".dockerenv");
if err == nil {
err = os.Remove(dirname + SEPARATOR + ".dockerenv")
if err != nil {
if fatal == true {
return cli.NewExitError("could not remove docker env file", 86)
} else {
jww.WARN.Println("error on remove .dockerenv, extracting anyway")
}
}
}

err = os.Remove(dirname + SEPARATOR + ".dockerinit")
if err != nil {
if fatal == true {
return cli.NewExitError("could not remove docker init file", 86)
} else {
jww.WARN.Println(".dockerinit not found, extracting anyway")
_, err = os.Stat(dirname + SEPARATOR + ".dockerinit");
if err == nil {
err = os.Remove(dirname + SEPARATOR + ".dockerinit")
if err != nil {
if fatal == true {
return cli.NewExitError("could not remove docker init file", 86)
} else {
jww.WARN.Println("error on remove .dockerinit, extracting anyway")
}
}
}

Expand Down

0 comments on commit 967d131

Please sign in to comment.