summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--io.c10
-rw-r--r--test/ruby/test_io.rb10
2 files changed, 20 insertions, 0 deletions
diff --git a/io.c b/io.c
index 50395f1f40..5d68eea318 100644
--- a/io.c
+++ b/io.c
@@ -10789,6 +10789,16 @@ nogvl_copy_file_range(struct copy_stream_struct *stp)
if (nogvl_copy_stream_wait_write(stp) == -1)
return -1;
goto retry_copy_file_range;
+ case EBADF:
+ {
+ int e = errno;
+ int flags = fcntl(stp->dst_fd, F_GETFL);
+
+ if (flags != -1 && flags & O_APPEND) {
+ return 0;
+ }
+ errno = e;
+ }
}
stp->syserr = "copy_file_range";
stp->error_no = errno;
diff --git a/test/ruby/test_io.rb b/test/ruby/test_io.rb
index b5d69d9ba4..7f86b4ebaf 100644
--- a/test/ruby/test_io.rb
+++ b/test/ruby/test_io.rb
@@ -366,6 +366,16 @@ class TestIO < Test::Unit::TestCase
}
end
+ def test_copy_stream_append
+ with_srccontent("foobar") {|src, content|
+ File.open('dst', 'ab') do |dst|
+ ret = IO.copy_stream(src, dst)
+ assert_equal(content.bytesize, ret)
+ assert_equal(content, File.read("dst"))
+ end
+ }
+ end
+
def test_copy_stream_smaller
with_srccontent {|src, content|