From f9a7c256ca6a959fb77190f821df17c7f2d2c1d5 Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Mon, 3 Apr 2023 06:00:16 +0200 Subject: [PATCH] package/libite: backport rsync + copyfile fixes from upcoming v2.5.3 Signed-off-by: Joachim Wiberg --- ...urn-value-when-copying-a-single-file.patch | 30 ++++++++ ...for-missing-dst-when-dst-is-a-direct.patch | 29 ++++++++ ...opying-empty-files-to-non-existing-d.patch | 68 +++++++++++++++++++ 3 files changed, 127 insertions(+) create mode 100644 patches/libite/2.5.2/0001-rsync-fix-return-value-when-copying-a-single-file.patch create mode 100644 patches/libite/2.5.2/0002-rsync-fix-check-for-missing-dst-when-dst-is-a-direct.patch create mode 100644 patches/libite/2.5.2/0003-copyfile-allow-copying-empty-files-to-non-existing-d.patch diff --git a/patches/libite/2.5.2/0001-rsync-fix-return-value-when-copying-a-single-file.patch b/patches/libite/2.5.2/0001-rsync-fix-return-value-when-copying-a-single-file.patch new file mode 100644 index 00000000..7e06dcd6 --- /dev/null +++ b/patches/libite/2.5.2/0001-rsync-fix-return-value-when-copying-a-single-file.patch @@ -0,0 +1,30 @@ +From 90fdcdeb39e35193fe4e8f5d5277cf9ca28d5055 Mon Sep 17 00:00:00 2001 +From: Joachim Wiberg +Date: Sun, 2 Apr 2023 22:16:50 +0200 +Subject: [PATCH 1/4] rsync: fix return value when copying a single file +Organization: Addiva Elektronik + +Signed-off-by: Joachim Wiberg +--- + src/rsync.c | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/src/rsync.c b/src/rsync.c +index 392e1d2..92b8d63 100644 +--- a/src/rsync.c ++++ b/src/rsync.c +@@ -85,9 +85,9 @@ int rsync(char *src, char *dst, int opt, int (*filter)(const char *file)) + return 1; + + if (copy(src, dst, keep_mtim)) +- result++; ++ return 1; + +- return errno; ++ return 0; + } + + /* Copy dir as well? */ +-- +2.34.1 + diff --git a/patches/libite/2.5.2/0002-rsync-fix-check-for-missing-dst-when-dst-is-a-direct.patch b/patches/libite/2.5.2/0002-rsync-fix-check-for-missing-dst-when-dst-is-a-direct.patch new file mode 100644 index 00000000..e9916cf7 --- /dev/null +++ b/patches/libite/2.5.2/0002-rsync-fix-check-for-missing-dst-when-dst-is-a-direct.patch @@ -0,0 +1,29 @@ +From d61b847e557e5162163dffd1abd4b5d9bedc6d7a Mon Sep 17 00:00:00 2001 +From: Joachim Wiberg +Date: Sun, 2 Apr 2023 22:17:09 +0200 +Subject: [PATCH 2/4] rsync: fix check for missing dst when dst is a directory +Organization: Addiva Elektronik + +Signed-off-by: Joachim Wiberg +--- + src/rsync.c | 4 +++- + 1 file changed, 3 insertions(+), 1 deletion(-) + +diff --git a/src/rsync.c b/src/rsync.c +index 92b8d63..695fac3 100644 +--- a/src/rsync.c ++++ b/src/rsync.c +@@ -77,7 +77,9 @@ int rsync(char *src, char *dst, int opt, int (*filter)(const char *file)) + char **files; /* Array of file names. */ + struct stat st; + +- if (!fisdir(dst)) ++ errno = 0; ++ ++ if (stat(dst, &st) && fisslashdir(dst)) + makedir(dst, 0755); + + if (!fisdir(src)) { +-- +2.34.1 + diff --git a/patches/libite/2.5.2/0003-copyfile-allow-copying-empty-files-to-non-existing-d.patch b/patches/libite/2.5.2/0003-copyfile-allow-copying-empty-files-to-non-existing-d.patch new file mode 100644 index 00000000..b7491c0a --- /dev/null +++ b/patches/libite/2.5.2/0003-copyfile-allow-copying-empty-files-to-non-existing-d.patch @@ -0,0 +1,68 @@ +From 4e9b5c13c16f7e7261a15143d9418385274a008e Mon Sep 17 00:00:00 2001 +From: Joachim Wiberg +Date: Sun, 2 Apr 2023 22:17:47 +0200 +Subject: [PATCH 3/4] copyfile: allow copying empty files to non-existing + destination dirs +Organization: Addiva Elektronik + +Signed-off-by: Joachim Wiberg +--- + src/copyfile.c | 14 ++++++++++++-- + 1 file changed, 12 insertions(+), 2 deletions(-) + +diff --git a/src/copyfile.c b/src/copyfile.c +index afbbda9..af34012 100644 +--- a/src/copyfile.c ++++ b/src/copyfile.c +@@ -38,6 +38,7 @@ static int adjust_target(const char *src, char **dst) + { + int isdir = 0; + ++ retry: + if (fisdir(*dst)) { + int slash = 0; + char *tmp, *ptr = strrchr(src, '/'); +@@ -58,6 +59,13 @@ static int adjust_target(const char *src, char **dst) + + sprintf(tmp, "%s%s%s", *dst, slash ? "" : "/", ptr); + *dst = tmp; ++ } else { ++ struct stat st; ++ ++ if (stat(*dst, &st) && fisslashdir(*dst)) { ++ makedir(*dst, 0755); ++ goto retry; ++ } + } + + return isdir; +@@ -67,7 +75,7 @@ static int adjust_target(const char *src, char **dst) + * breaks loop on error and EOF */ + static ssize_t do_copy(int in, int out, size_t num, char *buffer, size_t len) + { +- ssize_t ret = 0, size = 0; ++ ssize_t ret = 0, size = -1; + + do { + size_t count = num > len ? len : num; +@@ -76,6 +84,8 @@ static ssize_t do_copy(int in, int out, size_t num, char *buffer, size_t len) + if (ret <= 0) { + if (ret == -1 && EINTR == errno) + continue; ++ if (ret == 0 && size == -1) ++ size = 0; + break; + } + +@@ -194,7 +204,7 @@ ssize_t copyfile(const char *src, const char *dst, int len, int opt) + } + + size = do_copy(in, out, num, buffer, BUFSIZ); +- if (!size && errno) ++ if (size < 0) + saved_errno = errno; + else if (keep_mtim) + set_mtime(in, out); +-- +2.34.1 +