]> git.saurik.com Git - apt.git/blob - test/integration/test-pdiff-usage
rred: truncate result file before writing to it
[apt.git] / test / integration / test-pdiff-usage
1 #!/bin/sh
2 set -e
3
4 TESTDIR="$(readlink -f "$(dirname "$0")")"
5 . "$TESTDIR/framework"
6
7 setupenvironment
8 configarchitecture 'i386'
9 LOWCOSTEXT='lz4'
10
11 buildaptarchive
12 setupflataptarchive
13 changetowebserver
14
15 cat >rootdir/etc/apt/apt.conf.d/contents.conf <<EOF
16 Acquire::IndexTargets::deb::Contents {
17 MetaKey "\$(COMPONENT)/Contents-\$(ARCHITECTURE)";
18 ShortDescription "Contents";
19 Description "\$(RELEASE)/\$(COMPONENT) \$(ARCHITECTURE) Contents";
20 MetaKey "\$(COMPONENT)/Contents-\$(ARCHITECTURE)";
21 flatMetaKey "Contents-\$(ARCHITECTURE)";
22 flatDescription "\$(RELEASE) \$(ARCHITECTURE) Contents";
23 };
24 EOF
25
26 PKGFILE="${TESTDIR}/$(echo "$(basename $0)" | sed 's#^test-#Packages-#')"
27 echo 'contents for stuff' > aptarchive/Contents-i386
28 compressfile aptarchive/Contents-i386
29 echo 'hacked' > aptarchive/hacked-i386
30 compressfile aptarchive/hacked-i386
31
32 wasmergeused() {
33 if echo "$*" | grep -q -- '-o test::cannot-use-pdiff=1'; then
34 find rootdir/var/lib/apt/lists/partial -name '*-patched*' -delete
35 fi
36
37 testsuccess apt update "$@"
38
39 msgtest 'No intermediate patch files' 'still exist'
40 local EDS="$(find rootdir/var/lib/apt/lists -name '*.ed' -o -name '*.ed.*')"
41 if [ -z "$EDS" ]; then
42 msgpass
43 else
44 echo
45 echo "$EDS"
46 msgfail
47 fi
48
49 if echo "$*" | grep -q -- '-o test::cannot-use-pdiff=1'; then
50 msgtest 'Check if pdiff was' 'not used'
51 cp -a rootdir/tmp/testsuccess.output rootdir/tmp/aptupdate.output
52 testsuccess --nomsg grep "diff/Index with Message: Couldn't parse pdiff index" rootdir/tmp/aptupdate.output
53 return;
54 fi
55
56 msgtest 'Check if the right pdiff merger was used'
57 if grep -q '^pkgAcqIndexMergeDiffs::Done(): rred' rootdir/tmp/testsuccess.output; then
58 if echo "$*" | grep -q -- '-o Acquire::PDiffs::Merge=1'; then
59 msgpass
60 else
61 msgfail "Merge shouldn't have been used, but was"
62 fi
63 elif echo "$*" | grep -q -- '-o Acquire::PDiffs::Merge=1'; then
64 msgfail "Merge should have been used, but wasn't"
65 else
66 msgpass
67 fi
68 }
69
70 testrun() {
71 configcompression '.' 'xz'
72 msgmsg "Testcase: setup the base with: $*"
73 find aptarchive -name 'Packages*' -type f -delete
74 cp "${PKGFILE}" aptarchive/Packages
75 compressfile 'aptarchive/Packages'
76 generatereleasefiles
77 signreleasefiles
78 rm -rf aptarchive/Packages.diff rootdir/var/lib/apt/lists rootdir/var/lib/apt/lists-bak
79 testsuccess aptget update "$@"
80 cp -a rootdir/var/lib/apt/lists rootdir/var/lib/apt/lists-bak
81 testnopackage newstuff
82 testsuccessequal "$(cat "${PKGFILE}")
83 " aptcache show apt oldstuff
84 configcompression '.' 'gz'
85
86 # see if the code deals properly with leftover partial files
87 partialleftovers
88
89 msgmsg "Testcase: apply with one patch: $*"
90 find aptarchive -name 'Packages*' -type f -delete
91 cp "${PKGFILE}-new" aptarchive/Packages
92 compressfile 'aptarchive/Packages'
93 mkdir -p aptarchive/Packages.diff
94 PATCHFILE="aptarchive/Packages.diff/$(date +%Y-%m-%d-%H%M.%S)"
95 diff -e "${PKGFILE}" "${PKGFILE}-new" > "${PATCHFILE}" || true
96 cat "$PATCHFILE" | gzip > "${PATCHFILE}.gz"
97 PATCHINDEX='aptarchive/Packages.diff/Index'
98 echo "SHA256-Current: $(sha256sum "${PKGFILE}-new" | cut -d' ' -f 1) $(stat -c%s "${PKGFILE}-new")
99 SHA256-History:
100 01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b 33053002 2010-08-18-2013.28
101 $(sha256sum "$PKGFILE" | cut -d' ' -f 1) $(stat -c%s "$PKGFILE") $(basename "$PATCHFILE")
102 SHA256-Patches:
103 e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 19722 2010-08-18-2013.28
104 $(sha256sum "$PATCHFILE" | cut -d' ' -f 1) $(stat -c%s "$PATCHFILE") $(basename "$PATCHFILE")
105 SHA256-Download:
106 d2a1b33187ed2d248eeae3b1223ea71791ea35f2138a713ed371332a6421f467 197 2010-08-18-2013.28.gz
107 $(sha256sum "${PATCHFILE}.gz" | cut -d' ' -f 1) $(stat -c%s "${PATCHFILE}.gz") $(basename "${PATCHFILE}.gz")" > "$PATCHINDEX"
108
109 generatereleasefiles '+1hour'
110 signreleasefiles
111 find aptarchive -name 'Packages*' -type f -delete
112 wasmergeused "$@"
113 testnopackage oldstuff
114 testsuccessequal "$(cat "${PKGFILE}-new")
115 " aptcache show apt newstuff
116
117 msgmsg "Testcase: SHA1-only patches are not used: $*"
118 find aptarchive -name 'Packages*' -type f -delete
119 cp "${PKGFILE}-new" aptarchive/Packages
120 compressfile 'aptarchive/Packages'
121 mkdir -p aptarchive/Packages.diff
122 PATCHFILE="aptarchive/Packages.diff/$(date +%Y-%m-%d-%H%M.%S)"
123 diff -e "${PKGFILE}" "${PKGFILE}-new" > "${PATCHFILE}" || true
124 cat "$PATCHFILE" | gzip > "${PATCHFILE}.gz"
125 PATCHINDEX='aptarchive/Packages.diff/Index'
126 echo "SHA1-Current: $(sha1sum "${PKGFILE}-new" | cut -d' ' -f 1) $(stat -c%s "${PKGFILE}-new")
127 SHA1-History:
128 9f4148e06d7faa37062994ff10d0c842d7017513 33053002 2010-08-18-2013.28
129 $(sha1sum "$PKGFILE" | cut -d' ' -f 1) $(stat -c%s "$PKGFILE") $(basename "$PATCHFILE")
130 SHA1-Patches:
131 7651fc0ac57cd83d41c63195a9342e2db5650257 19722 2010-08-18-2013.28
132 $(sha1sum "$PATCHFILE" | cut -d' ' -f 1) $(stat -c%s "$PATCHFILE") $(basename "$PATCHFILE")
133 SHA1-Download:
134 2365ac0ac57cde3d43c63145e8251a3bd5410213 197 2010-08-18-2013.28.gz
135 $(sha1sum "${PATCHFILE}.gz" | cut -d' ' -f 1) $(stat -c%s "${PATCHFILE}.gz") $(basename "${PATCHFILE}.gz")" > "$PATCHINDEX"
136 generatereleasefiles '+1hour'
137 signreleasefiles
138 rm -rf rootdir/var/lib/apt/lists
139 cp -a rootdir/var/lib/apt/lists-bak rootdir/var/lib/apt/lists
140 wasmergeused "$@" -o test::cannot-use-pdiff=1
141 testnopackage oldstuff
142 testsuccessequal "$(cat "${PKGFILE}-new")
143 " aptcache show apt newstuff
144
145 msgmsg "Testcase: no download-hashes patches are not used: $*"
146 find aptarchive -name 'Packages*' -type f -delete
147 cp "${PKGFILE}-new" aptarchive/Packages
148 compressfile 'aptarchive/Packages'
149 mkdir -p aptarchive/Packages.diff
150 PATCHFILE="aptarchive/Packages.diff/$(date +%Y-%m-%d-%H%M.%S)"
151 diff -e "${PKGFILE}" "${PKGFILE}-new" > "${PATCHFILE}" || true
152 cat "$PATCHFILE" | gzip > "${PATCHFILE}.gz"
153 PATCHINDEX='aptarchive/Packages.diff/Index'
154 echo "SHA256-Current: $(sha256sum "${PKGFILE}-new" | cut -d' ' -f 1) $(stat -c%s "${PKGFILE}-new")
155 SHA256-History:
156 01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b 33053002 2010-08-18-2013.28
157 $(sha256sum "$PKGFILE" | cut -d' ' -f 1) $(stat -c%s "$PKGFILE") $(basename "$PATCHFILE")
158 SHA256-Patches:
159 e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 19722 2010-08-18-2013.28
160 $(sha256sum "$PATCHFILE" | cut -d' ' -f 1) $(stat -c%s "$PATCHFILE") $(basename "$PATCHFILE")" > "$PATCHINDEX"
161 generatereleasefiles '+1hour'
162 signreleasefiles
163 rm -rf rootdir/var/lib/apt/lists
164 cp -a rootdir/var/lib/apt/lists-bak rootdir/var/lib/apt/lists
165 wasmergeused "$@" -o test::cannot-use-pdiff=1
166 testnopackage oldstuff
167 testsuccessequal "$(cat "${PKGFILE}-new")
168 " aptcache show apt newstuff
169
170 msgmsg "Testcase: apply with two patches: $*"
171 cp "${PKGFILE}-new" aptarchive/Packages
172 echo '
173 Package: futurestuff
174 Version: 1.0
175 Architecture: i386
176 Maintainer: Joe Sixpack <joe@example.org>
177 Installed-Size: 202
178 Filename: pool/futurestuff_1.0_i386.deb
179 Size: 202200
180 SHA256: b46fd154615edaae5ba33c56a5cc0e7deaef23e2da3e4f129727fd660f28f050
181 Description: some cool and shiny future stuff
182 This package will appear in the next next mirror update
183 Description-md5: d5f89fbbc2ce34c455dfee9b67d82b6b' >> aptarchive/Packages
184
185 compressfile 'aptarchive/Packages'
186 PATCHFILE2="aptarchive/Packages.diff/$(date -d 'now + 1hour' '+%Y-%m-%d-%H%M.%S')"
187 diff -e "${PKGFILE}-new" aptarchive/Packages > "${PATCHFILE2}" || true
188 cat "$PATCHFILE2" | gzip > "${PATCHFILE2}.gz"
189 echo "SHA256-Current: $(sha256sum aptarchive/Packages | cut -d' ' -f 1) $(stat -c%s aptarchive/Packages)
190 SHA256-History:
191 01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b 33053002 2010-08-18-2013.28
192 $(sha256sum "$PKGFILE" | cut -d' ' -f 1) $(stat -c%s "$PKGFILE") $(basename "$PATCHFILE")
193 $(sha256sum "${PKGFILE}-new" | cut -d' ' -f 1) $(stat -c%s "${PKGFILE}-new") $(basename "${PATCHFILE2}")
194 SHA256-Patches:
195 e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 19722 2010-08-18-2013.28
196 $(sha256sum "$PATCHFILE" | cut -d' ' -f 1) $(stat -c%s "$PATCHFILE") $(basename "$PATCHFILE")
197 $(sha256sum "${PATCHFILE2}" | cut -d' ' -f 1) $(stat -c%s "${PATCHFILE2}") $(basename "${PATCHFILE2}")
198 SHA256-Download:
199 d2a1b33187ed2d248eeae3b1223ea71791ea35f2138a713ed371332a6421f467 197 2010-08-18-2013.28.gz
200 $(sha256sum "${PATCHFILE}.gz" | cut -d' ' -f 1) $(stat -c%s "${PATCHFILE}.gz") $(basename "${PATCHFILE}.gz")
201 $(sha256sum "${PATCHFILE2}.gz" | cut -d' ' -f 1) $(stat -c%s "${PATCHFILE2}.gz") $(basename "${PATCHFILE2}.gz")" > "$PATCHINDEX"
202
203 generatereleasefiles '+2hour'
204 signreleasefiles
205 cp -a aptarchive/Packages Packages-future
206 find aptarchive -name 'Packages*' -type f -delete
207 rm -rf rootdir/var/lib/apt/lists
208 cp -a rootdir/var/lib/apt/lists-bak rootdir/var/lib/apt/lists
209 wasmergeused "$@"
210 testnopackage oldstuff
211 testsuccessequal "$(cat Packages-future)
212 " aptcache show apt newstuff futurestuff
213
214 # we reuse the archive state of the previous test here
215 msgmsg "Testcase: pdiff handling is stopped if transaction fails $*"
216 rm -rf rootdir/var/lib/apt/lists
217 cp -a rootdir/var/lib/apt/lists-bak rootdir/var/lib/apt/lists
218 cp Packages-future aptarchive/Packages
219 rm -f rootdir/var/lib/apt/lists/*_Contents-*
220 webserverconfig 'aptwebserver::overwrite::.*Contents-.*::filename' '/hacked-i386.gz'
221 testfailure apt update "$@" -o Debug::pkgAcquire::Worker=1 -o Debug::Acquire::http=1
222 webserverconfig 'aptwebserver::overwrite::.*Contents-.*::filename' '/Contents-i386.gz'
223 cp rootdir/tmp/testfailure.output patchdownload.output
224 testfailure grep 'rred:600' patchdownload.output
225 testnopackage newstuff futurestuff
226 testsuccessequal "$(cat "${PKGFILE}")
227 " aptcache show apt oldstuff
228
229 # we reuse the archive state of the previous test here
230 msgmsg "Testcase: downloading a patch fails, but successful fallback: $*"
231 rm -rf rootdir/var/lib/apt/lists
232 cp -a rootdir/var/lib/apt/lists-bak rootdir/var/lib/apt/lists
233 cp Packages-future aptarchive/Packages
234 rm "${PATCHFILE}.gz"
235 testsuccess apt update "$@"
236 cp rootdir/tmp/testsuccess.output patchdownload.output
237 testsuccess grep '^Falling back to normal index file acquire' patchdownload.output
238 testnopackage oldstuff
239 testsuccessequal "$(cat Packages-future)
240 " aptcache show apt newstuff futurestuff
241
242 msgmsg "Testcase: patch applying fails, but successful fallback: $*"
243 rm -rf rootdir/var/lib/apt/lists
244 cp -a rootdir/var/lib/apt/lists-bak rootdir/var/lib/apt/lists
245 cp "${PKGFILE}-new" aptarchive/Packages
246 compressfile 'aptarchive/Packages'
247 mkdir -p aptarchive/Packages.diff
248 PATCHFILE="aptarchive/Packages.diff/$(date +%Y-%m-%d-%H%M.%S)"
249 diff -e "${PKGFILE}" "${PKGFILE}-new" > "${PATCHFILE}" || true
250 cat "$PATCHFILE" | gzip > "${PATCHFILE}.gz"
251 PATCHINDEX='aptarchive/Packages.diff/Index'
252 echo "SHA256-Current: $(sha256sum "${PKGFILE}-new" | cut -d' ' -f 1) $(stat -c%s "${PKGFILE}-new")
253 SHA256-History:
254 01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b 33053002 2010-08-18-2013.28
255 $(sha256sum "$PKGFILE" | cut -d' ' -f 1) $(stat -c%s "$PKGFILE") $(basename "$PATCHFILE")
256 SHA256-Patches:
257 e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 19722 2010-08-18-2013.28
258 $(sha256sum "$PATCHFILE" | cut -d' ' -f 1) $(stat -c%s "$PATCHFILE") $(basename "$PATCHFILE")
259 SHA256-Download:
260 d2a1b33187ed2d248eeae3b1223ea71791ea35f2138a713ed371332a6421f467 197 2010-08-18-2013.28.gz
261 $(sha256sum "${PATCHFILE}.gz" | cut -d' ' -f 1) $(stat -c%s "${PATCHFILE}.gz") $(basename "${PATCHFILE}.gz")" > "$PATCHINDEX"
262 # needs to look like a valid command, otherwise the parser will fail before hashes are checked
263 echo '1d' > "$PATCHFILE"
264 cat "$PATCHFILE" | gzip > "${PATCHFILE}.gz"
265 generatereleasefiles '+1hour'
266 signreleasefiles
267 testsuccess apt update "$@"
268 cp -f rootdir/tmp/testsuccess.output rootdir/tmp/aptupdate.output
269 testsuccess grep 'Hash Sum mismatch' rootdir/tmp/aptupdate.output
270 testnopackage oldstuff
271 testsuccessequal "$(cat "${PKGFILE}-new")
272 " aptcache show apt newstuff
273
274 msgmsg "Testcase: pdiff patch bigger than index itself: $*"
275 rm -rf rootdir/var/lib/apt/lists
276 cp -a rootdir/var/lib/apt/lists-bak rootdir/var/lib/apt/lists
277 # the general testcode checks for leftovers in partial, but as this file
278 # is never touched in this test as it exits earlier its not a leftover…
279 rm -f rootdir/var/lib/apt/lists/partial/localhost:${APTHTTPPORT}_Packages
280 cp "${PKGFILE}-new" aptarchive/Packages
281 compressfile 'aptarchive/Packages'
282 mkdir -p aptarchive/Packages.diff
283 PATCHFILE="aptarchive/Packages.diff/$(date +%Y-%m-%d-%H%M.%S)"
284 diff -e "${PKGFILE}" "${PKGFILE}-new" > "${PATCHFILE}" || true
285 cat "$PATCHFILE" | gzip > "${PATCHFILE}.gz"
286 PATCHINDEX='aptarchive/Packages.diff/Index'
287 echo "SHA256-Current: $(sha256sum "${PKGFILE}-new" | cut -d' ' -f 1) $(stat -c%s "${PKGFILE}-new")
288 SHA256-History:
289 01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b 33053002 2010-08-18-2013.28
290 $(sha256sum "$PKGFILE" | cut -d' ' -f 1) $(stat -c%s "$PKGFILE") $(basename "$PATCHFILE")
291 SHA256-Patches:
292 e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 19722 2010-08-18-2013.28
293 $(sha256sum "$PATCHFILE" | cut -d' ' -f 1) $(stat -c%s "$PATCHFILE") $(basename "$PATCHFILE")
294 SHA256-Download:
295 d2a1b33187ed2d248eeae3b1223ea71791ea35f2138a713ed371332a6421f467 197 2010-08-18-2013.28.gz
296 $(sha256sum "${PATCHFILE}.gz" | cut -d' ' -f 1) $(stat -c%s "${PATCHFILE}.gz")000 $(basename "${PATCHFILE}.gz")" > "$PATCHINDEX"
297 generatereleasefiles '+1hour'
298 signreleasefiles
299 wasmergeused "$@" -o test::cannot-use-pdiff=1
300 testsuccess grep 'bytes (Limit is' rootdir/tmp/aptupdate.output
301 testnopackage oldstuff
302 testsuccessequal "$(cat "${PKGFILE}-new")
303 " aptcache show apt newstuff
304 }
305 echo 'Debug::pkgAcquire::Diffs "true";
306 Debug::Acquire::Transaction "true";
307 Debug::pkgAcquire::rred "true";' > rootdir/etc/apt/apt.conf.d/rreddebug.conf
308
309 testcase() {
310 testrun -o Acquire::PDiffs::Merge=0 -o APT::Get::List-Cleanup=1 "$@"
311 testrun -o Acquire::PDiffs::Merge=1 -o APT::Get::List-Cleanup=1 "$@"
312 testrun -o Acquire::PDiffs::Merge=0 -o APT::Get::List-Cleanup=0 "$@"
313 testrun -o Acquire::PDiffs::Merge=1 -o APT::Get::List-Cleanup=0 "$@"
314 }
315 generatepartialleftovers() {
316 for f in "$@"; do
317 cat "${PKGFILE}" "${PKGFILE}" > "rootdir/var/lib/apt/lists-bak/partial/localhost:${APTHTTPPORT}_${f}"
318 printf '\n\nInvalid\nStanza: yes\n\n' >> "rootdir/var/lib/apt/lists-bak/partial/localhost:${APTHTTPPORT}_${f}"
319 done
320 }
321
322 partialleftovers() { generatepartialleftovers 'Packages' 'Packages-patched'; }
323 aptautotest_apt_update() { aptautotest_aptget_update "$@"; testsuccess test -e "rootdir/var/lib/apt/lists/localhost:${APTHTTPPORT}_Packages"; }
324 testcase -o Acquire::IndexTargets::deb::Packages::KeepCompressed=false
325 partialleftovers() { generatepartialleftovers "Packages.${LOWCOSTEXT}" "Packages-patched.${LOWCOSTEXT}"; }
326 aptautotest_apt_update() { aptautotest_aptget_update "$@"; testsuccess test -e "rootdir/var/lib/apt/lists/localhost:${APTHTTPPORT}_Packages.$LOWCOSTEXT"; }
327 testcase -o Acquire::IndexTargets::deb::Packages::KeepCompressed=true
328
329
330 partialleftovers() { generatepartialleftovers "redirectme_Packages.${LOWCOSTEXT}" "redirectme_Packages-patched.${LOWCOSTEXT}"; }
331 webserverconfig 'aptwebserver::redirect::replace::/redirectme/' "http://0.0.0.0:${APTHTTPPORT}/"
332 rewritesourceslist "http://localhost:${APTHTTPPORT}/redirectme"
333 aptautotest_apt_update() {
334 aptautotest_aptget_update "$@"
335 testsuccess test -e "rootdir/var/lib/apt/lists/localhost:${APTHTTPPORT}_redirectme_Packages.$LOWCOSTEXT"
336 testempty find rootdir/var/lib/apt/lists -type f \! \( -name lock -o -name '*_redirectme_*' \)
337 }
338 testcase -o Acquire::IndexTargets::deb::Packages::KeepCompressed=true