Debian Codegraph @

testsuite/link-dest-pathroot_test.py

raw symbols SCIP
1 #!/usr/bin/env python3
2 # Functional regression: a relative --link-dest=../sibling against a daemon
3 # module with `path = /` (the intersection of #897 and #915).
4 #
5 # #915 re-anchors the receiver's basis open at the module root so an in-module
6 # "../01" climb is honoured. The gate keyed on a nonzero module_dirlen, but a
7 # `path = /` module has module_dirlen == 0 (clientserver.c), so the re-anchor
8 # was skipped there and --link-dest=../01 was silently ignored (every file
9 # re-transferred) even though plain #915 modules were fixed.
10 #
11 # Like link-dest-relative-basis, the secure per-component walk now honours the
12 # in-module `..` climb on every platform (it pops `..` to the held parent), so a
13 # `path = /` module uses the relative basis too. Runs at any uid.
14
15 import shutil
16 import subprocess
17
18 from rsyncfns import (
19 SCRATCHDIR, make_data_file, makepath, rmtree, rsync_argv, start_test_daemon,
20 test_fail, write_daemon_conf,
21 )
22
23 DAEMON_PORT = 12931
24 DATA_SIZE = 40000
25
26 # dest 00 and basis 01 live side by side under `base`; the module is rooted at
27 # "/", so the served subtree is addressed by its absolute path minus the leading
28 # slash, and --link-dest=../01 climbs dest 00 -> sibling 01 (both inside /).
29 base = SCRATCHDIR / 'bakroot'
30 src = SCRATCHDIR / 'srcroot'
31 rmtree(base)
32 rmtree(src)
33 makepath(base / '01', src)
34 make_data_file(src / 'f.dat', DATA_SIZE)
35 shutil.copy2(src / 'f.dat', base / '01' / 'f.dat')
36
37 conf = write_daemon_conf([
38 ('root', {'path': '/', 'read only': 'no'}),
39 ])
40 url = start_test_daemon(conf, DAEMON_PORT)
41
42 base_rel = str(base).lstrip('/') # address `base` via the path=/ module
43 rmtree(base / '00')
44 proc = subprocess.run(
45 rsync_argv('-a', '--link-dest=../01', f'{src}/', f'{url}root/{base_rel}/00/'),
46 stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True)
47 out = proc.stdout or ''
48 if proc.returncode != 0:
49 test_fail(f"path=/ --link-dest push failed unexpectedly (rc={proc.returncode}):\n{out}")
50
51 dest = base / '00' / 'f.dat'
52 basis = base / '01' / 'f.dat'
53 if not dest.is_file():
54 test_fail(f"destination file missing ({dest})")
55
56 ds, bs = dest.stat(), basis.stat()
57 if (ds.st_dev, ds.st_ino) != (bs.st_dev, bs.st_ino):
58 test_fail(
59 "#915 (path=/ case): a `path = /` daemon module ignored --link-dest=../01 "
60 "(module_dirlen==0 skipped the re-anchor) -- the file was re-transferred "
61 "instead of hard-linked. The secure walk must honour the in-module climb.")
62 # Honoured: the dest is hard-linked to the in-module sibling basis.