| 1 |
|
| 2 |
"""Coverage of -R implied directories and --no-implied-dirs at depth. |
| 3 |
|
| 4 |
With -R the directories implied by a source path are recreated at the |
| 5 |
destination AND have their attributes mirrored from the source. With |
| 6 |
--no-implied-dirs those implied directories are still created as needed but get |
| 7 |
default attributes instead of the source's. Verify the distinction on an |
| 8 |
implied directory carrying a non-default mode, several levels deep. |
| 9 |
""" |
| 10 |
|
| 11 |
import os |
| 12 |
|
| 13 |
from rsyncfns import ( |
| 14 |
SCRATCHDIR, TODIR, |
| 15 |
assert_mode, assert_same, forced_protocol, makepath, rmtree, run_rsync, |
| 16 |
) |
| 17 |
|
| 18 |
os.umask(0o022) |
| 19 |
|
| 20 |
base = SCRATCHDIR / 'rbase' |
| 21 |
rmtree(base) |
| 22 |
rmtree(TODIR) |
| 23 |
makepath(base / 'a' / 'b' / 'c') |
| 24 |
os.chmod(base / 'a' / 'b', 0o750) |
| 25 |
(base / 'a' / 'b' / 'c' / 'file').write_text("data\n") |
| 26 |
|
| 27 |
os.chdir(base / 'a') |
| 28 |
|
| 29 |
|
| 30 |
run_rsync('-aR', 'b/c/file', f'{TODIR}/') |
| 31 |
assert_mode(TODIR / 'b', 0o750, label='-R mirrors implied-dir mode') |
| 32 |
assert_same(TODIR / 'b' / 'c' / 'file', base / 'a' / 'b' / 'c' / 'file', |
| 33 |
label='-R deep file') |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
proto = forced_protocol() |
| 40 |
if proto is not None and proto < 30: |
| 41 |
print(f"relative-implied: protocol {proto} -- skipping --no-implied-dirs " |
| 42 |
"(the multi-component path is rejected by the proto-29 generator)") |
| 43 |
else: |
| 44 |
rmtree(TODIR) |
| 45 |
run_rsync('-aR', '--no-implied-dirs', 'b/c/file', f'{TODIR}/') |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
assert_mode(TODIR / 'b', 0o755, |
| 50 |
label='--no-implied-dirs uses the default mode, not source 0750') |
| 51 |
assert_same(TODIR / 'b' / 'c' / 'file', base / 'a' / 'b' / 'c' / 'file', |
| 52 |
label='--no-implied-dirs deep file') |
| 53 |
|
| 54 |
print("relative-implied: -R mirrors implied-dir attrs; --no-implied-dirs does not") |