Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -781,6 +781,11 @@ static char *get_local_name(struct file_list *flist, char *dest_path)
exit_cleanup(RERR_FILESELECT);
}

if (dry_run) {
/* Indicate that dest dir doesn't really exist. */
dry_run++;
}

/* If we need a destination directory because the transfer is not
* of a single non-directory or the user has requested one via a
* destination path ending in a slash, create one and use mode 1. */
Expand All @@ -807,11 +812,6 @@ static char *get_local_name(struct file_list *flist, char *dest_path)
if (INFO_GTE(NAME, 1) || stdout_format_has_i)
rprintf(FINFO, "created directory %s\n", dest_path);

if (dry_run) {
/* Indicate that dest dir doesn't really exist. */
dry_run++;
}

if (!change_dir(dest_path, dry_run > 1 ? CD_SKIP_CHDIR : CD_NORMAL)) {
rsyserr(FERROR, errno, "change_dir#2 %s failed",
full_fname(dest_path));
Expand All @@ -832,7 +832,7 @@ static char *get_local_name(struct file_list *flist, char *dest_path)
dest_path = "/";

*cp = '\0';
if (!change_dir(dest_path, CD_NORMAL)) {
if (!change_dir(dest_path, dry_run > 1 ? CD_SKIP_CHDIR : CD_NORMAL)) {
rsyserr(FERROR, errno, "change_dir#3 %s failed",
full_fname(dest_path));
exit_cleanup(RERR_FILESELECT);
Expand Down
26 changes: 26 additions & 0 deletions testsuite/file-to-file-mkpath-dry-run_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env python3
# Copying file-to-file with --mkpath and --dry-run had different behavior than to-directory.
# The --dry-run would fail while the actual command would succeed.

import os

from rsyncfns import (
TMPDIR, rsync_argv, assert_same, assert_exists
)
import subprocess

os.chdir(TMPDIR)

os.mkdir("from")
with open("from/source_file", "w") as f:
f.write("payload\n")

# Check if dry-run works
dry_run_result = subprocess.run(rsync_argv('--dry-run', '--recursive', '--mkpath', '--links', '--perms', '--times', '--omit-dir-times', 'from/source_file', 'dest_dir/dest_file'), capture_output=True, text=True)
actual_run = subprocess.run(rsync_argv('--recursive', '--mkpath', '--links', '--perms', '--times', '--omit-dir-times', 'from/source_file', 'dest_dir/dest_file'), capture_output=True, text=True)
(TMPDIR / 'dry_run.out').write_text(dry_run_result.stdout + dry_run_result.stderr)
(TMPDIR / 'actual_run.out').write_text(actual_run.stdout + actual_run.stderr)
print(dry_run_result.stdout)
print(actual_run.stdout)
assert_same(TMPDIR / 'dry_run.out', TMPDIR / 'actual_run.out', label='dry-run vs actual run output')
assert_exists("dest_dir/dest_file")
Loading