swipely/docker-api — pull request #144 by tylerhunt (2014-06-04 04:21:32+00:00)
Title: Prevent premature deletion of temporary tar files

This fixes the error reported in #133, in which creating an image could result in an error like:

No such file or directory @ unlink_internal - /var/folders/b9/3dxpcnmn7r7ff8dnvysqlf_80000gn/T/out20140603-32965-kdhtif

In this case, the image is built fine, but by the time `Container#build_from_dir` reaches the `ensure` block where the temporary Tar file is closed, the temporary file has already been removed. While I was unable to produce a failing test case, this was a reproducible issue in my own app, and this fix appears to resolve it.

I believe the issue is that Ruby's automatic unlinking of the temporary file is kicking in at some point while the build is in progress (maybe during GC, though `GC.start` alone didn't seem to trigger it my test), since there is no longer a reference to the `Tempfile` instance after the `Util#create_dir_tar` method has returned.