| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
import os |
| 10 |
import subprocess |
| 11 |
import time |
| 12 |
|
| 13 |
from rsyncfns import ( |
| 14 |
CHKDIR, FROMDIR, OUTFILE, TMPDIR, TODIR, |
| 15 |
checkit, hands_setup, makepath, rsync_argv, |
| 16 |
run_rsync, test_fail, |
| 17 |
) |
| 18 |
|
| 19 |
|
| 20 |
deepstr = 'down/3/deep' |
| 21 |
deepdir = FROMDIR / deepstr |
| 22 |
extradir = TMPDIR / 'extra' |
| 23 |
|
| 24 |
makepath(deepdir, extradir / deepstr, CHKDIR) |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
import rsyncfns |
| 30 |
real_fromdir = rsyncfns.FROMDIR |
| 31 |
try: |
| 32 |
rsyncfns.FROMDIR = deepdir |
| 33 |
hands_setup() |
| 34 |
finally: |
| 35 |
rsyncfns.FROMDIR = real_fromdir |
| 36 |
|
| 37 |
extrafile = extradir / deepstr / 'extra.added.value' |
| 38 |
extrafile.write_text("wowza\n") |
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
extrafile_for_rsync = f"{extradir}/./{deepstr}/extra.added.value" |
| 44 |
|
| 45 |
|
| 46 |
run_rsync('-av', '--existing', '--include=*/', '--exclude=*', |
| 47 |
f'{FROMDIR}/', f'{extradir}/') |
| 48 |
|
| 49 |
os.chdir(FROMDIR) |
| 50 |
|
| 51 |
|
| 52 |
run_rsync('-ai', '--include=/down/', '--exclude=/*', |
| 53 |
f'{FROMDIR}/', f'{CHKDIR}/') |
| 54 |
|
| 55 |
time.sleep(1) |
| 56 |
|
| 57 |
print("Test basic relative:") |
| 58 |
checkit(['-avR', f'./{deepstr}', str(TODIR)], CHKDIR, TODIR) |
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
os.link(deepdir / 'filelist', deepdir / 'dir' / 'filelist') |
| 63 |
os.link(CHKDIR / deepstr / 'filelist', CHKDIR / deepstr / 'dir' / 'filelist') |
| 64 |
|
| 65 |
src_t = (deepdir / 'dir').stat().st_mtime |
| 66 |
os.utime(deepdir / 'dir', (src_t, src_t)) |
| 67 |
os.utime(CHKDIR / deepstr / 'dir', (src_t, src_t)) |
| 68 |
|
| 69 |
print("Test hard links:") |
| 70 |
checkit(['-avHR', f'./{deepstr}/', str(TODIR)], CHKDIR, TODIR) |
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
import shutil |
| 75 |
shutil.copy(deepdir / 'text', TODIR / deepstr / 'ThisShouldGo') |
| 76 |
shutil.copy(deepdir / 'text', TODIR / deepstr / 'dir' / 'ThisShouldGoToo') |
| 77 |
|
| 78 |
print("Test deletion:") |
| 79 |
checkit(['-avHR', '--del', f'./{deepstr}/', str(TODIR)], CHKDIR, TODIR) |
| 80 |
|
| 81 |
print("Test non-deletion:") |
| 82 |
|
| 83 |
|
| 84 |
proc = subprocess.run( |
| 85 |
rsync_argv('-aiHR', '--del', f'./{deepstr}/', str(TODIR)), |
| 86 |
capture_output=True, text=True, |
| 87 |
) |
| 88 |
OUTFILE.write_text(proc.stdout) |
| 89 |
print(proc.stdout, end='') |
| 90 |
if proc.returncode != 0: |
| 91 |
test_fail(f"non-deletion run exited {proc.returncode}") |
| 92 |
if 'deleting ' in proc.stdout: |
| 93 |
test_fail("Erroneous deletions occurred!") |
| 94 |
|
| 95 |
|
| 96 |
run_rsync('-ai', str(extradir / 'down'), f'{CHKDIR}/') |
| 97 |
|
| 98 |
print("Test merge:") |
| 99 |
checkit(['-aiR', deepstr, extrafile_for_rsync, str(TODIR)], CHKDIR, TODIR) |
| 100 |
|
| 101 |
print("Test merge with --del:") |
| 102 |
proc = subprocess.run( |
| 103 |
rsync_argv('-aiR', '--del', deepstr, extrafile_for_rsync, str(TODIR)), |
| 104 |
capture_output=True, text=True, |
| 105 |
) |
| 106 |
OUTFILE.write_text(proc.stdout) |
| 107 |
print(proc.stdout, end='') |
| 108 |
if proc.returncode != 0: |
| 109 |
test_fail(f"merge --del run exited {proc.returncode}") |
| 110 |
if 'deleting ' in proc.stdout: |
| 111 |
test_fail("Erroneous deletions occurred! (2)") |