Debian Codegraph @

testsuite/executability_test.py

raw symbols SCIP
1 #!/usr/bin/env python3
2 # Python rewrite of testsuite/executability.test.
3 #
4 # Test --executability (-E): -E should propagate only the executable bits
5 # from source to destination (other permission changes ignored), while a
6 # normal copy without -E should leave the destination permissions alone.
7
8 import errno
9 import os
10
11 from rsyncfns import FROMDIR, TODIR, check_perms, run_rsync, test_skipped
12
13
14 FROMDIR.mkdir(parents=True, exist_ok=True)
15 (FROMDIR / '1').write_text("#!/bin/sh\necho 'Program One!'\n")
16 (FROMDIR / '2').write_text("#!/bin/sh\necho 'Program Two!'\n")
17
18 # Setuid-and-rwx for owner, nothing else. Some platforms reject 1700 for
19 # non-root callers (no permission to set sticky); FreeBSD rejects it with
20 # EFTYPE rather than EPERM. Only skip on those; re-raise anything unexpected.
21 _STICKY_SKIP_ERRNOS = {errno.EPERM, errno.EACCES, getattr(errno, 'EFTYPE', None)}
22 try:
23 os.chmod(FROMDIR / '1', 0o1700)
24 except OSError as e:
25 if e.errno not in _STICKY_SKIP_ERRNOS:
26 raise
27 test_skipped("Can't chmod")
28 os.chmod(FROMDIR / '2', 0o600)
29
30 run_rsync('-rvv', f'{FROMDIR}/', f'{TODIR}/')
31
32 check_perms(TODIR / '1', 'rwx------')
33 check_perms(TODIR / '2', 'rw-------')
34
35 # Permute the source/destination perms; without -E nothing should change.
36 os.chmod(FROMDIR / '1', 0o600)
37 os.chmod(FROMDIR / '2', 0o601)
38 os.chmod(TODIR / '2', 0o604)
39
40 run_rsync('-rvv', f'{FROMDIR}/', f'{TODIR}/')
41
42 check_perms(TODIR / '1', 'rwx------')
43 check_perms(TODIR / '2', 'rw----r--')
44
45 # Now with -E: 1 loses its x (source has 600), 2 gains x (source has 601).
46 run_rsync('-rvvE', f'{FROMDIR}/', f'{TODIR}/')
47
48 check_perms(TODIR / '1', 'rw-------')
49 check_perms(TODIR / '2', 'rwx---r-x')