Handle a --mkpath failure
authorWayne Davison <wayne@opencoder.net>
Tue, 8 Sep 2020 17:53:29 +0000 (10:53 -0700)
committerWayne Davison <wayne@opencoder.net>
Tue, 8 Sep 2020 17:58:47 +0000 (10:58 -0700)
Fixes bug #96 where --mkpath makes rsync complain when a dest path
exists but the path contains an alt-dest name for the single file.

main.c
testsuite/mkpath.test

diff --git a/main.c b/main.c
index 46b97b58df23235dad543195229d13ef5a3b80ef..66e5f780ac208d791e61f06c92694264299becf8 100644 (file)
--- a/main.c
+++ b/main.c
@@ -721,18 +721,21 @@ static char *get_local_name(struct file_list *flist, char *dest_path)
        trailing_slash = cp && !cp[1];
 
        if (mkpath_dest_arg && statret < 0 && (cp || file_total > 1)) {
+               int save_errno = errno;
                int ret = make_path(dest_path, file_total > 1 && !trailing_slash ? 0 : MKP_DROP_NAME);
                if (ret < 0)
                        goto mkdir_error;
-               if (INFO_GTE(NAME, 1)) {
+               if (ret && INFO_GTE(NAME, 1)) {
                        if (file_total == 1 || trailing_slash)
                                *cp = '\0';
                        rprintf(FINFO, "created %d director%s for %s\n", ret, ret == 1 ? "y" : "ies", dest_path);
                        if (file_total == 1 || trailing_slash)
                                *cp = '/';
                }
-               if (file_total > 1 || trailing_slash)
+               if (ret)
                        statret = do_stat(dest_path, &st);
+               else
+                       errno = save_errno;
        }
 
        if (statret == 0) {
index 6efb2105ecc3dd13a205b4ecb4864f474374259a..8046345418f8f00c78cb100da74fa1319b51e992 100755 (executable)
@@ -25,6 +25,10 @@ rm $deep_dir/text
 mkdir $deep_dir/new
 $RSYNC -aiv --mkpath from/text $deep_dir/new
 test -f $deep_dir/new/text || test_fail "'text' file not found in $deep_dir/new dir"
+
+# ... and an existing path when an alternate dest filename is specified
+$RSYNC -aiv --mkpath from/text $deep_dir/new/text2
+test -f $deep_dir/new/text2 || test_fail "'text2' file not found in $deep_dir/new dir"
 rm -rf to/foo
 
 # Try the tests again with multiple source args