aboutsummaryrefslogtreecommitdiffstats
path: root/lib/tempfile.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/tempfile.rb')
-rw-r--r--lib/tempfile.rb8
1 files changed, 5 insertions, 3 deletions
diff --git a/lib/tempfile.rb b/lib/tempfile.rb
index b6270b827a..85b7720a48 100644
--- a/lib/tempfile.rb
+++ b/lib/tempfile.rb
@@ -334,10 +334,12 @@ 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
+ unless tmpfile.closed?
+ if File.identical?(tmpfile, tmpfile.path)
+ unlinked = File.unlink tmpfile.path rescue nil
+ end
+ tmpfile.close
end
- tmpfile.close
unless unlinked
begin
File.unlink tmpfile.path