puppetlabs/puppet — pull request #3029 by cprice404 (2014-08-28 19:40:34+00:00)
Title: (PUP-3153) Guard against nil when closing Uniquefiles

In a recent commit we introduced `Uniquefile` to use in place
of `Tempfile` for certain code paths. Because `Uniquefile` does
not automatically delete files for you, it is necessary to call
`close!` explicitly if you wish to make sure that they get
removed.

In the original commit I did this in a few places in an `ensure`
block. However, I did not guard against the possibility that
an error might occur when attempting to instantiate the `Uniquefile`
object (e.g., file permissions error), and thus the calls to `close!`
in the `ensure` blocks may result in a NilClass exception (and also
mask the real error).

This commit adds guards to ensure that we only try to call `close!`
if the `Uniquefile` object was actually instantiated.