From b555e659c4974acc423083b71b1bd5ec6a926046 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Sun, 5 Dec 2021 18:08:55 +0900 Subject: Do not use `fcopyfile` if appending to non-empty file [Bug #18388] `fcopyfile` appends `src` to `to` and then truncates `to` to it's original size. --- test/ruby/test_io.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'test') diff --git a/test/ruby/test_io.rb b/test/ruby/test_io.rb index 96e572b98d..71a8911fbd 100644 --- a/test/ruby/test_io.rb +++ b/test/ruby/test_io.rb @@ -476,6 +476,18 @@ class TestIO < Test::Unit::TestCase } end + def test_copy_stream_append_to_nonempty + with_srccontent("foobar") {|src, content| + preface = 'preface' + File.write('dst', preface) + File.open('dst', 'ab') do |dst| + ret = IO.copy_stream(src, dst) + assert_equal(content.bytesize, ret) + assert_equal(preface + content, File.read("dst")) + end + } + end + def test_copy_stream_smaller with_srccontent {|src, content| -- cgit v1.2.3