| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
import os |
| 9 |
import subprocess |
| 10 |
|
| 11 |
from rsyncfns import ( |
| 12 |
FROMDIR, TODIR, |
| 13 |
rsync_argv, rsync_ls_lR, test_fail, |
| 14 |
) |
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
FROMDIR.mkdir(parents=True, exist_ok=True) |
| 19 |
name1 = FROMDIR / 'name1' |
| 20 |
name2 = FROMDIR / 'name2' |
| 21 |
name1.write_text("This is the file\n") |
| 22 |
try: |
| 23 |
os.symlink(str(name1), name2) |
| 24 |
except OSError as e: |
| 25 |
test_fail(f"can't create symlink: {e}") |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
sources = [f'{FROMDIR}/'] * 10 |
| 31 |
proc = subprocess.run( |
| 32 |
rsync_argv('-avv', *sources, f'{TODIR}/'), |
| 33 |
capture_output=True, text=True, |
| 34 |
) |
| 35 |
print(proc.stdout) |
| 36 |
if proc.returncode != 0: |
| 37 |
test_fail(f"rsync exited {proc.returncode}\n{proc.stderr}") |
| 38 |
|
| 39 |
name1_count = sum(1 for ln in proc.stdout.splitlines() if ln == 'name1') |
| 40 |
if name1_count != 1: |
| 41 |
test_fail(f"name1 was not copied exactly once (got {name1_count})") |
| 42 |
|
| 43 |
name2_count = sum(1 for ln in proc.stdout.splitlines() if ln.startswith('name2 -> ')) |
| 44 |
if name2_count != 1: |
| 45 |
test_fail(f"name2 was not copied exactly once (got {name2_count})") |
| 46 |
|
| 47 |
|
| 48 |
if rsync_ls_lR(FROMDIR) != rsync_ls_lR(TODIR): |
| 49 |
test_fail("destination listing differs from source after deduplication") |