| 1 |
|
| 2 |
"""Property-level coverage of --delay-updates at depth. |
| 3 |
|
| 4 |
--delay-updates writes each updated file into a per-directory staging dir |
| 5 |
(.~tmp~) during the transfer and only renames them into place at the very end, |
| 6 |
so an interrupted run never leaves a half-written file visible. The staging dir |
| 7 |
sits inside each destination directory, so the staging write and the |
| 8 |
end-of-run rename are parent-directory operations the resolver restructure |
| 9 |
rewrites; the ported delay-updates_test.py only exercises the tree root, so |
| 10 |
this companion drives a >=3-deep tree. |
| 11 |
|
| 12 |
Asserts, at every level of the tree: |
| 13 |
* a --delay-updates transfer reproduces the source and leaves no .~tmp~ |
| 14 |
staging directory behind; |
| 15 |
* a stale file pre-planted in a deep .~tmp~ staging dir is overwritten |
| 16 |
cleanly and the staging dir is removed. |
| 17 |
""" |
| 18 |
|
| 19 |
import os |
| 20 |
|
| 21 |
from rsyncfns import ( |
| 22 |
FROMDIR, TODIR, |
| 23 |
assert_same, make_tree, rmtree, run_rsync, test_fail, walk_dirs, |
| 24 |
walk_files, |
| 25 |
) |
| 26 |
|
| 27 |
src = FROMDIR |
| 28 |
deepdir = os.path.join('d1', 'd2', 'd3') |
| 29 |
|
| 30 |
|
| 31 |
def no_staging_left(): |
| 32 |
leftover = [p for p in walk_dirs(TODIR) if p.name == '.~tmp~'] |
| 33 |
if leftover: |
| 34 |
test_fail(f"--delay-updates left staging dirs behind: {leftover}") |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
rmtree(src) |
| 39 |
rmtree(TODIR) |
| 40 |
make_tree(src, depth=3, data=True, data_size=4096) |
| 41 |
rels = [p.relative_to(src) for p in walk_files(src)] |
| 42 |
|
| 43 |
run_rsync('-a', '--delay-updates', f'{src}/', f'{TODIR}/') |
| 44 |
for rel in rels: |
| 45 |
assert_same(TODIR / rel, src / rel, label=f'delay-updates initial {rel}') |
| 46 |
no_staging_left() |
| 47 |
|
| 48 |
|
| 49 |
for rel in rels: |
| 50 |
with open(src / rel, 'ab') as f: |
| 51 |
f.write(b'\nupdated content\n') |
| 52 |
|
| 53 |
stage = TODIR / deepdir / '.~tmp~' |
| 54 |
stage.mkdir(parents=True, exist_ok=True) |
| 55 |
(stage / 'f3').write_bytes(b'stale staged junk\n') |
| 56 |
|
| 57 |
run_rsync('-a', '--delay-updates', f'{src}/', f'{TODIR}/') |
| 58 |
for rel in rels: |
| 59 |
assert_same(TODIR / rel, src / rel, label=f'delay-updates update {rel}') |
| 60 |
no_staging_left() |
| 61 |
|
| 62 |
print("delay-updates-deep: staging + clean overwrite verified at depth") |