Debian Codegraph @

testsuite/chmod_test.py

raw symbols SCIP
1 #!/usr/bin/env python3
2 # Python rewrite of testsuite/chmod.test.
3 #
4 # Test that varied read-only and set[ug]id permissions transfer correctly
5 # both on first copy (whole-file) and on subsequent updates (delta).
6
7 import os
8
9 from rsyncfns import FROMDIR, TODIR, checkit, hands_setup
10
11
12 hands_setup()
13
14 # Three of these chmod modes use the sticky/setuid/setgid bits which some
15 # platforms refuse for non-root. The shell test tries them in descending
16 # order, falling back to plain mode on rejection.
17 def _try_chmods(path, modes):
18 for m in modes:
19 try:
20 os.chmod(path, m)
21 return
22 except PermissionError:
23 continue
24 # Final mode in the list is the no-special-bits fallback.
25 os.chmod(path, modes[-1])
26
27
28 os.chmod(FROMDIR / 'text', 0o440)
29 os.chmod(FROMDIR / 'dir' / 'text', 0o500)
30 _try_chmods(FROMDIR / 'dir' / 'subdir' / 'foobar.baz',
31 [0o6450, 0o2450, 0o1450, 0o450])
32 _try_chmods(FROMDIR / 'dir' / 'subdir' / 'subsubdir' / 'etc-ltr-list',
33 [0o2670, 0o1670, 0o670])
34
35 # First a normal whole-file copy.
36 checkit(['-avv', f'{FROMDIR}/', str(TODIR)], FROMDIR, TODIR)
37
38 # Then update through delta with -I (ignore times) so every file is
39 # touched again.
40 checkit(['-avvI', '--no-whole-file', f'{FROMDIR}/', str(TODIR)], FROMDIR, TODIR)