| 1 |
|
| 2 |
"""Coverage of -A (acls) at depth. |
| 3 |
|
| 4 |
acls_test.py exercises a shallow tree; this companion sets a distinctive POSIX |
| 5 |
ACL on a file AND a directory at every level of a >=3-deep tree and checks that |
| 6 |
-A reproduces them (the ACL is applied per entry, on a name whose parent chain |
| 7 |
the resolver restructure rewrites). |
| 8 |
""" |
| 9 |
|
| 10 |
import os |
| 11 |
import shutil |
| 12 |
import subprocess |
| 13 |
|
| 14 |
from rsyncfns import ( |
| 15 |
FROMDIR, TODIR, |
| 16 |
make_tree, rmtree, run_rsync, test_fail, test_skipped, |
| 17 |
walk_dirs, walk_files, |
| 18 |
) |
| 19 |
|
| 20 |
vv = run_rsync('-VV', check=True, capture_output=True).stdout |
| 21 |
if '"ACLs": true' not in vv: |
| 22 |
test_skipped("rsync built without ACL support") |
| 23 |
if not (shutil.which('setfacl') and shutil.which('getfacl')): |
| 24 |
test_skipped("setfacl/getfacl not available") |
| 25 |
|
| 26 |
src = FROMDIR |
| 27 |
rmtree(src) |
| 28 |
rmtree(TODIR) |
| 29 |
make_tree(src, depth=3) |
| 30 |
|
| 31 |
entries = [p.relative_to(src) for p in (walk_dirs(src) + walk_files(src))] |
| 32 |
entries.sort() |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
for rel in entries: |
| 37 |
r = subprocess.run(['setfacl', '-m', 'u:0:r-x', str(src / rel)]) |
| 38 |
if r.returncode != 0: |
| 39 |
test_skipped("filesystem does not support setting ACLs") |
| 40 |
|
| 41 |
|
| 42 |
def getfacl(path): |
| 43 |
|
| 44 |
|
| 45 |
out = subprocess.check_output(['getfacl', str(path)], text=True, |
| 46 |
stderr=subprocess.DEVNULL) |
| 47 |
return ''.join(ln for ln in out.splitlines(keepends=True) |
| 48 |
if not ln.startswith('#')) |
| 49 |
|
| 50 |
|
| 51 |
run_rsync('-aA', f'{src}/', f'{TODIR}/') |
| 52 |
|
| 53 |
for rel in entries: |
| 54 |
want = getfacl(src / rel) |
| 55 |
got = getfacl(TODIR / rel) |
| 56 |
|
| 57 |
if 'user:root:r-x' not in got and 'user:0:r-x' not in got: |
| 58 |
test_fail(f"-A did not reproduce the named-user ACL on {rel}:\n{got}") |
| 59 |
if want != got: |
| 60 |
test_fail(f"-A: ACL of {rel} differs\n--- source ---\n{want}" |
| 61 |
f"--- dest ---\n{got}") |
| 62 |
|
| 63 |
print("acls-depth: -A reproduced a POSIX ACL on every entry at depth") |