commit:     fe2e58325ffd1d4424564998f64bed4cb4ab8ffa
Author:     Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Sat Dec 11 20:40:04 2021 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Sun Dec 12 01:14:13 2021 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=fe2e5832

file_copy: handle zero bytes copied by copy_file_range (bug 828844)

When copy_file_range copied zero bytes, fall back to sendfile,
so that we don't call copy_file_range in an infinite loop.

Bug: https://bugs.gentoo.org/828844
Tested-by: John Helmert III <ajak <AT> gentoo.org>
Signed-off-by: Zac Medico <zmedico <AT> gentoo.org>

 src/portage_util_file_copy_reflink_linux.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/src/portage_util_file_copy_reflink_linux.c 
b/src/portage_util_file_copy_reflink_linux.c
index c6affe57a..b00b57952 100644
--- a/src/portage_util_file_copy_reflink_linux.c
+++ b/src/portage_util_file_copy_reflink_linux.c
@@ -261,13 +261,14 @@ _reflink_linux_file_copy(PyObject *self, PyObject *args)
                                         &offset_out,
                                         len);
 
-                if (copyfunc_ret < 0) {
+                if (copyfunc_ret <= 0) {
                     error = errno;
-                    if ((errno == EXDEV || errno == ENOSYS || errno == 
EOPNOTSUPP) &&
+                    if ((errno == EXDEV || errno == ENOSYS || errno == 
EOPNOTSUPP || copyfunc_ret == 0) &&
                         copyfunc == cfr_wrapper) {
                         /* Use sendfile instead of copy_file_range for
                          * cross-device copies, or when the copy_file_range
-                         * syscall is not available (less than Linux 4.5).
+                         * syscall is not available (less than Linux 4.5),
+                         * or when copy_file_range copies zero bytes.
                          */
                         error = 0;
                         copyfunc = sf_wrapper;

Reply via email to