[前][次][番号順一覧][スレッド一覧]

ruby-changes:62870

From: Jeremy <ko1@a...>
Date: Wed, 9 Sep 2020 21:11:35 +0900 (JST)
Subject: [ruby-changes:62870] 6997109fca (master): [ruby/tempfile] Revert Tempfile.open unlinking the file

https://git.ruby-lang.org/ruby.git/commit/?id=6997109fca

From 6997109fcaef0567f176e53dfc092aecc49f9ece Mon Sep 17 00:00:00 2001
From: Jeremy Evans <code@j...>
Date: Tue, 8 Sep 2020 12:02:56 -0700
Subject: [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

diff --git a/lib/tempfile.rb b/lib/tempfile.rb
index 4148d30..5f8a345 100644
--- a/lib/tempfile.rb
+++ b/lib/tempfile.rb
@@ -270,6 +270,13 @@ class Tempfile < DelegateClass(File) https://github.com/ruby/ruby/blob/trunk/lib/tempfile.rb#L270
     # 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) https://github.com/ruby/ruby/blob/trunk/lib/tempfile.rb#L297
         begin
           yield(tempfile)
         ensure
-          tempfile.close!
+          tempfile.close
         end
       else
         tempfile
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]