From: Wayne Davison Date: Tue, 8 Sep 2020 17:53:29 +0000 (-0700) Subject: Handle a --mkpath failure X-Git-Tag: v3.2.4pre1~133 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=2613c9d98aaef363e4cb1b8683f51af503264fde;p=thirdparty%2Frsync.git Handle a --mkpath failure 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. --- diff --git a/main.c b/main.c index 46b97b58..66e5f780 100644 --- 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) { diff --git a/testsuite/mkpath.test b/testsuite/mkpath.test index 6efb2105..80463454 100755 --- a/testsuite/mkpath.test +++ b/testsuite/mkpath.test @@ -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