Debian Codegraph @

testsuite/keep-dirlinks-symlinked-dest_test.py

raw symbols SCIP
1 #!/usr/bin/env python3
2 # --keep-dirlinks (-K) into a symlinked destination directory must follow the
3 # symlink and write into the real dir -- that is the entire purpose of -K
4 # (treat a symlinked dir on the receiver as a dir; the #715 family).
5 #
6 # A/B-discovered 3.5 regression (abdiff: 3.5 vs 3.4.4): an early per-component
7 # O_NOFOLLOW resolver refused the in-tree dir-symlink that -K is meant to follow,
8 # so the transfer failed (Not a directory -> exit 23, the directory's files lost;
9 # near-silent). The secure resolver now follows in-tree directory symlinks on
10 # every platform, so -K writes through the symlinked dest dir uniformly; 3.4.x is
11 # unaffected. Plain transfer, no root.
12
13 import os
14
15 from rsyncfns import SCRATCHDIR, assert_same, makepath, rmtree, run_rsync, test_fail
16
17 base = SCRATCHDIR / 'kdl'
18 src = base / 'src'
19 dest = base / 'dest'
20 rmtree(base)
21 makepath(src / 'dir', dest / 'realdir')
22 (src / 'dir' / 'f1').write_text('one\n')
23 (src / 'dir' / 'f2').write_text('two\n')
24 (src / 'top.txt').write_text('top\n')
25 # The receiver already has the destination subdir as an in-tree symlink to a
26 # real directory -- exactly what --keep-dirlinks is for.
27 os.symlink('realdir', dest / 'dir')
28
29 run_rsync('-aK', f'{src}/', f'{dest}/') # check=True: resolver follows the in-tree dest symlink
30
31 real = dest / 'realdir'
32 for n in ('f1', 'f2'):
33 if not (real / n).is_file():
34 test_fail(f"-K did not follow the symlinked dest dir: {real / n} missing")
35 assert_same(src / 'dir' / n, real / n, label=f'-K content {n}')
36
37 print("keep-dirlinks-symlinked-dest: -K follows a symlinked destination directory")