| 1 |
|
| 2 |
"""Coverage: cache_tmp_acl/cache_tmp_xattr (and cache_rsync_acl/uncache_duo_acls) |
| 3 |
in backup.c make_backup_dir_tree(). |
| 4 |
|
| 5 |
When --backup --backup-dir=<dir> backs up a file at a nested path, rsync |
| 6 |
recreates the intermediate directories under the backup dir and copies |
| 7 |
each one's ACL/xattrs from the corresponding live directory. That copy |
| 8 |
goes through cache_tmp_acl()/cache_tmp_xattr() (backup.c:~127/134), which |
| 9 |
no other test reaches: backup_test.py doesn't pass -A/-X, and the |
| 10 |
make_backup() per-file path normally short-circuits via link_or_rename() |
| 11 |
on a same-fs backup dir, never reaching its own cache_tmp_* block. |
| 12 |
|
| 13 |
Skips when the scratch fs lacks ACL or xattr support. |
| 14 |
""" |
| 15 |
|
| 16 |
import os |
| 17 |
|
| 18 |
from rsyncfns import ( |
| 19 |
SCRATCHDIR, |
| 20 |
acls_supported, xattrs_supported, acl_set, xattr_set, |
| 21 |
makepath, rmtree, rsync_argv, test_fail, test_skipped, |
| 22 |
) |
| 23 |
import subprocess |
| 24 |
|
| 25 |
if not acls_supported(): |
| 26 |
test_skipped("ACLs not supported on this filesystem") |
| 27 |
if not xattrs_supported(): |
| 28 |
test_skipped("xattrs not supported on this filesystem") |
| 29 |
|
| 30 |
src = SCRATCHDIR / 'bak-src' |
| 31 |
dest = SCRATCHDIR / 'bak-dest' |
| 32 |
bak = SCRATCHDIR / 'bak-dir' |
| 33 |
rmtree(src); rmtree(dest); rmtree(bak) |
| 34 |
makepath(src / 'd1' / 'd2', dest / 'd1' / 'd2', bak) |
| 35 |
|
| 36 |
|
| 37 |
(src / 'd1' / 'd2' / 'file').write_bytes(b'NEW') |
| 38 |
(dest / 'd1' / 'd2' / 'file').write_bytes(b'OLD') |
| 39 |
os.utime(dest / 'd1' / 'd2' / 'file', (1_600_000_000, 1_600_000_000)) |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
for d in (dest / 'd1', dest / 'd1' / 'd2'): |
| 45 |
if not acl_set('u:0:rwx', d): |
| 46 |
test_skipped(f"setfacl failed on {d}") |
| 47 |
xattr_set('user.bak-cache', 'v', d) |
| 48 |
|
| 49 |
r = subprocess.run( |
| 50 |
rsync_argv('-aAX', '--backup', f'--backup-dir={bak}', f'{src}/', f'{dest}/'), |
| 51 |
capture_output=True, text=True, |
| 52 |
) |
| 53 |
if r.returncode != 0: |
| 54 |
test_fail(f"-aAX --backup --backup-dir push -> rc={r.returncode}\n{r.stderr}") |
| 55 |
|
| 56 |
|
| 57 |
bf = bak / 'd1' / 'd2' / 'file' |
| 58 |
if not bf.is_file() or bf.read_bytes() != b'OLD': |
| 59 |
test_fail(f"backup file missing or wrong content: {bf}") |
| 60 |
for d in (bak / 'd1', bak / 'd1' / 'd2'): |
| 61 |
if not d.is_dir(): |
| 62 |
test_fail(f"backup intermediate dir not created: {d}") |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
if (dest / 'd1' / 'd2' / 'file').read_bytes() != b'NEW': |
| 74 |
test_fail("dest/d1/d2/file not updated to NEW") |
| 75 |
|
| 76 |
print("backup-acl-xattr-cache: make_backup_dir_tree cache_tmp_acl/xattr -> " |
| 77 |
"bak/d1, bak/d2 created with propagated ACL+xattr") |