| 1 |
|
| 2 |
"""Breadth coverage of the algorithm-selection options at depth: |
| 3 |
--compress-choice / --compress-level / --skip-compress and |
| 4 |
--checksum-choice / --checksum-seed. |
| 5 |
|
| 6 |
Compression and checksum choice don't change the result, so each available |
| 7 |
algorithm is exercised for a clean, byte-identical transfer of a >=3-deep tree |
| 8 |
(proving the option parses, negotiates and doesn't corrupt data). |
| 9 |
""" |
| 10 |
|
| 11 |
import json |
| 12 |
import re |
| 13 |
|
| 14 |
from rsyncfns import ( |
| 15 |
FROMDIR, TODIR, |
| 16 |
assert_same, make_tree, rmtree, run_rsync, test_fail, walk_files, |
| 17 |
) |
| 18 |
|
| 19 |
src = FROMDIR |
| 20 |
vv = json.loads(run_rsync('-VV', check=True, capture_output=True).stdout) |
| 21 |
compressors = [a for a in vv.get('compress_list', []) if a != 'none'] |
| 22 |
checksums = [a for a in vv.get('checksum_list', []) if a != 'none'] |
| 23 |
|
| 24 |
|
| 25 |
def fresh(): |
| 26 |
rmtree(src) |
| 27 |
rmtree(TODIR) |
| 28 |
make_tree(src, depth=3, data=True, data_size=4096) |
| 29 |
return [p.relative_to(src) for p in walk_files(src)] |
| 30 |
|
| 31 |
|
| 32 |
def verify(rels, label): |
| 33 |
for rel in rels: |
| 34 |
assert_same(TODIR / rel, src / rel, label=f'{label} {rel}') |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
for algo in compressors: |
| 42 |
rels = fresh() |
| 43 |
proc = run_rsync('-az', f'--compress-choice={algo}', '--debug=NSTR', |
| 44 |
f'{src}/', f'{TODIR}/', capture_output=True) |
| 45 |
if not re.search(rf'compress: {re.escape(algo)} \(level', proc.stdout): |
| 46 |
test_fail(f"--compress-choice={algo} was not the selected compressor; " |
| 47 |
f"--debug=NSTR output:\n{proc.stdout}") |
| 48 |
verify(rels, f'--compress-choice={algo}') |
| 49 |
|
| 50 |
|
| 51 |
rels = fresh() |
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
level_algo = next((a for a in ('zlibx', 'zlib') if a in compressors), None) |
| 56 |
level_args = [f'--compress-choice={level_algo}'] if level_algo else [] |
| 57 |
proc = run_rsync('-az', *level_args, '--compress-level=9', '--debug=NSTR', |
| 58 |
f'{src}/', f'{TODIR}/', capture_output=True) |
| 59 |
if not re.search(r'compress: \S+ \(level 9\)', proc.stdout): |
| 60 |
test_fail("--compress-level=9 was not applied; " |
| 61 |
f"--debug=NSTR output:\n{proc.stdout}") |
| 62 |
verify(rels, '--compress-level=9') |
| 63 |
|
| 64 |
|
| 65 |
rels = fresh() |
| 66 |
(src / 'd1' / 'd2' / 'x.gz').write_bytes(b'\x1f\x8b' + b'pseudo gzip body ' * 64) |
| 67 |
run_rsync('-az', '--skip-compress=gz', f'{src}/', f'{TODIR}/') |
| 68 |
assert_same(TODIR / 'd1' / 'd2' / 'x.gz', src / 'd1' / 'd2' / 'x.gz', |
| 69 |
label='--skip-compress gz') |
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
for algo in checksums: |
| 75 |
rels = fresh() |
| 76 |
proc = run_rsync('-a', '-c', f'--checksum-choice={algo}', '--debug=NSTR', |
| 77 |
f'{src}/', f'{TODIR}/', capture_output=True) |
| 78 |
if not re.search(rf'checksum: {re.escape(algo)}\b', proc.stdout): |
| 79 |
test_fail(f"--checksum-choice={algo} was not the selected checksum; " |
| 80 |
f"--debug=NSTR output:\n{proc.stdout}") |
| 81 |
verify(rels, f'--checksum-choice={algo}') |
| 82 |
|
| 83 |
|
| 84 |
rels = fresh() |
| 85 |
run_rsync('-a', '-c', '--checksum-seed=12345', f'{src}/', f'{TODIR}/') |
| 86 |
verify(rels, '--checksum-seed') |
| 87 |
|
| 88 |
print("compress-options: compress/checksum algorithm selection verified at depth") |