Debian Codegraph @

testsuite/hardlinks-deep_test.py

raw symbols SCIP
1 #!/usr/bin/env python3
2 """Coverage of -H across directory boundaries.
3
4 hardlinks_test.py exercises -H on sibling files at the tree root; this
5 companion checks that -H preserves a hard link whose two names live in
6 DIFFERENT directories several levels deep (the cross-directory case the
7 resolver restructure touches), and that without -H the names become
8 independent inodes.
9 """
10
11 from rsyncfns import (
12 FROMDIR, TODIR,
13 assert_hardlinked, assert_not_hardlinked, makepath, rmtree, run_rsync,
14 )
15 import os
16
17 src = FROMDIR
18 a = os.path.join('a', 'aa', 'orig')
19 b = os.path.join('b', 'bb', 'hardlink')
20
21 rmtree(src)
22 rmtree(TODIR)
23 makepath(src / 'a' / 'aa', src / 'b' / 'bb')
24 (src / a).write_text("shared content across directories\n")
25 os.link(src / a, src / b) # one inode, two names in different dirs
26
27 # -H preserves the cross-directory hard link.
28 run_rsync('-aH', f'{src}/', f'{TODIR}/')
29 assert_hardlinked(TODIR / a, TODIR / b, label='-H cross-dir hardlink')
30
31 # Without -H the two names are copied as independent files.
32 rmtree(TODIR)
33 run_rsync('-a', f'{src}/', f'{TODIR}/')
34 assert_not_hardlinked(TODIR / a, TODIR / b, label='no -H => separate inodes')
35
36 print("hardlinks-deep: -H preserves a cross-directory hard link at depth")