Fix bug of Tempfile#size if nothing is written [Bug #13198]
* lib/tempfile.rb (Tempfile#size): Fix its behavior when nothing is written. Tempfile#size should return 0 in this case. The patch is from nobu <nobu@ruby-lang.org>. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57972 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
3c96f9c76a
commit
279d31f11d
@ -227,7 +227,7 @@ class Tempfile < DelegateClass(File)
|
|||||||
if !@tmpfile.closed?
|
if !@tmpfile.closed?
|
||||||
@tmpfile.size # File#size calls rb_io_flush_raw()
|
@tmpfile.size # File#size calls rb_io_flush_raw()
|
||||||
else
|
else
|
||||||
File.size?(@tmpfile.path)
|
File.size(@tmpfile.path)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
alias length size
|
alias length size
|
||||||
|
@ -247,6 +247,13 @@ puts Tempfile.new('foo').path
|
|||||||
assert_equal 5, t.size
|
assert_equal 5, t.size
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_size_on_empty_file
|
||||||
|
t = tempfile("foo")
|
||||||
|
t.write("")
|
||||||
|
t.close
|
||||||
|
assert_equal 0, t.size
|
||||||
|
end
|
||||||
|
|
||||||
def test_concurrency
|
def test_concurrency
|
||||||
threads = []
|
threads = []
|
||||||
tempfiles = []
|
tempfiles = []
|
||||||
|
Loading…
x
Reference in New Issue
Block a user