Debian Codegraph @

testsuite/relative-implied_test.py

raw symbols SCIP
1 #!/usr/bin/env python3
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) # make the default implied-dir mode deterministic (0o755)
19
20 base = SCRATCHDIR / 'rbase'
21 rmtree(base)
22 rmtree(TODIR)
23 makepath(base / 'a' / 'b' / 'c')
24 os.chmod(base / 'a' / 'b', 0o750) # distinctive mode on an implied dir
25 (base / 'a' / 'b' / 'c' / 'file').write_text("data\n")
26
27 os.chdir(base / 'a')
28
29 # -R: implied dirs b and c are recreated with the source's attributes.
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 # --no-implied-dirs: implied dir b is created with default (not source) attrs.
36 # At protocol 29 the generator rejects a multi-component path that has no
37 # transmitted directory entries ("invalid path from sender"), so this half is
38 # protocol-30+.
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 # The implied dir must get the default mode (0o777 & ~umask == 0o755),
47 # not the source's distinctive 0750 -- assert the exact mode, not merely
48 # "different from 0750".
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")