1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

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
yield tmpfile
ensure
if File.identical?(tmpfile, tmpfile.path)
unlinked = File.unlink tmpfile.path rescue nil
end
tmpfile.close
File.unlink tmpfile
unless unlinked
begin
File.unlink tmpfile.path
rescue Errno::ENOENT
end
end
end
else
tmpfile

View file

@ -343,6 +343,12 @@ puts Tempfile.new('foo').path
assert_file.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
def test_create_without_block