Skip to content

Commit b194973

Browse files
committed
Revert the related commits about Tempfile.open change.
Start with fa21985 to d7492a0
1 parent 6997109 commit b194973

File tree

6 files changed

+33
-57
lines changed

6 files changed

+33
-57
lines changed

NEWS.md

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -203,16 +203,6 @@ Outstanding ones only.
203203
take request headers as a Hash in the second argument when the first
204204
argument is a URI. [[Feature #16686]]
205205

206-
* Tempfile
207-
208-
* Modified method
209-
210-
* `Tempfile.open { ... }` will now unlink the file at the end of the
211-
block (https://github.com/ruby/tempfile/pull/3), such that once the
212-
block finishes execution nothing leaks.
213-
214-
215-
216206
## Compatibility issues
217207

218208
Excluding feature bug fixes.

lib/reline/line_editor.rb

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2079,14 +2079,12 @@ def finish
20792079
end
20802080

20812081
private def vi_histedit(key)
2082-
Tempfile.open { |fp|
2082+
path = Tempfile.open { |fp|
20832083
fp.write @line
2084-
path = fp.path
2085-
fp.close
2086-
2087-
system("#{ENV['EDITOR']} #{path}")
2088-
@line = File.read(path)
2084+
fp.path
20892085
}
2086+
system("#{ENV['EDITOR']} #{path}")
2087+
@line = File.read(path)
20902088
finish
20912089
end
20922090

spec/ruby/library/tempfile/open_spec.rb

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,8 @@
3838
end
3939

4040
it "is passed an array [base, suffix] as first argument" do
41-
Tempfile.open(["specs", ".tt"]) { |tempfile|
42-
@tempfile = tempfile
43-
tempfile.path.should =~ /specs.*\.tt$/
44-
}
41+
Tempfile.open(["specs", ".tt"]) { |tempfile| @tempfile = tempfile }
42+
@tempfile.path.should =~ /specs.*\.tt$/
4543
end
4644

4745
it "passes the third argument (options) to open" do
@@ -67,7 +65,7 @@
6765
end
6866

6967
after :each do
70-
# Tempfile.open with block does not unlink in Ruby <= 2.7
68+
# Tempfile.open with block does not unlink
7169
@tempfile.close! if @tempfile
7270
end
7371

@@ -96,24 +94,4 @@
9694
Tempfile.open("specs") { |tempfile| @tempfile = tempfile }
9795
@tempfile.closed?.should be_true
9896
end
99-
100-
ruby_version_is ""..."2.8" do
101-
it "does not unlink the file after the block ends" do
102-
path = Tempfile.open("specs") { |tempfile|
103-
@tempfile = tempfile
104-
tempfile.path
105-
}
106-
File.should.exist?(path)
107-
end
108-
end
109-
110-
ruby_version_is "2.8" do
111-
it "unlinks the file after the block ends" do
112-
path = Tempfile.open("specs") { |tempfile|
113-
@tempfile = tempfile
114-
tempfile.path
115-
}
116-
File.should_not.exist?(path)
117-
end
118-
end
11997
end

test/openssl/test_x509store.rb

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,20 @@ def test_add_file
3333
]
3434
cert1 = issue_cert(@ca1, @rsa1024, 1, ca_exts, nil, nil)
3535
cert2 = issue_cert(@ca2, @rsa2048, 1, ca_exts, nil, nil)
36-
Tempfile.open { |tmpfile|
37-
tmpfile << cert1.to_pem << cert2.to_pem
38-
tmpfile.close
39-
40-
store = OpenSSL::X509::Store.new
41-
assert_equal false, store.verify(cert1)
42-
assert_equal false, store.verify(cert2)
43-
store.add_file(tmpfile.path)
44-
assert_equal true, store.verify(cert1)
45-
assert_equal true, store.verify(cert2)
46-
47-
# OpenSSL < 1.1.1 leaks an error on a duplicate certificate
48-
assert_nothing_raised { store.add_file(tmpfile.path) }
49-
assert_equal [], OpenSSL.errors
50-
}
36+
tmpfile = Tempfile.open { |f| f << cert1.to_pem << cert2.to_pem; f }
37+
38+
store = OpenSSL::X509::Store.new
39+
assert_equal false, store.verify(cert1)
40+
assert_equal false, store.verify(cert2)
41+
store.add_file(tmpfile.path)
42+
assert_equal true, store.verify(cert1)
43+
assert_equal true, store.verify(cert2)
44+
45+
# OpenSSL < 1.1.1 leaks an error on a duplicate certificate
46+
assert_nothing_raised { store.add_file(tmpfile.path) }
47+
assert_equal [], OpenSSL.errors
48+
ensure
49+
tmpfile and tmpfile.close!
5150
end
5251

5352
def test_verify

test/ruby/test_io.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2814,7 +2814,7 @@ def test_threaded_flush
28142814

28152815
def test_flush_in_finalizer1
28162816
bug3910 = '[ruby-dev:42341]'
2817-
Tempfile.open("bug3910") {|t|
2817+
tmp = Tempfile.open("bug3910") {|t|
28182818
path = t.path
28192819
t.close
28202820
fds = []
@@ -2826,13 +2826,15 @@ def test_flush_in_finalizer1
28262826
f.print "hoge"
28272827
}
28282828
end
2829+
t
28292830
}
28302831
ensure
28312832
ObjectSpace.each_object(File) {|f|
28322833
if f.instance_variables.include?(:@test_flush_in_finalizer1)
28332834
f.close
28342835
end
28352836
}
2837+
tmp.close!
28362838
end
28372839

28382840
def test_flush_in_finalizer2
@@ -2856,6 +2858,7 @@ def test_flush_in_finalizer2
28562858
end
28572859
}
28582860
end
2861+
t.close!
28592862
}
28602863
end
28612864

tool/lib/minitest/unit.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,16 @@ def diff exp, act
122122
return "Expected: #{mu_pp exp}\n Actual: #{mu_pp act}" unless
123123
need_to_diff
124124

125+
tempfile_a = nil
126+
tempfile_b = nil
127+
125128
Tempfile.open("expect") do |a|
129+
tempfile_a = a
126130
a.puts expect
127131
a.flush
128132

129133
Tempfile.open("butwas") do |b|
134+
tempfile_b = b
130135
b.puts butwas
131136
b.flush
132137

@@ -147,6 +152,9 @@ def diff exp, act
147152
end
148153

149154
result
155+
ensure
156+
tempfile_a.close! if tempfile_a
157+
tempfile_b.close! if tempfile_b
150158
end
151159

152160
##

0 commit comments

Comments
 (0)