Debian Codegraph @

testsuite/itemize_test.py

raw symbols SCIP
1 #!/usr/bin/env python3
2 # Python rewrite of testsuite/itemize.test.
3 #
4 # Test the output of various copy commands to ensure itemized output
5 # (-i, -ii) and double-verbose output (-vv) match the canonical
6 # representations across whole-file and delta paths.
7
8 import os
9 import shutil
10
11 from rsyncfns import (
12 CHKFILE, FROMDIR, RSYNC, SCRATCHDIR, SRCDIR, TMPDIR, TODIR,
13 all_plus, allspace, dots,
14 checkdiff, cp_p, makepath, run_rsync, v_filt, hardlink_symlinks_supported,
15 )
16
17
18 to2dir = TMPDIR / 'to2'
19
20 makepath(FROMDIR / 'foo', FROMDIR / 'bar' / 'baz')
21 cp_p(SRCDIR / 'configure.ac', FROMDIR / 'foo' / 'config1')
22 cp_p(SRCDIR / 'config.sub', FROMDIR / 'foo' / 'config2')
23 cp_p(SRCDIR / 'rsync.h', FROMDIR / 'bar' / 'baz' / 'rsync')
24 os.chmod(FROMDIR / 'foo' / 'config1', 0o600)
25 os.chmod(FROMDIR / 'foo' / 'config2', 0o600)
26 os.chmod(FROMDIR / 'bar' / 'baz' / 'rsync', 0o600)
27
28 old_umask = os.umask(0)
29 try:
30 os.symlink('../bar/baz/rsync', FROMDIR / 'foo' / 'sym')
31 finally:
32 os.umask(old_umask)
33
34 os.link(FROMDIR / 'foo' / 'config1', FROMDIR / 'foo' / 'extra')
35 if to2dir.is_file():
36 to2dir.unlink()
37
38
39 # Detect what this rsync build supports.
40 vv = run_rsync('-VV', check=True, capture_output=True).stdout
41 hardlink_symlinks = '"hardlink_symlinks": true' in vv
42 symtimes_supported = '"symtimes": true' in vv
43 # The only itemisation difference between a platform that can hard-link a
44 # symlink and one that cannot is the change-type letter where the symlink
45 # itself is transferred: hL when it is hard-linked, cL when it is copied.
46 # The attribute field, the "is uptodate" wording and the --copy-dest lines
47 # are identical either way -- measured on macOS 10.13, the one platform that
48 # lacks the capability (linkat(AT_FDCWD, sym, ..., 0) is EOPNOTSUPP there).
49 #
50 # The two answers can disagree, so both are asked. The build capability is
51 # decided by configure on whatever filesystem the source tree sat on, while the
52 # link happens on whichever filesystem holds the test data: macOS builds on APFS
53 # (yes) and can write to HFS+ (ENOTSUP). rsync falls back to a copy when the
54 # filesystem refuses, so the letter follows the filesystem.
55 L = ('hL' if hardlink_symlinks and hardlink_symlinks_supported(SCRATCHDIR)
56 else 'cL')
57
58 if 'protocol=2' in RSYNC:
59 T = '.T'
60 elif symtimes_supported:
61 T = '.t'
62 else:
63 T = '.T'
64
65
66 # First check: -iplr basic itemize on a fresh transfer.
67 checkdiff(['-iplr', f'{FROMDIR}/', f'{TODIR}/'],
68 f"created directory {TODIR}\n"
69 f"cd{all_plus} ./\n"
70 f"cd{all_plus} bar/\n"
71 f"cd{all_plus} bar/baz/\n"
72 f">f{all_plus} bar/baz/rsync\n"
73 f"cd{all_plus} foo/\n"
74 f">f{all_plus} foo/config1\n"
75 f">f{all_plus} foo/config2\n"
76 f">f{all_plus} foo/extra\n"
77 f"cL{all_plus} foo/sym -> ../bar/baz/rsync\n")
78
79 # Touch dir times so subsequent itemize diffs don't pick up dir-time noise.
80 run_rsync('-a', '-f', '-! */', f'{FROMDIR}/', str(TODIR))
81
82 # Permute one file's content + mode; expect a content/mode itemize.
83 cp_p(SRCDIR / 'configure.ac', FROMDIR / 'foo' / 'config2')
84 os.chmod(FROMDIR / 'foo' / 'config2', 0o601)
85
86 checkdiff(['-iplrH', f'{FROMDIR}/', f'{TODIR}/'],
87 f">f..T.{dots} bar/baz/rsync\n"
88 f">f..T.{dots} foo/config1\n"
89 f">f.sTp{dots} foo/config2\n"
90 f"hf..T.{dots} foo/extra => foo/config1\n")
91
92 # Re-touch dirs, permute config2 again and replace the symlink target.
93 run_rsync('-a', '-f', '-! */', f'{FROMDIR}/', str(TODIR))
94 cp_p(SRCDIR / 'config.sub', FROMDIR / 'foo' / 'config2')
95 import time
96 time.sleep(1) # to provoke a directory mtime change below
97 (TODIR / 'foo' / 'sym').unlink()
98 old_umask = os.umask(0)
99 try:
100 os.symlink('../bar/baz', TODIR / 'foo' / 'sym')
101 finally:
102 os.umask(old_umask)
103 os.chmod(FROMDIR / 'foo' / 'config2', 0o600)
104 os.chmod(TODIR / 'bar' / 'baz' / 'rsync', 0o777)
105
106 checkdiff(['-iplrtc', f'{FROMDIR}/', f'{TODIR}/'],
107 f".f..tp{dots} bar/baz/rsync\n"
108 f".d..t.{dots} foo/\n"
109 f".f..t.{dots} foo/config1\n"
110 f">fcstp{dots} foo/config2\n"
111 f"cLc{T}.{dots} foo/sym -> ../bar/baz/rsync\n")
112
113 # Re-permute config2, leaving the others untouched; lack of -t is for
114 # the unchanged-hard-link stress test.
115 cp_p(SRCDIR / 'configure.ac', FROMDIR / 'foo' / 'config2')
116 os.chmod(FROMDIR / 'foo' / 'config2', 0o600)
117
118 checkdiff(['-vvplrH', f'{FROMDIR}/', f'{TODIR}/'],
119 "bar/baz/rsync is uptodate\n"
120 "foo/config1 is uptodate\n"
121 "foo/extra is uptodate\n"
122 "foo/sym is uptodate\n"
123 "foo/config2\n",
124 filter=v_filt)
125
126 # Touch a mode change on one dest file then run -ii to see "no change".
127 os.chmod(TODIR / 'bar' / 'baz' / 'rsync', 0o747)
128 run_rsync('-a', '-f', '-! */', f'{FROMDIR}/', str(TODIR))
129
130 checkdiff(['-ivvplrtH', f'{FROMDIR}/', f'{TODIR}/'],
131 f".d{allspace} ./\n"
132 f".d{allspace} bar/\n"
133 f".d{allspace} bar/baz/\n"
134 f".f...p{dots} bar/baz/rsync\n"
135 f".d{allspace} foo/\n"
136 f".f{allspace} foo/config1\n"
137 f">f..t.{dots} foo/config2\n"
138 f"hf{allspace} foo/extra\n"
139 f".L{allspace} foo/sym -> ../bar/baz/rsync\n",
140 filter=v_filt)
141
142 # Permute one perm and re-touch a file; expect just those two itemizes.
143 os.chmod(TODIR / 'foo' / 'config1', 0o757)
144 (TODIR / 'foo' / 'config2').touch()
145 checkdiff(['-vplrtH', f'{FROMDIR}/', f'{TODIR}/'],
146 "foo/config2\n",
147 filter=v_filt)
148
149 os.chmod(TODIR / 'foo' / 'config1', 0o757)
150 (TODIR / 'foo' / 'config2').touch()
151 checkdiff(['-iplrtH', f'{FROMDIR}/', f'{TODIR}/'],
152 f".f...p{dots} foo/config1\n"
153 f">f..t.{dots} foo/config2\n")
154
155
156 # --copy-dest variants.
157 checkdiff(['-ivvplrtH', '--copy-dest=../to', f'{FROMDIR}/', f'{to2dir}/'],
158 f"cd{allspace} ./\n"
159 f"cd{allspace} bar/\n"
160 f"cd{allspace} bar/baz/\n"
161 f"cf{allspace} bar/baz/rsync\n"
162 f"cd{allspace} foo/\n"
163 f"cf{allspace} foo/config1\n"
164 f"cf{allspace} foo/config2\n"
165 f"hf{allspace} foo/extra => foo/config1\n"
166 f"cL{allspace} foo/sym -> ../bar/baz/rsync\n",
167 filter=v_filt)
168
169 shutil.rmtree(to2dir, ignore_errors=True)
170 checkdiff(['-iplrtH', '--copy-dest=../to', f'{FROMDIR}/', f'{to2dir}/'],
171 f"created directory {to2dir}\n"
172 f"hf{allspace} foo/extra => foo/config1\n")
173
174 shutil.rmtree(to2dir, ignore_errors=True)
175 checkdiff(['-vvplrtH', f'--copy-dest={TODIR}', f'{FROMDIR}/', f'{to2dir}/'],
176 "./ is uptodate\n"
177 "bar/ is uptodate\n"
178 "bar/baz/ is uptodate\n"
179 "bar/baz/rsync is uptodate\n"
180 "foo/ is uptodate\n"
181 "foo/config1 is uptodate\n"
182 "foo/config2 is uptodate\n"
183 f"foo/sym is uptodate\n"
184 "foo/extra => foo/config1\n",
185 filter=v_filt)
186
187
188 # --link-dest variants.
189 shutil.rmtree(to2dir, ignore_errors=True)
190 checkdiff(['-ivvplrtH', f'--link-dest={TODIR}', f'{FROMDIR}/', f'{to2dir}/'],
191 f"cd{allspace} ./\n"
192 f"cd{allspace} bar/\n"
193 f"cd{allspace} bar/baz/\n"
194 f"hf{allspace} bar/baz/rsync\n"
195 f"cd{allspace} foo/\n"
196 f"hf{allspace} foo/config1\n"
197 f"hf{allspace} foo/config2\n"
198 f"hf{allspace} foo/extra => foo/config1\n"
199 f"{L}{allspace} foo/sym -> ../bar/baz/rsync\n",
200 filter=v_filt)
201
202 shutil.rmtree(to2dir, ignore_errors=True)
203 checkdiff(['-iplrtH', '--dry-run', '--link-dest=../to', f'{FROMDIR}/', f'{to2dir}/'],
204 f"created directory {to2dir}\n")
205
206 shutil.rmtree(to2dir, ignore_errors=True)
207 checkdiff(['-iplrtH', '--link-dest=../to', f'{FROMDIR}/', f'{to2dir}/'],
208 f"created directory {to2dir}\n")
209
210 shutil.rmtree(to2dir, ignore_errors=True)
211 checkdiff(['-vvplrtH', f'--link-dest={TODIR}', f'{FROMDIR}/', f'{to2dir}/'],
212 "./ is uptodate\n"
213 "bar/ is uptodate\n"
214 "bar/baz/ is uptodate\n"
215 "bar/baz/rsync is uptodate\n"
216 "foo/ is uptodate\n"
217 "foo/config1 is uptodate\n"
218 "foo/config2 is uptodate\n"
219 "foo/extra is uptodate\n"
220 f"foo/sym is uptodate\n",
221 filter=v_filt)
222
223
224 # --compare-dest variants.
225 shutil.rmtree(to2dir, ignore_errors=True)
226 checkdiff(['-ivvplrtH', f'--compare-dest={TODIR}', f'{FROMDIR}/', f'{to2dir}/'],
227 f"cd{allspace} ./\n"
228 f"cd{allspace} bar/\n"
229 f"cd{allspace} bar/baz/\n"
230 f".f{allspace} bar/baz/rsync\n"
231 f"cd{allspace} foo/\n"
232 f".f{allspace} foo/config1\n"
233 f".f{allspace} foo/config2\n"
234 f".f{allspace} foo/extra\n"
235 f".L{allspace} foo/sym -> ../bar/baz/rsync\n",
236 filter=v_filt)
237
238 shutil.rmtree(to2dir, ignore_errors=True)
239 checkdiff(['-iplrtH', f'--compare-dest={TODIR}', f'{FROMDIR}/', f'{to2dir}/'],
240 f"created directory {to2dir}\n")
241
242 shutil.rmtree(to2dir, ignore_errors=True)
243 checkdiff(['-vvplrtH', f'--compare-dest={TODIR}', f'{FROMDIR}/', f'{to2dir}/'],
244 "./ is uptodate\n"
245 "bar/ is uptodate\n"
246 "bar/baz/ is uptodate\n"
247 "bar/baz/rsync is uptodate\n"
248 "foo/ is uptodate\n"
249 "foo/config1 is uptodate\n"
250 "foo/config2 is uptodate\n"
251 "foo/extra is uptodate\n"
252 f"foo/sym is uptodate\n",
253 filter=v_filt)