1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Revert the related commits about Tempfile.open change.

Start with fa21985a7a
  to d7492a0be8
This commit is contained in:
Hiroshi SHIBATA 2020-09-09 20:52:48 +09:00
parent 6997109fca
commit b194973dcd
No known key found for this signature in database
GPG key ID: F9CF13417264FAC2
6 changed files with 31 additions and 55 deletions

10
NEWS.md
View file

@ -203,16 +203,6 @@ Outstanding ones only.
take request headers as a Hash in the second argument when the first take request headers as a Hash in the second argument when the first
argument is a URI. [[Feature #16686]] 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 ## Compatibility issues
Excluding feature bug fixes. Excluding feature bug fixes.

View file

@ -2079,14 +2079,12 @@ class Reline::LineEditor
end end
private def vi_histedit(key) private def vi_histedit(key)
Tempfile.open { |fp| path = Tempfile.open { |fp|
fp.write @line fp.write @line
path = fp.path fp.path
fp.close
system("#{ENV['EDITOR']} #{path}")
@line = File.read(path)
} }
system("#{ENV['EDITOR']} #{path}")
@line = File.read(path)
finish finish
end end

View file

@ -38,10 +38,8 @@ describe "Tempfile.open" do
end end
it "is passed an array [base, suffix] as first argument" do it "is passed an array [base, suffix] as first argument" do
Tempfile.open(["specs", ".tt"]) { |tempfile| Tempfile.open(["specs", ".tt"]) { |tempfile| @tempfile = tempfile }
@tempfile = tempfile @tempfile.path.should =~ /specs.*\.tt$/
tempfile.path.should =~ /specs.*\.tt$/
}
end end
it "passes the third argument (options) to open" do it "passes the third argument (options) to open" do
@ -67,7 +65,7 @@ describe "Tempfile.open when passed a block" do
end end
after :each do 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 @tempfile.close! if @tempfile
end end
@ -96,24 +94,4 @@ describe "Tempfile.open when passed a block" do
Tempfile.open("specs") { |tempfile| @tempfile = tempfile } Tempfile.open("specs") { |tempfile| @tempfile = tempfile }
@tempfile.closed?.should be_true @tempfile.closed?.should be_true
end 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 end

View file

@ -33,21 +33,20 @@ class OpenSSL::TestX509Store < OpenSSL::TestCase
] ]
cert1 = issue_cert(@ca1, @rsa1024, 1, ca_exts, nil, nil) cert1 = issue_cert(@ca1, @rsa1024, 1, ca_exts, nil, nil)
cert2 = issue_cert(@ca2, @rsa2048, 1, ca_exts, nil, nil) cert2 = issue_cert(@ca2, @rsa2048, 1, ca_exts, nil, nil)
Tempfile.open { |tmpfile| tmpfile = Tempfile.open { |f| f << cert1.to_pem << cert2.to_pem; f }
tmpfile << cert1.to_pem << cert2.to_pem
tmpfile.close
store = OpenSSL::X509::Store.new store = OpenSSL::X509::Store.new
assert_equal false, store.verify(cert1) assert_equal false, store.verify(cert1)
assert_equal false, store.verify(cert2) assert_equal false, store.verify(cert2)
store.add_file(tmpfile.path) store.add_file(tmpfile.path)
assert_equal true, store.verify(cert1) assert_equal true, store.verify(cert1)
assert_equal true, store.verify(cert2) assert_equal true, store.verify(cert2)
# OpenSSL < 1.1.1 leaks an error on a duplicate certificate # OpenSSL < 1.1.1 leaks an error on a duplicate certificate
assert_nothing_raised { store.add_file(tmpfile.path) } assert_nothing_raised { store.add_file(tmpfile.path) }
assert_equal [], OpenSSL.errors assert_equal [], OpenSSL.errors
} ensure
tmpfile and tmpfile.close!
end end
def test_verify def test_verify

View file

@ -2814,7 +2814,7 @@ __END__
def test_flush_in_finalizer1 def test_flush_in_finalizer1
bug3910 = '[ruby-dev:42341]' bug3910 = '[ruby-dev:42341]'
Tempfile.open("bug3910") {|t| tmp = Tempfile.open("bug3910") {|t|
path = t.path path = t.path
t.close t.close
fds = [] fds = []
@ -2826,6 +2826,7 @@ __END__
f.print "hoge" f.print "hoge"
} }
end end
t
} }
ensure ensure
ObjectSpace.each_object(File) {|f| ObjectSpace.each_object(File) {|f|
@ -2833,6 +2834,7 @@ __END__
f.close f.close
end end
} }
tmp.close!
end end
def test_flush_in_finalizer2 def test_flush_in_finalizer2
@ -2856,6 +2858,7 @@ __END__
end end
} }
end end
t.close!
} }
end end

View file

@ -122,11 +122,16 @@ module MiniTest
return "Expected: #{mu_pp exp}\n Actual: #{mu_pp act}" unless return "Expected: #{mu_pp exp}\n Actual: #{mu_pp act}" unless
need_to_diff need_to_diff
tempfile_a = nil
tempfile_b = nil
Tempfile.open("expect") do |a| Tempfile.open("expect") do |a|
tempfile_a = a
a.puts expect a.puts expect
a.flush a.flush
Tempfile.open("butwas") do |b| Tempfile.open("butwas") do |b|
tempfile_b = b
b.puts butwas b.puts butwas
b.flush b.flush
@ -147,6 +152,9 @@ module MiniTest
end end
result result
ensure
tempfile_a.close! if tempfile_a
tempfile_b.close! if tempfile_b
end end
## ##