(#14964) Unlink Tempfiles consistently across different ruby versions
The previous fix for #14964 relied on inconsisent behavior of ruby 1.8's
Tempfile#close! method, which is called by close(true). Although
the ruby documentation says close! is the same as delete followed by
unlink, the exact semantics are different. The former calls the
Tempfile's finalizer callback directly and can raise an Errno::EACCES,
while unlink never does.
In ruby 1.9, the Tempfile#close! method was changed to call unlink,
making the two APIs consistent. As a result, the begin-ensure block
added previously to fix #14964 was wrong.
Also, previously if the call to read failed, then the Tempfile would
not be closed and deleted until its finalizer ran.
This commit changes the wait_for_output method to close and unlink the
Tempfile in two steps. The unlink method will not raise an
Errno::EACCES in either ruby 1.8 or 1.9. It also changes the read
call to occur within the begin-ensure block, so that the Tempfile is
closed and unlinked as soon as we are done with it.
Paired-with: Andrew Parker <andy@puppetlabs.com>