| 1 |
|
| 2 |
"""Coverage of -X (xattrs) at depth. |
| 3 |
|
| 4 |
xattrs_test.py exercises a shallow tree; this companion sets a distinctive user |
| 5 |
xattr on a file AND a directory at every level of a >=3-deep tree and checks |
| 6 |
that -X reproduces them all (the xattr is applied per entry, on a name whose |
| 7 |
parent chain the resolver restructure rewrites). |
| 8 |
""" |
| 9 |
|
| 10 |
import os |
| 11 |
import sys |
| 12 |
|
| 13 |
from rsyncfns import ( |
| 14 |
FROMDIR, TODIR, |
| 15 |
make_tree, rmtree, run_rsync, test_fail, test_skipped, |
| 16 |
walk_dirs, walk_files, xattr_dump, xattr_set, xattrs_supported, |
| 17 |
) |
| 18 |
|
| 19 |
if not xattrs_supported(): |
| 20 |
test_skipped("rsync built without xattr support (or no xattr tooling here)") |
| 21 |
|
| 22 |
src = FROMDIR |
| 23 |
rmtree(src) |
| 24 |
rmtree(TODIR) |
| 25 |
make_tree(src, depth=3) |
| 26 |
|
| 27 |
entries = [p.relative_to(src) for p in (walk_dirs(src) + walk_files(src))] |
| 28 |
entries.sort() |
| 29 |
|
| 30 |
os.chdir(src) |
| 31 |
try: |
| 32 |
for i, rel in enumerate(entries): |
| 33 |
xattr_set('depth', f'value-{i}-{rel}', str(rel)) |
| 34 |
except OSError as e: |
| 35 |
test_skipped(f"unable to set an xattr on this filesystem: {e}") |
| 36 |
|
| 37 |
want = xattr_dump(*[str(r) for r in entries]) |
| 38 |
|
| 39 |
run_rsync('-aX', '-f-x_system.*', '-f-x_security.*', '--super', |
| 40 |
f'{src}/', f'{TODIR}/') |
| 41 |
|
| 42 |
os.chdir(TODIR) |
| 43 |
got = xattr_dump(*[str(r) for r in entries]) |
| 44 |
|
| 45 |
if got != want: |
| 46 |
from difflib import unified_diff |
| 47 |
sys.stdout.write(''.join(unified_diff( |
| 48 |
want.splitlines(keepends=True), got.splitlines(keepends=True), |
| 49 |
fromfile='source', tofile='dest'))) |
| 50 |
test_fail("xattrs differ between source and destination at depth") |
| 51 |
|
| 52 |
print("xattrs-depth: -X reproduced a user xattr on every entry at depth") |