From 847564fa49b27af508a02a371583019482534d31 Mon Sep 17 00:00:00 2001 From: Yong Tang Date: Fri, 16 Dec 2016 21:11:53 -0800 Subject: [PATCH] Clean up tmp files for interrupted `docker build` This fix tries to fix the issue raised in 29486 where interrupted `docker build` leaves some tmp files in `/var/lib/docker/tmp`. With tmp file name prefixed with `/var/lib/docker/tmp/docker-builderXXXXXX`. The reason for the issue is that in `MakeTarSumContext()`: ``` if err := chrootarchive.Untar(sum, root, nil); err != nil { return nil, err } ``` the `err` is shadowed and caused the clean up function in `defer func()` not being called. This fix fixes the issue. This fix is tested manually, as was specified in 29486: ``` rm -rf /var/lib/docker/tmp mkdir repro && cd repro fallocate -l 300M bigfile cat > Dockerfile < --- builder/tarsum.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/builder/tarsum.go b/builder/tarsum.go index 35054dcba1..77d3142e7b 100644 --- a/builder/tarsum.go +++ b/builder/tarsum.go @@ -104,7 +104,8 @@ func MakeTarSumContext(tarStream io.Reader) (ModifiableContext, error) { return nil, err } - if err := chrootarchive.Untar(sum, root, nil); err != nil { + err = chrootarchive.Untar(sum, root, nil) + if err != nil { return nil, err }