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:
parent
94ddec6f9c
commit
3c5344bf30
2 changed files with 15 additions and 1 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue