From 8c85033a85388fc37be66bef1e1d6f0fdac0b59d Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Sun, 29 Nov 2026 00:15:03 -0600 Subject: [PATCH] Fix for Georg Meyer's cp/mv issues where read/write failure didn't get propagated up where it needs to go. --- lib/portability.c | 7 +++++-- toys/posix/cp.c | 5 ++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/portability.c b/lib/portability.c index 6b97f268..34126c8f 100644 --- a/lib/portability.c +++ b/lib/portability.c @@ -690,8 +690,11 @@ long long sendfile_len(int in, int out, long long bytes, long long *consumed) if (bytes<0 || len>sizeof(libbuf)) len = sizeof(libbuf); ww = len = read(in, libbuf, len); } - if (len<1 && errno==EAGAIN) continue; - if (len<1) break; + if (len<1) { + if (errno==EAGAIN) continue; + if (len<0) return len; + break; + } if (consumed) *consumed += len; if (ww && writeall(out, libbuf, len) != len) return -1; total += len; diff --git a/toys/posix/cp.c b/toys/posix/cp.c index 1f1816e5..3675b06b 100644 --- a/toys/posix/cp.c +++ b/toys/posix/cp.c @@ -295,10 +295,9 @@ static int cp_node(struct dirtree *try) if (S_ISLNK(try->st.st_mode)) fstat(fdin, &try->st); fdout = openat(cfd, catch, O_RDWR|O_CREAT|O_TRUNC, try->st.st_mode); if (fdout >= 0) { - xsendfile(fdin, fdout); + if (0>sendfile_len(fdin, fdout, -1, 0)) break; err = 0; } - cp_xattr(fdin, fdout, catch); } if (fdin != -1) close(fdin); @@ -306,7 +305,7 @@ static int cp_node(struct dirtree *try) } // Did we make a thing? - if (fdout != -1) { + if (!err && fdout!=-1) { // Inability to set --preserve isn't fatal, some require root access. // ownership -- 2.39.5