mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
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
2 changed files with 8 additions and 1 deletions
|
@ -227,7 +227,7 @@ class Tempfile < DelegateClass(File)
|
|||
if !@tmpfile.closed?
|
||||
@tmpfile.size # File#size calls rb_io_flush_raw()
|
||||
else
|
||||
File.size?(@tmpfile.path)
|
||||
File.size(@tmpfile.path)
|
||||
end
|
||||
end
|
||||
alias length size
|
||||
|
|
|
@ -247,6 +247,13 @@ puts Tempfile.new('foo').path
|
|||
assert_equal 5, t.size
|
||||
end
|
||||
|
||||
def test_size_on_empty_file
|
||||
t = tempfile("foo")
|
||||
t.write("")
|
||||
t.close
|
||||
assert_equal 0, t.size
|
||||
end
|
||||
|
||||
def test_concurrency
|
||||
threads = []
|
||||
tempfiles = []
|
||||
|
|
Loading…
Add table
Reference in a new issue