| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
import subprocess |
| 9 |
from rsyncfns import ( |
| 10 |
FROMDIR, SCRATCHDIR, forced_protocol, makepath, rmtree, run_rsync, rsync_argv, |
| 11 |
test_fail, test_skipped, xattr_set, xattrs_supported, |
| 12 |
) |
| 13 |
|
| 14 |
if not xattrs_supported(): |
| 15 |
test_skipped("needs xattr support to write an -X batch") |
| 16 |
|
| 17 |
proto = forced_protocol() |
| 18 |
if proto is not None and proto < 30: |
| 19 |
test_skipped("xattrs (-X) need protocol 30+") |
| 20 |
|
| 21 |
src = FROMDIR |
| 22 |
rmtree(src) |
| 23 |
makepath(src) |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
for i in range(40): |
| 29 |
f = src / f'f{i:03d}' |
| 30 |
f.write_text('x\n') |
| 31 |
try: |
| 32 |
xattr_set('user.m', 'v', f) |
| 33 |
except Exception as e: |
| 34 |
test_skipped(f"cannot set a user xattr on a regular file here: {e}") |
| 35 |
|
| 36 |
batch = SCRATCHDIR / 'xbatch' |
| 37 |
wb_dest = SCRATCHDIR / 'wb-dest' |
| 38 |
rmtree(wb_dest) |
| 39 |
|
| 40 |
run_rsync('-a', '-X', f'--only-write-batch={batch}', f'{src}/', str(wb_dest)) |
| 41 |
|
| 42 |
dest = SCRATCHDIR / 'rb-dest' |
| 43 |
rmtree(dest) |
| 44 |
makepath(dest) |
| 45 |
|
| 46 |
|
| 47 |
r = subprocess.run(rsync_argv('-a', f'--read-batch={batch}', str(dest)), |
| 48 |
capture_output=True, text=True) |
| 49 |
if r.returncode < 0 or r.returncode >= 128: |
| 50 |
test_fail(f'read-batch crashed (rc={r.returncode}): {r.stderr.strip()[:200]}') |
| 51 |
if not (dest / 'f000').exists(): |
| 52 |
test_fail(f'read-batch did not replay the files (rc={r.returncode}): ' |
| 53 |
f'{r.stderr.strip()[:200]}') |
| 54 |
print("scanner-batch-flag-mismatch: -X batch replayed with bare -a is clean") |