tempfile.rb: remove in Tempfile.create

* lib/tempfile.rb (Tempfile.create): should not fail even if the
  temporary file has been removed in the block, just ignore.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58791 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2017-05-19 09:20:14 +00:00
parent 94ddec6f9c
commit 3c5344bf30
2 changed files with 15 additions and 1 deletions

View File

@ -334,8 +334,16 @@ def Tempfile.create(basename="", tmpdir=nil, mode: 0, **options)
begin begin
yield tmpfile yield tmpfile
ensure ensure
if File.identical?(tmpfile, tmpfile.path)
unlinked = File.unlink tmpfile.path rescue nil
end
tmpfile.close tmpfile.close
File.unlink tmpfile unless unlinked
begin
File.unlink tmpfile.path
rescue Errno::ENOENT
end
end
end end
else else
tmpfile tmpfile

View File

@ -343,6 +343,12 @@ puts Tempfile.new('foo').path
assert_file.exist?(path) assert_file.exist?(path)
} }
assert_file.not_exist?(path) assert_file.not_exist?(path)
Tempfile.create("tempfile-create") {|f|
path = f.path
File.unlink(f.path)
}
assert_file.not_exist?(path)
end end
def test_create_without_block def test_create_without_block