summaryrefslogtreecommitdiff
path: root/lib/tempfile.rb
diff options
context:
space:
mode:
authorJeremy Evans <code@jeremyevans.net>2020-09-08 12:02:56 -0700
committerHiroshi SHIBATA <hsbt@ruby-lang.org>2020-09-09 20:15:41 +0900
commit6997109fcaef0567f176e53dfc092aecc49f9ece (patch)
tree362c0e14fc785a8d03073a07f5e2f7d1b74e0522 /lib/tempfile.rb
parent96f2b2e0864ad08ce0b5600f61832a8580ea5b05 (diff)
[ruby/tempfile] Revert Tempfile.open unlinking the file
Document difference in behavior between Tempfile.open and Tempfile.create. https://github.com/ruby/tempfile/commit/426d6f887f
Diffstat (limited to 'lib/tempfile.rb')
-rw-r--r--lib/tempfile.rb9
1 files changed, 8 insertions, 1 deletions
diff --git a/lib/tempfile.rb b/lib/tempfile.rb
index 4148d30a86..5f8a345bee 100644
--- a/lib/tempfile.rb
+++ b/lib/tempfile.rb
@@ -270,6 +270,13 @@ class Tempfile < DelegateClass(File)
# object will be automatically closed after the block terminates.
# The call returns the value of the block.
#
+ # Unlike Tempfile.create, Tempfile.open when called with a block
+ # does not unlink the temporary file when the block exits. When using
+ # Tempfile.open, the temporary file is not unlinked from the file
+ # system unless Tempfile#unlink or Tempfile#close! is called directly,
+ # or until the Tempfile instance is garbage collected. Due to this,
+ # most callers of Tempfile.open with a block should use Tempfile.create instead.
+ #
# In any case, all arguments (<code>*args</code>) will be passed to Tempfile.new.
#
# Tempfile.open('foo', '/home/temp') do |f|
@@ -290,7 +297,7 @@ class Tempfile < DelegateClass(File)
begin
yield(tempfile)
ensure
- tempfile.close!
+ tempfile.close
end
else
tempfile