ensure tmp image is cleaned up on crash (addresses part of #58)
This commit is contained in:
parent
7d868096ca
commit
b1962b9ae5
@ -361,12 +361,17 @@ func saveImage(imageID string) (string, string) {
|
||||
tmpDir, err := ioutil.TempDir("", "dive")
|
||||
check(err)
|
||||
|
||||
cleanUpTmp := func() {
|
||||
os.RemoveAll(tmpDir)
|
||||
}
|
||||
|
||||
imageTarPath := filepath.Join(tmpDir, "image.tar")
|
||||
imageFile, err := os.Create(imageTarPath)
|
||||
check(err)
|
||||
|
||||
defer func() {
|
||||
if err := imageFile.Close(); err != nil {
|
||||
cleanUpTmp()
|
||||
logrus.Panic(err)
|
||||
}
|
||||
}()
|
||||
@ -379,6 +384,7 @@ func saveImage(imageID string) (string, string) {
|
||||
for {
|
||||
n, err := readCloser.Read(buf)
|
||||
if err != nil && err != io.EOF {
|
||||
cleanUpTmp()
|
||||
logrus.Panic(err)
|
||||
}
|
||||
if n == 0 {
|
||||
@ -392,11 +398,13 @@ func saveImage(imageID string) (string, string) {
|
||||
}
|
||||
|
||||
if _, err := imageWriter.Write(buf[:n]); err != nil {
|
||||
cleanUpTmp()
|
||||
logrus.Panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
if err = imageWriter.Flush(); err != nil {
|
||||
cleanUpTmp()
|
||||
logrus.Panic(err)
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user