ruby-changes:46676
From: nobu <ko1@a...>
Date: Fri, 19 May 2017 18:20:19 +0900 (JST)
Subject: [ruby-changes:46676] nobu:r58791 (trunk): tempfile.rb: remove in Tempfile.create
nobu 2017-05-19 18:20:14 +0900 (Fri, 19 May 2017) New Revision: 58791 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=58791 Log: 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. Modified files: trunk/lib/tempfile.rb trunk/test/test_tempfile.rb Index: test/test_tempfile.rb =================================================================== --- test/test_tempfile.rb (revision 58790) +++ test/test_tempfile.rb (revision 58791) @@ -343,6 +343,12 @@ puts Tempfile.new('foo').path https://github.com/ruby/ruby/blob/trunk/test/test_tempfile.rb#L343 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 Index: lib/tempfile.rb =================================================================== --- lib/tempfile.rb (revision 58790) +++ lib/tempfile.rb (revision 58791) @@ -334,8 +334,16 @@ def Tempfile.create(basename="", tmpdir= https://github.com/ruby/ruby/blob/trunk/lib/tempfile.rb#L334 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 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/