Debian Codegraph @

testsuite/merge_test.py

raw symbols SCIP
1 #!/usr/bin/env python3
2 # Python rewrite of testsuite/merge.test.
3 #
4 # Verify that rsync merges files from multiple source directories into a
5 # single destination, with later sources NOT clobbering earlier ones for
6 # unchanged content and per-directory conflict resolution behaving as in
7 # the canonical case.
8
9 import os
10 import time
11
12 from rsyncfns import (
13 CHKDIR, TMPDIR, TODIR,
14 checkit, cp_touch, run_rsync,
15 )
16
17
18 # Use relative names below so the rsync command line exercises the
19 # arg-parsing path the way the shell test did.
20 os.chdir(TMPDIR)
21
22 for d in ('from1', 'from2', 'from3', 'deep'):
23 os.mkdir(d)
24 for d in ('from2/sub1', 'from3/sub1', 'from3/sub2', 'from1/dir-and-not-dir'):
25 os.mkdir(d)
26
27 CHKDIR.mkdir(exist_ok=True)
28 for d in ('sub1', 'sub2', 'dir-and-not-dir'):
29 (CHKDIR / d).mkdir()
30
31 with open('from1/one', 'w') as f:
32 f.write("one\n")
33 cp_touch('from1/one', 'from2/one')
34 cp_touch('from1/one', 'from3/one')
35
36 with open('from1/two', 'w') as f:
37 f.write("two\n")
38 with open('from2/three', 'w') as f:
39 f.write("three\n")
40 with open('from3/four', 'w') as f:
41 f.write("four\n")
42 with open('from1/five', 'w') as f:
43 f.write("five\n")
44 with open('from3/six', 'w') as f:
45 f.write("six\n")
46 with open('from2/sub1/uno', 'w') as f:
47 f.write("sub1\n")
48 cp_touch('from2/sub1/uno', 'from3/sub1/uno')
49 with open('from3/sub1/dos', 'w') as f:
50 f.write("sub2\n")
51 with open('from2/sub1/tres', 'w') as f:
52 f.write("sub3\n")
53 with open('from3/sub2/subby', 'w') as f:
54 f.write("subby\n")
55 with open('from1/dir-and-not-dir/inside', 'w') as f:
56 f.write("extra\n")
57 with open('from3/dir-and-not-dir', 'w') as f:
58 f.write("not-dir\n")
59 with open('deep/arg-test', 'w') as f:
60 f.write("arg-test\n")
61 with open('shallow', 'w') as f:
62 f.write("shallow\n")
63
64 for src in ('from1/one', 'from1/two', 'from2/three', 'from3/four',
65 'from1/five', 'from3/six'):
66 cp_touch(src, str(CHKDIR))
67 cp_touch('deep/arg-test', str(CHKDIR))
68 cp_touch('shallow', str(CHKDIR))
69 cp_touch('from1/dir-and-not-dir/inside', str(CHKDIR / 'dir-and-not-dir'))
70 for src in ('from2/sub1/uno', 'from3/sub1/dos', 'from2/sub1/tres'):
71 cp_touch(src, str(CHKDIR / 'sub1'))
72 cp_touch('from3/sub2/subby', str(CHKDIR / 'sub2'))
73
74 # Make sure time has moved on before the rsync runs.
75 time.sleep(1)
76
77 # Pre-sync directory-only updates to flatten directory-time differences,
78 # matching the shell test's --existing -f 'exclude,! */' preparation.
79 def _flatten_dirs(src, dst):
80 run_rsync('-av', '--existing', '-f', 'exclude,! */', f'{src}/', f'{dst}/')
81
82
83 _flatten_dirs('from1', 'from2')
84 _flatten_dirs('from2', 'from3')
85 _flatten_dirs('from1', str(CHKDIR))
86 _flatten_dirs('from3', str(CHKDIR))
87
88 checkit(['-avv', 'deep/arg-test', 'shallow', 'from1/', 'from2/', 'from3/', 'to/'],
89 CHKDIR, TODIR)