Debian Codegraph @

testsuite/daemon-copylinks-intree_test.py

raw symbols SCIP
1 #!/usr/bin/env python3
2 """A daemon sender must follow an in-tree symlink for -L/--copy-links.
3
4 A read-only daemon module that contains a benign in-tree symlink (`lnk` ->
5 a sibling regular file inside the module) must, when pulled with `-aL`, transfer
6 the symlink's target as a regular file -- exactly as a plain local `-aL` does.
7
8 Regression: the daemon sender was observed to refuse the in-tree symlink with
9 "failed to open ... Too many levels of symbolic links" (ELOOP), exit 23, leaving
10 the file untransferred -- while a local `-aL` of the same tree, and an older
11 rsync over the daemon, both follow it. The leaf-symlink refusal that protects the
12 content open must not defeat an operator's explicit --copy-links request for an
13 in-tree (non-escaping) symlink.
14 """
15
16 import os
17
18 from rsyncfns import (
19 SCRATCHDIR, assert_same, makepath, rmtree, run_rsync, start_test_daemon,
20 test_fail, write_daemon_conf,
21 )
22
23 DAEMON_PORT = 12935
24
25 served = SCRATCHDIR / 'cli_mod'
26 dest = SCRATCHDIR / 'cli_dest'
27 rmtree(served)
28 rmtree(dest)
29 makepath(served)
30 (served / 'real').write_text("symlink target content\n")
31 os.symlink('real', served / 'lnk') # in-tree symlink to a sibling file
32 (served / 'anchor').write_text("anchor\n")
33
34 conf = write_daemon_conf([('m', {'path': str(served), 'read only': 'yes'})])
35 url = start_test_daemon(conf, DAEMON_PORT)
36
37 # Pull with -L: the daemon sender must follow the in-tree symlink and send its
38 # target as a regular file (codes 0 ok; 23 = the very failure we are guarding).
39 run_rsync('-aL', f'{url}m/', f'{dest}/', check=False)
40
41 if not (dest / 'lnk').exists():
42 test_fail("daemon -aL did not transfer the in-tree symlink 'lnk' "
43 "(the sender refused to follow it)")
44 if os.path.islink(dest / 'lnk'):
45 test_fail("daemon -aL left 'lnk' as a symlink instead of following it")
46 assert_same(dest / 'lnk', served / 'real',
47 label="daemon -aL followed the in-tree symlink to its target")
48
49 print("daemon-copylinks-intree: daemon -aL follows an in-tree symlink")