Debian Codegraph @

testsuite/chmod-temp-dir_test.py

raw symbols SCIP
1 #!/usr/bin/env python3
2 # Python rewrite of testsuite/chmod-temp-dir.test.
3 #
4 # Like chmod_test.py, but uses --temp-dir pointing at a different
5 # filesystem so rsync must rename(2) across filesystems (i.e. fall back
6 # to copy+unlink) instead of the in-place rename it does when temp and
7 # destination are on the same fs. We probe candidate tmp paths to find
8 # one whose filesystem differs from the scratch dir.
9
10 import os
11 import subprocess
12
13 from rsyncfns import FROMDIR, SCRATCHDIR, TODIR, TOOLDIR, checkit, hands_setup, test_skipped
14
15
16 def _fsdev(path: str) -> str:
17 return subprocess.check_output(
18 [str(TOOLDIR / 'getfsdev'), path], text=True,
19 ).strip()
20
21
22 hands_setup()
23
24 scratch_dev = _fsdev(str(SCRATCHDIR))
25 tmpdir2 = None
26 candidates = [
27 os.environ.get('RSYNC_TEST_TMP', '/override-tmp-not-specified'),
28 '/run/shm', '/var/tmp', '/tmp',
29 ]
30 for cand in candidates:
31 if not (os.path.isdir(cand) and os.access(cand, os.W_OK)):
32 continue
33 if _fsdev(cand) != scratch_dev:
34 tmpdir2 = cand
35 break
36
37 if tmpdir2 is None:
38 test_skipped("Can't find a tmp dir on a different file system")
39
40
41 # Mirror chmod_test.py: set up a varied permission tree on the source.
42 def _try_chmods(path, modes):
43 for m in modes:
44 try:
45 os.chmod(path, m)
46 return
47 except PermissionError:
48 continue
49 os.chmod(path, modes[-1])
50
51
52 os.chmod(FROMDIR / 'text', 0o440)
53 os.chmod(FROMDIR / 'dir' / 'text', 0o500)
54 _try_chmods(FROMDIR / 'dir' / 'subdir' / 'foobar.baz',
55 [0o6450, 0o2450, 0o1450, 0o450])
56 _try_chmods(FROMDIR / 'dir' / 'subdir' / 'subsubdir' / 'etc-ltr-list',
57 [0o2670, 0o1670, 0o670])
58
59 # First a normal copy (whole-file) but through a cross-fs --temp-dir.
60 checkit(['-avv', f'--temp-dir={tmpdir2}', f'{FROMDIR}/', str(TODIR)],
61 FROMDIR, TODIR)
62
63 # Then an update through delta, still routing partial transfers across fs.
64 checkit(['-avvI', '--no-whole-file', f'--temp-dir={tmpdir2}',
65 f'{FROMDIR}/', str(TODIR)], FROMDIR, TODIR)