Debian Codegraph @

testsuite/relative-implied-symlink_test.py

raw symbols SCIP
1 """Pin that `-R`/`--relative` materializes implied parent dirs as REAL
2 directories even when a sending-side path element is a symlink.
3
4 The rsync(1) `--relative` entry claims: "Beginning with rsync 3.0.0, rsync
5 always sends these implied directories as real directories in the file list,
6 even if a path element is really a symlink on the sending side. This prevents
7 some really unexpected behaviors..." This test checks the "always" by making an
8 implied path element a symlink on the sender and confirming the receiver creates
9 it as a real directory (not a symlink), so the deep file lands under a real dir.
10
11 Pure local client behaviour: no daemon/root/tcp. Cross-version: expected
12 identical against --rsync-bin=old_versions/rsync_3.2.7 (3.2.7 >= 3.0.0).
13 """
14
15 import os
16 import subprocess
17
18 from rsyncfns import SCRATCHDIR, rmtree, rsync_argv, test_fail
19
20 base = SCRATCHDIR / 'relative-implied'
21 rmtree(base)
22 base.mkdir(parents=True)
23
24 src = base / 'src'
25 (src / 'realdir').mkdir(parents=True)
26 (src / 'realdir' / 'file').write_text('F\n')
27 os.symlink('realdir', src / 'link') # 'link' is a symlink path element
28
29 dst = base / 'dst'
30 rmtree(dst)
31 dst.mkdir()
32 # Transfer through the symlink path element with -R: src/./link/file
33 subprocess.run(rsync_argv('-a', '-R', f'{src}/./link/file', f'{dst}/'),
34 stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
35
36 p = dst / 'link'
37 if p.is_symlink():
38 test_fail("--relative: implied 'link' was sent as a symlink, not materialized "
39 "as a real directory (the 'always sends ... as real directories' "
40 "claim would be false)")
41 if not p.is_dir():
42 test_fail("--relative: implied 'link' was not created as a directory")
43 f = dst / 'link' / 'file'
44 if not f.is_file() or f.read_text() != 'F\n':
45 test_fail("--relative: deep file did not land under the materialized dir")
46
47 print("relative-implied-symlink: -R materializes an implied path element as a "
48 "REAL directory on the receiver even when it is a symlink on the sender -- "
49 "the 'always sends implied dirs as real directories' claim holds")