TomPoulton/hiera-eyaml — pull request #57 by hopecream (2013-12-03 08:10:24+00:00)
Title: Fix the decrypted tempfile might be deleted before it is securely erased

Sample Exception (ruby 1.9.3p448):

vendor/bundle/ruby/1.9.1/gems/hiera-eyaml-1.3.8/lib/hiera/backend/eyaml/utils.rb:36:in `initialize':
No such file or directory -
/var/folders/pf/z8kdlj_x1kj6zp70h0mbj3yr0000gn/T/eyaml_edit20131203-57895-h4r6cn (Errno::ENOENT)

from vendor/bundle/ruby/1.9.1/gems/hiera-eyaml-1.3.8/lib/hiera/backend/eyaml/utils.rb:36:in `open'
from vendor/bundle/ruby/1.9.1/gems/hiera-eyaml-1.3.8/lib/hiera/backend/eyaml/utils.rb:36:in `secure_file_delete'
from vendor/bundle/ruby/1.9.1/gems/hiera-eyaml-1.3.8/lib/hiera/backend/eyaml/actions/edit_action.rb:77:in `execute'
from vendor/bundle/ruby/1.9.1/gems/hiera-eyaml-1.3.8/lib/hiera/backend/eyaml/CLI.rb:110:in `execute'
from vendor/bundle/ruby/1.9.1/gems/hiera-eyaml-1.3.8/bin/eyaml:13:in `'
from bin/eyaml:23:in `load'
from bin/eyaml:23:in `

'
from bin/ruby_executable_hooks:15:in `eval'
from bin/ruby_executable_hooks:15:in `

'

The root cause is a Tempfile instance will be deleted by the ruby VM at an
unknown time when the instance is recycled by gc after it is closed. The
solution is to use Tempfile as a random file name generation method
only. Tempfile.close!() can guarantee the file is deleted immediately
when it is called. So the later manually created file is safe.

reference:
http://po-ru.com/diary/the-case-of-the-mysteriously-disappearing-file/