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

ruby-changes:62869

From: Hiroshi <ko1@a...>
Date: Wed, 9 Sep 2020 21:11:34 +0900 (JST)
Subject: [ruby-changes:62869] b194973dcd (master): Revert the related commits about `Tempfile.open` change.

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

From b194973dcd5eda6c9e256029ea39dc532ae18962 Mon Sep 17 00:00:00 2001
From: Hiroshi SHIBATA <hsbt@r...>
Date: Wed, 9 Sep 2020 20:52:48 +0900
Subject: Revert the related commits about `Tempfile.open` change.

  Start with https://github.com/ruby/ruby/commit/fa21985a7a2f8f52a8bd82bd12a724e9dca74934
  to https://github.com/ruby/ruby/commit/d7492a0be885ea9f2b9f71e3e95582f9a859c439

diff --git a/NEWS.md b/NEWS.md
index 2308cc7..a814a3b 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -203,16 +203,6 @@ Outstanding ones only. https://github.com/ruby/ruby/blob/trunk/NEWS.md#L203
           take request headers as a Hash in the second argument when the first
           argument is a URI.  [[Feature #16686]]
 
-* Tempfile
-
-    * Modified method
-
-        * `Tempfile.open { ... }` will now unlink the file at the end of the
-          block (https://github.com/ruby/tempfile/pull/3), such that once the
-          block finishes execution nothing leaks.
-
-
-
 ## Compatibility issues
 
 Excluding feature bug fixes.
diff --git a/lib/reline/line_editor.rb b/lib/reline/line_editor.rb
index 6826d58..b4d2b45 100644
--- a/lib/reline/line_editor.rb
+++ b/lib/reline/line_editor.rb
@@ -2079,14 +2079,12 @@ class Reline::LineEditor https://github.com/ruby/ruby/blob/trunk/lib/reline/line_editor.rb#L2079
   end
 
   private def vi_histedit(key)
-    Tempfile.open { |fp|
+    path = Tempfile.open { |fp|
       fp.write @line
-      path = fp.path
-      fp.close
-
-      system("#{ENV['EDITOR']} #{path}")
-      @line = File.read(path)
+      fp.path
     }
+    system("#{ENV['EDITOR']} #{path}")
+    @line = File.read(path)
     finish
   end
 
diff --git a/spec/ruby/library/tempfile/open_spec.rb b/spec/ruby/library/tempfile/open_spec.rb
index dabbe92..ef2c953 100644
--- a/spec/ruby/library/tempfile/open_spec.rb
+++ b/spec/ruby/library/tempfile/open_spec.rb
@@ -38,10 +38,8 @@ describe "Tempfile.open" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/library/tempfile/open_spec.rb#L38
   end
 
   it "is passed an array [base, suffix] as first argument" do
-    Tempfile.open(["specs", ".tt"]) { |tempfile|
-      @tempfile = tempfile
-      tempfile.path.should =~ /specs.*\.tt$/
-    }
+    Tempfile.open(["specs", ".tt"]) { |tempfile| @tempfile = tempfile }
+    @tempfile.path.should =~ /specs.*\.tt$/
   end
 
   it "passes the third argument (options) to open" do
@@ -67,7 +65,7 @@ describe "Tempfile.open when passed a block" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/library/tempfile/open_spec.rb#L65
   end
 
   after :each do
-    # Tempfile.open with block does not unlink in Ruby <= 2.7
+    # Tempfile.open with block does not unlink
     @tempfile.close! if @tempfile
   end
 
@@ -96,24 +94,4 @@ describe "Tempfile.open when passed a block" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/library/tempfile/open_spec.rb#L94
     Tempfile.open("specs") { |tempfile| @tempfile = tempfile }
     @tempfile.closed?.should be_true
   end
-
-  ruby_version_is ""..."2.8" do
-    it "does not unlink the file after the block ends" do
-      path = Tempfile.open("specs") { |tempfile|
-        @tempfile = tempfile
-        tempfile.path
-      }
-      File.should.exist?(path)
-    end
-  end
-
-  ruby_version_is "2.8" do
-    it "unlinks the file after the block ends" do
-      path = Tempfile.open("specs") { |tempfile|
-        @tempfile = tempfile
-        tempfile.path
-      }
-      File.should_not.exist?(path)
-    end
-  end
 end
diff --git a/test/openssl/test_x509store.rb b/test/openssl/test_x509store.rb
index e1898d6..1cbc73d 100644
--- a/test/openssl/test_x509store.rb
+++ b/test/openssl/test_x509store.rb
@@ -33,21 +33,20 @@ class OpenSSL::TestX509Store < OpenSSL::TestCase https://github.com/ruby/ruby/blob/trunk/test/openssl/test_x509store.rb#L33
     ]
     cert1 = issue_cert(@ca1, @rsa1024, 1, ca_exts, nil, nil)
     cert2 = issue_cert(@ca2, @rsa2048, 1, ca_exts, nil, nil)
-    Tempfile.open { |tmpfile|
-      tmpfile << cert1.to_pem << cert2.to_pem
-      tmpfile.close
-
-      store = OpenSSL::X509::Store.new
-      assert_equal false, store.verify(cert1)
-      assert_equal false, store.verify(cert2)
-      store.add_file(tmpfile.path)
-      assert_equal true, store.verify(cert1)
-      assert_equal true, store.verify(cert2)
-
-      # OpenSSL < 1.1.1 leaks an error on a duplicate certificate
-      assert_nothing_raised { store.add_file(tmpfile.path) }
-      assert_equal [], OpenSSL.errors
-    }
+    tmpfile = Tempfile.open { |f| f << cert1.to_pem << cert2.to_pem; f }
+
+    store = OpenSSL::X509::Store.new
+    assert_equal false, store.verify(cert1)
+    assert_equal false, store.verify(cert2)
+    store.add_file(tmpfile.path)
+    assert_equal true, store.verify(cert1)
+    assert_equal true, store.verify(cert2)
+
+    # OpenSSL < 1.1.1 leaks an error on a duplicate certificate
+    assert_nothing_raised { store.add_file(tmpfile.path) }
+    assert_equal [], OpenSSL.errors
+  ensure
+    tmpfile and tmpfile.close!
   end
 
   def test_verify
diff --git a/test/ruby/test_io.rb b/test/ruby/test_io.rb
index c528eea..fafb082 100644
--- a/test/ruby/test_io.rb
+++ b/test/ruby/test_io.rb
@@ -2814,7 +2814,7 @@ __END__ https://github.com/ruby/ruby/blob/trunk/test/ruby/test_io.rb#L2814
 
   def test_flush_in_finalizer1
     bug3910 = '[ruby-dev:42341]'
-    Tempfile.open("bug3910") {|t|
+    tmp = Tempfile.open("bug3910") {|t|
       path = t.path
       t.close
       fds = []
@@ -2826,6 +2826,7 @@ __END__ https://github.com/ruby/ruby/blob/trunk/test/ruby/test_io.rb#L2826
           f.print "hoge"
         }
       end
+      t
     }
   ensure
     ObjectSpace.each_object(File) {|f|
@@ -2833,6 +2834,7 @@ __END__ https://github.com/ruby/ruby/blob/trunk/test/ruby/test_io.rb#L2834
         f.close
       end
     }
+    tmp.close!
   end
 
   def test_flush_in_finalizer2
@@ -2856,6 +2858,7 @@ __END__ https://github.com/ruby/ruby/blob/trunk/test/ruby/test_io.rb#L2858
           end
         }
       end
+      t.close!
     }
   end
 
diff --git a/tool/lib/minitest/unit.rb b/tool/lib/minitest/unit.rb
index 9066782..c325134 100644
--- a/tool/lib/minitest/unit.rb
+++ b/tool/lib/minitest/unit.rb
@@ -122,11 +122,16 @@ module MiniTest https://github.com/ruby/ruby/blob/trunk/tool/lib/minitest/unit.rb#L122
       return "Expected: #{mu_pp exp}\n  Actual: #{mu_pp act}" unless
         need_to_diff
 
+      tempfile_a = nil
+      tempfile_b = nil
+
       Tempfile.open("expect") do |a|
+        tempfile_a = a
         a.puts expect
         a.flush
 
         Tempfile.open("butwas") do |b|
+          tempfile_b = b
           b.puts butwas
           b.flush
 
@@ -147,6 +152,9 @@ module MiniTest https://github.com/ruby/ruby/blob/trunk/tool/lib/minitest/unit.rb#L152
       end
 
       result
+    ensure
+      tempfile_a.close! if tempfile_a
+      tempfile_b.close! if tempfile_b
     end
 
     ##
-- 
cgit v0.10.2


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

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