| 1 |
|
| 2 |
"""Coverage of -p (perms), -t (times) and --chmod at depth. |
| 3 |
|
| 4 |
Each attribute is set distinctively on a file AND a directory at every level of |
| 5 |
a >=3-deep tree, then checked per entry after the transfer -- the metadata is |
| 6 |
applied as a single-component operation on an entry whose parent chain the |
| 7 |
resolver restructure rewrites, so it must be verified deep, not just at the |
| 8 |
root. |
| 9 |
""" |
| 10 |
|
| 11 |
import os |
| 12 |
|
| 13 |
from rsyncfns import ( |
| 14 |
FROMDIR, TODIR, |
| 15 |
assert_mode, assert_mtime_close, make_tree, rmtree, run_rsync, test_fail, |
| 16 |
walk_dirs, walk_files, |
| 17 |
) |
| 18 |
|
| 19 |
src = FROMDIR |
| 20 |
FILE_MODE = 0o640 |
| 21 |
DIR_MODE = 0o750 |
| 22 |
BASE_MTIME = 1_400_000_000 |
| 23 |
|
| 24 |
|
| 25 |
def seed(): |
| 26 |
rmtree(src) |
| 27 |
rmtree(TODIR) |
| 28 |
make_tree(src, depth=3) |
| 29 |
for i, f in enumerate(walk_files(src)): |
| 30 |
os.chmod(f, FILE_MODE) |
| 31 |
os.utime(f, (BASE_MTIME + i * 100, BASE_MTIME + i * 100)) |
| 32 |
for d in walk_dirs(src): |
| 33 |
os.chmod(d, DIR_MODE) |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
seed() |
| 38 |
run_rsync('-rlpt', f'{src}/', f'{TODIR}/') |
| 39 |
for f in walk_files(src): |
| 40 |
assert_mode(TODIR / f.relative_to(src), FILE_MODE, label=f'-p file {f.name}') |
| 41 |
for d in walk_dirs(src): |
| 42 |
assert_mode(TODIR / d.relative_to(src), DIR_MODE, label=f'-p dir {d.name}') |
| 43 |
|
| 44 |
|
| 45 |
for f in walk_files(src): |
| 46 |
rel = f.relative_to(src) |
| 47 |
assert_mtime_close(TODIR / rel, f.stat().st_mtime, label=f'-t {rel}') |
| 48 |
|
| 49 |
|
| 50 |
seed() |
| 51 |
run_rsync('-a', '--chmod=D710,F600', f'{src}/', f'{TODIR}/') |
| 52 |
for f in walk_files(src): |
| 53 |
assert_mode(TODIR / f.relative_to(src), 0o600, label=f'--chmod file {f.name}') |
| 54 |
for d in walk_dirs(src): |
| 55 |
assert_mode(TODIR / d.relative_to(src), 0o710, label=f'--chmod dir {d.name}') |
| 56 |
|
| 57 |
print("metadata-depth: -p / -t / --chmod verified per entry at depth") |