diff options
author | glass <glass@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-03-14 12:53:32 +0000 |
---|---|---|
committer | glass <glass@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-03-14 12:53:32 +0000 |
commit | 279d31f11de8bd0727626a6c32ccd72e1da76508 (patch) | |
tree | 9d71ba2ecbcba860da5f56f875e6060b6f04ebec | |
parent | 3c96f9c76a82907d0201cd3af5f5f2d1c2c48850 (diff) | |
download | ruby-279d31f11de8bd0727626a6c32ccd72e1da76508.tar.gz |
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
-rw-r--r-- | lib/tempfile.rb | 2 | ||||
-rw-r--r-- | test/test_tempfile.rb | 7 |
2 files changed, 8 insertions, 1 deletions
diff --git a/lib/tempfile.rb b/lib/tempfile.rb index d068dd603c..b36c6638b6 100644 --- a/lib/tempfile.rb +++ b/lib/tempfile.rb @@ -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 diff --git a/test/test_tempfile.rb b/test/test_tempfile.rb index 7f7f75c7db..a2b272747e 100644 --- a/test/test_tempfile.rb +++ b/test/test_tempfile.rb @@ -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 = [] |