aboutsummaryrefslogtreecommitdiffstats
path: root/lib/tempfile.rb
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-05-19 09:20:14 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-05-19 09:20:14 +0000
commitdc516c5235149f056aa2809a2c1609aaf4cfa84f (patch)
treefbfd86cb5a5bbbafafef9394ae3844d0cfb9c1d9 /lib/tempfile.rb
parent541c59cd25ccd70cece01237b88efb8e78964da5 (diff)
downloadruby-dc516c5235149f056aa2809a2c1609aaf4cfa84f.tar.gz
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
Diffstat (limited to 'lib/tempfile.rb')
-rw-r--r--lib/tempfile.rb10
1 files changed, 9 insertions, 1 deletions
diff --git a/lib/tempfile.rb b/lib/tempfile.rb
index b36c6638b6..b6270b827a 100644
--- a/lib/tempfile.rb
+++ b/lib/tempfile.rb
@@ -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