| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
import os |
| 13 |
import subprocess |
| 14 |
|
| 15 |
from rsyncfns import FROMDIR, RSYNC, TMPDIR, TODIR, makepath, rsync_argv, test_fail |
| 16 |
|
| 17 |
|
| 18 |
makepath(FROMDIR / 'subdir', TODIR) |
| 19 |
(FROMDIR / 'subdir' / 'file').write_text("data\n") |
| 20 |
(TODIR / 'other').write_text("data\n") |
| 21 |
|
| 22 |
|
| 23 |
def run_capture(*args): |
| 24 |
proc = subprocess.run(rsync_argv(*args), capture_output=True, text=True) |
| 25 |
print(proc.stdout, end='') |
| 26 |
print(proc.stderr, end='') |
| 27 |
return proc |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
out_path = TMPDIR / 'out1' |
| 32 |
proc = run_capture('-n', '-r', '--ignore-non-existing', '-vv', |
| 33 |
f'{FROMDIR}/', f'{TODIR}/') |
| 34 |
if proc.returncode != 0: |
| 35 |
test_fail(f"test 1 failed: dry-run errored (rc={proc.returncode})") |
| 36 |
out_path.write_text(proc.stdout) |
| 37 |
for line in proc.stdout.splitlines(): |
| 38 |
if 'not creating new' in line and 'subdir/file' in line: |
| 39 |
test_fail("test 1 failed: dry-run announced creating subdir/file") |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
if 'protocol=29' not in RSYNC: |
| 44 |
proc = run_capture('-n', '-r', '-R', '--no-implied-dirs', '-y', |
| 45 |
f'{FROMDIR}/./subdir/file', f'{TODIR}/') |
| 46 |
if proc.returncode != 0: |
| 47 |
test_fail("test 2 failed: --no-implied-dirs dry-run errored") |
| 48 |
else: |
| 49 |
print("Skipped test 2 for protocol 29.") |
| 50 |
|
| 51 |
|
| 52 |
proc = run_capture('-n', '-r', '--delete-after', '-i', |
| 53 |
f'{FROMDIR}/', f'{TODIR}/') |
| 54 |
saw_delete = any(line.lstrip().startswith('*deleting') |
| 55 |
and 'other' in line |
| 56 |
for line in proc.stdout.splitlines()) |
| 57 |
if not saw_delete: |
| 58 |
test_fail("test 3 failed: no '*deleting other' line in dry-run output") |