зеркало из https://github.com/github/ruby.git
Revert the related commits about `Tempfile.open` change.
Start withfa21985a7a
tod7492a0be8
This commit is contained in:
Родитель
6997109fca
Коммит
b194973dcd
10
NEWS.md
10
NEWS.md
|
@ -203,16 +203,6 @@ Outstanding ones only.
|
|||
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.
|
||||
|
|
|
@ -2079,14 +2079,12 @@ class Reline::LineEditor
|
|||
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
|
||||
|
||||
|
|
|
@ -38,10 +38,8 @@ describe "Tempfile.open" do
|
|||
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
|
|||
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
|
|||
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
|
||||
|
|
|
@ -33,21 +33,20 @@ class OpenSSL::TestX509Store < OpenSSL::TestCase
|
|||
]
|
||||
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
|
||||
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)
|
||||
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
|
||||
}
|
||||
# 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
|
||||
|
|
|
@ -2814,7 +2814,7 @@ __END__
|
|||
|
||||
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__
|
|||
f.print "hoge"
|
||||
}
|
||||
end
|
||||
t
|
||||
}
|
||||
ensure
|
||||
ObjectSpace.each_object(File) {|f|
|
||||
|
@ -2833,6 +2834,7 @@ __END__
|
|||
f.close
|
||||
end
|
||||
}
|
||||
tmp.close!
|
||||
end
|
||||
|
||||
def test_flush_in_finalizer2
|
||||
|
@ -2856,6 +2858,7 @@ __END__
|
|||
end
|
||||
}
|
||||
end
|
||||
t.close!
|
||||
}
|
||||
end
|
||||
|
||||
|
|
|
@ -122,11 +122,16 @@ module MiniTest
|
|||
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
|
|||
end
|
||||
|
||||
result
|
||||
ensure
|
||||
tempfile_a.close! if tempfile_a
|
||||
tempfile_b.close! if tempfile_b
|
||||
end
|
||||
|
||||
##
|
||||
|
|
Загрузка…
Ссылка в новой задаче