Debian Codegraph @

testsuite/alt-dest-deep_test.py

raw symbols SCIP
1 #!/usr/bin/env python3
2 """Property-level coverage of --link-dest / --copy-dest / --compare-dest at
3 depth and across directory boundaries.
4
5 The existing alt-dest_test.py is a faithful port that checks tree equality;
6 this companion asserts the *distinguishing* property of each option, at every
7 level of a >=3-deep tree, with the alternate-destination tree placed OUTSIDE
8 both the source and destination trees (a sibling, not a parent/child):
9
10 --link-dest unchanged files are HARD-LINKED to the reference (same inode);
11 a changed file is transferred fresh (not linked).
12 --copy-dest unchanged files are COPIED from the reference (never linked);
13 dest is complete and byte-identical to the source.
14 --compare-dest unchanged files are NEITHER transferred NOR created in dest;
15 only a changed/new file lands in dest.
16
17 These options drive the two-dirfd / outside-tree path handling the resolver
18 restructure rewrites, so they must be guarded at depth.
19 """
20
21 import os
22
23 from rsyncfns import (
24 FROMDIR, SCRATCHDIR, TODIR,
25 assert_exists, assert_hardlinked, assert_not_exists, assert_not_hardlinked,
26 assert_same, make_tree, rmtree, run_rsync, walk_files,
27 )
28
29 src = FROMDIR
30 ref = SCRATCHDIR / 'altref' # sibling of from/ and to/ -- outside both trees
31
32 rmtree(src)
33 rmtree(ref)
34 rmtree(TODIR)
35
36 # A >=3-deep source: f0 at the root, then d1/f1, d1/d2/f2, d1/d2/d3/f3.
37 make_tree(src, depth=3, data=True)
38
39 # Reference tree == an exact copy of the source, so every file is "identical"
40 # for the alt-dest comparison.
41 run_rsync('-a', f'{src}/', f'{ref}/')
42
43 # Now make the deepest file differ so it must be transferred in every mode.
44 changed = os.path.join('d1', 'd2', 'd3', 'f3')
45 with open(src / changed, 'ab') as f:
46 f.write(b'a changed deep tail\n')
47
48 rels = [p.relative_to(src) for p in walk_files(src)]
49 assert os.path.join('d1', 'd2', 'd3', 'f3') in [str(r) for r in rels]
50
51
52 def run_to(opt):
53 rmtree(TODIR)
54 run_rsync('-a', f'--{opt}={ref}', f'{src}/', f'{TODIR}/')
55
56
57 # --- --link-dest: unchanged -> hardlink to ref; changed -> fresh copy -------
58 run_to('link-dest')
59 for rel in rels:
60 d, r = TODIR / rel, ref / rel
61 if str(rel) == changed:
62 assert_not_hardlinked(d, r, label=f'link-dest changed {rel}')
63 assert_same(d, src / rel, label=f'link-dest changed {rel}')
64 else:
65 assert_hardlinked(d, r, label=f'link-dest unchanged {rel}')
66
67 # --- --copy-dest: every file copied (never linked), dest complete -----------
68 run_to('copy-dest')
69 for rel in rels:
70 d, r = TODIR / rel, ref / rel
71 assert_exists(d, label=f'copy-dest {rel}')
72 assert_same(d, src / rel, label=f'copy-dest {rel}')
73 assert_not_hardlinked(d, r, label=f'copy-dest {rel}')
74
75 # --- --compare-dest: unchanged absent from dest; only the changed file lands -
76 run_to('compare-dest')
77 for rel in rels:
78 d = TODIR / rel
79 if str(rel) == changed:
80 assert_exists(d, label=f'compare-dest changed {rel}')
81 assert_same(d, src / rel, label=f'compare-dest changed {rel}')
82 else:
83 assert_not_exists(d, label=f'compare-dest unchanged {rel}')
84
85 print("alt-dest-deep: link-dest/copy-dest/compare-dest verified at depth")