-
Notifications
You must be signed in to change notification settings - Fork 299
Expand file tree
/
Copy pathconflicts.sh
More file actions
executable file
·525 lines (452 loc) · 11.7 KB
/
conflicts.sh
File metadata and controls
executable file
·525 lines (452 loc) · 11.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
#! /usr/bin/env atf-sh
. $(atf_get_srcdir)/test_environment.sh
tests_init \
more_complex_choice \
complex_conflicts \
fileexists_notinpkg \
find_conflicts \
find_conflicts_digest
# install foo
# foo depends on bar-1.0
# foo is upgraded to new dep on bar1-1.0 & bar is updated to 2.0
# bar1 and bar conflict with each other
complex_conflicts_body() {
echo "bar-1.0" > file1
atf_check -s exit:0 sh ${RESOURCEDIR}/test_subr.sh new_pkg bar bar 1.0 "${TMPDIR}"
cat << EOF >> bar.ucl
files: {
${TMPDIR}/file1: "",
}
EOF
atf_check \
-o empty \
-e empty \
-s exit:0 \
pkg create -M ./bar.ucl -o ./repo/
atf_check -s exit:0 sh ${RESOURCEDIR}/test_subr.sh new_pkg foo foo 1.0 "${TMPDIR}"
cat << EOF >> foo.ucl
deps: {
bar: {
origin: "bar",
version: "1.0"
}
}
EOF
atf_check \
-o empty \
-e empty \
-s exit:0 \
pkg create -M ./foo.ucl -o ./repo/
cat << EOF > pkg.conf
PKG_DBDIR=${TMPDIR}
REPOS_DIR=[]
repositories: {
local: { url : file://${TMPDIR}/repo }
}
EOF
atf_check \
-o inline:"Creating repository in ./repo: done\nPacking files for repository: done\n" \
-e empty \
-s exit:0 \
pkg -C ./pkg.conf repo ./repo
atf_check \
-o ignore \
-s exit:0 \
pkg -C ./pkg.conf update -f
atf_check \
-o match:"Installing foo-1\.0" \
-s exit:0 \
pkg -C ./pkg.conf install -y foo
# Upgrade bar
rm -fr repo
echo "bar-2.0" > file1
atf_check -s exit:0 sh ${RESOURCEDIR}/test_subr.sh new_pkg bar bar 2.0 "${TMPDIR}"
cat << EOF >> bar.ucl
files: {
${TMPDIR}/file1: "",
}
EOF
atf_check \
-o empty \
-e empty \
-s exit:0 \
pkg create -M ./bar.ucl -o ./repo/
# Create bar1-1.1
echo "bar-1.1" > file1
atf_check -s exit:0 sh ${RESOURCEDIR}/test_subr.sh new_pkg bar1 bar1 1.1 "${TMPDIR}"
cat << EOF >> bar1.ucl
files: {
${TMPDIR}/file1: "",
}
EOF
atf_check \
-o empty \
-e empty \
-s exit:0 \
pkg create -M ./bar1.ucl -o ./repo/
atf_check -s exit:0 sh ${RESOURCEDIR}/test_subr.sh new_pkg foo foo 1.0_1 "${TMPDIR}"
cat << EOF >> foo.ucl
deps: {
bar1: {
origin: "bar1",
version: "1.1"
}
}
EOF
atf_check \
-o empty \
-e empty \
-s exit:0 \
pkg create -M ./foo.ucl -o ./repo/
atf_check \
-o inline:"Creating repository in ./repo: done\nPacking files for repository: done\n" \
-e empty \
-s exit:0 \
pkg -C ./pkg.conf repo ./repo
atf_check \
-o ignore \
-e empty \
-s exit:0 \
pkg -C ./pkg.conf update -f
OUTPUT="Updating local repository catalogue...
local repository is up to date.
All repositories are up to date.
Checking for upgrades (2 candidates): done
Processing candidates (2 candidates): done
Checking integrity... done (2 conflicting)
- bar1-1.1 conflicts with bar-1.0 on ${TMPDIR}/file1
- bar1-1.1 conflicts with bar-2.0 on ${TMPDIR}/file1
Cannot solve problem using SAT solver, trying another plan
Checking integrity... done (0 conflicting)
The following 3 package(s) will be affected (of 0 checked):
Installed packages to be REMOVED:
bar: 1.0
New packages to be INSTALLED:
bar1: 1.1
Installed packages to be UPGRADED:
foo: 1.0 -> 1.0_1
Number of packages to be removed: 1
Number of packages to be installed: 1
Number of packages to be upgraded: 1
[1/3] Deinstalling bar-1.0...
[1/3] Deleting files for bar-1.0: done
[2/3] Installing bar1-1.1...
[2/3] Extracting bar1-1.1: done
[3/3] Upgrading foo from 1.0 to 1.0_1...
"
atf_check \
-o inline:"${OUTPUT}" \
-e empty \
-s exit:0 \
pkg -C ./pkg.conf upgrade -y
atf_check \
-o match:"foo-1.0_1" \
-o match:"bar1-1.1" \
-o not-match:"bar-2.0" \
-e empty \
-s exit:0 \
pkg info
}
# install foo
# foo depends on bar-1.0
# foo is upgraded to new dep on bar1-1.0 & bar is updated to 2.0
# other still depends on bar1-1.0
# bar1 and bar conflict with each other
more_complex_choice_body()
{
echo "bar-1.0" > file1
atf_check -s exit:0 sh ${RESOURCEDIR}/test_subr.sh new_pkg bar bar 1.0 "${TMPDIR}"
cat << EOF >> bar.ucl
files: {
${TMPDIR}/file1: "",
}
EOF
atf_check \
-o empty \
-e empty \
-s exit:0 \
pkg create -M ./bar.ucl -o ./repo/
atf_check -s exit:0 sh ${RESOURCEDIR}/test_subr.sh new_pkg foo foo 1.0 "${TMPDIR}"
cat << EOF >> foo.ucl
deps: {
bar: {
origin: "bar",
version: "1.0"
}
}
EOF
atf_check \
-o empty \
-e empty \
-s exit:0 \
pkg create -M ./foo.ucl -o ./repo/
atf_check -s exit:0 sh ${RESOURCEDIR}/test_subr.sh new_pkg other other 1.0 "${TMPDIR}"
cat << EOF >> other.ucl
deps: {
bar: {
origin: "bar",
version: "1.0"
}
}
EOF
atf_check pkg create -M ./other.ucl -o ./repo/
cat << EOF > pkg.conf
PKG_DBDIR=${TMPDIR}
REPOS_DIR=[]
repositories: {
local: { url : file://${TMPDIR}/repo }
}
EOF
atf_check \
-o inline:"Creating repository in ./repo: done\nPacking files for repository: done\n" \
-e empty \
-s exit:0 \
pkg -C ./pkg.conf repo ./repo
atf_check \
-o ignore \
-s exit:0 \
pkg -C ./pkg.conf update -f
atf_check \
-o match:"Installing foo-1\.0" \
-o match:"Installing other-1\.0" \
-s exit:0 \
pkg -C ./pkg.conf install -y foo other
# Upgrade bar
rm -fr repo
echo "bar-2.0" > file1
atf_check -s exit:0 sh ${RESOURCEDIR}/test_subr.sh new_pkg bar bar 2.0 "${TMPDIR}"
cat << EOF >> bar.ucl
files: {
${TMPDIR}/file1: "",
}
EOF
atf_check \
-o empty \
-e empty \
-s exit:0 \
pkg create -M ./bar.ucl -o ./repo/
# Create bar1-1.1
echo "bar-1.1" > file1
atf_check -s exit:0 sh ${RESOURCEDIR}/test_subr.sh new_pkg bar1 bar1 1.1 "${TMPDIR}"
cat << EOF >> bar1.ucl
files: {
${TMPDIR}/file1: "",
}
EOF
atf_check \
-o empty \
-e empty \
-s exit:0 \
pkg create -M ./bar1.ucl -o ./repo/
atf_check -s exit:0 sh ${RESOURCEDIR}/test_subr.sh new_pkg foo foo 1.0_1 "${TMPDIR}"
cat << EOF >> foo.ucl
deps: {
bar1: {
origin: "bar1",
version: "1.1"
}
}
EOF
atf_check \
-o empty \
-e empty \
-s exit:0 \
pkg create -M ./foo.ucl -o ./repo/
atf_check \
-o inline:"Creating repository in ./repo: done\nPacking files for repository: done\n" \
-e empty \
-s exit:0 \
pkg -C ./pkg.conf repo ./repo
atf_check \
-o ignore \
-e empty \
-s exit:0 \
pkg -C ./pkg.conf update -f
OUTPUT="Updating local repository catalogue...
local repository is up to date.
All repositories are up to date.
Checking for upgrades (2 candidates): done
Processing candidates (2 candidates): done
Checking integrity... done (2 conflicting)
- bar1-1.1 conflicts with bar-1.0 on ${TMPDIR}/file1
- bar1-1.1 conflicts with bar-2.0 on ${TMPDIR}/file1
Cannot solve problem using SAT solver, trying another plan
Checking integrity... done (0 conflicting)
The following 4 package(s) will be affected (of 0 checked):
Installed packages to be REMOVED:
bar: 1.0
other: 1.0
New packages to be INSTALLED:
bar1: 1.1
Installed packages to be UPGRADED:
foo: 1.0 -> 1.0_1
Number of packages to be removed: 2
Number of packages to be installed: 1
Number of packages to be upgraded: 1
[1/4] Deinstalling other-1.0...
[2/4] Deinstalling bar-1.0...
[2/4] Deleting files for bar-1.0: done
[3/4] Installing bar1-1.1...
[3/4] Extracting bar1-1.1: done
[4/4] Upgrading foo from 1.0 to 1.0_1...
"
atf_check \
-o inline:"${OUTPUT}" \
-e empty \
-s exit:0 \
pkg -C ./pkg.conf upgrade -y
atf_check \
-o match:"foo-1.0_1" \
-o match:"bar1-1.1" \
-o not-match:"other-1.0" \
-o not-match:"bar-2.0" \
-e empty \
-s exit:0 \
pkg info
}
fileexists_notinpkg_body()
{
mkdir -p ${TMPDIR}/target/${TMPDIR}
echo "entry" > ${TMPDIR}/target/${TMPDIR}/a
unset PKG_DBDIR
atf_check -s exit:0 sh ${RESOURCEDIR}/test_subr.sh new_pkg "test" "test" "2"
echo "entry 2" > a
echo "${TMPDIR}/a" > plist
atf_check \
pkg create -M test.ucl -p plist
pkg repo .
mkdir reposconf
echo "local: { url: file://${TMPDIR} }" > reposconf/local.conf
atf_check \
pkg -o REPOS_DIR=${TMPDIR}/reposconf -r ${TMPDIR}/target install -qy test
test -f ${TMPDIR}/target/${TMPDIR}/a.pkgsave || atf_fail "file not saved when it should have"
# Test the nominal situation just in case
rm -f ${TMPDIR}/target/${TMPDIR}/a.pkgsave
atf_check \
pkg -o REPOS_DIR=${TMPDIR}/reposconf -r ${TMPDIR}/target install -qyf test
test -f ${TMPDIR}/target/${TMPDIR}/a.pkgsave && atf_fail "file saved when it should not have"
# Test if both files are identical
atf_check \
pkg -o REPOS_DIR=${TMPDIR}/reposconf -r ${TMPDIR}/target delete -qyf test
echo "entry 2" > ${TMPDIR}/target/${TMPDIR}/a
atf_check \
pkg -o REPOS_DIR=${TMPDIR}/reposconf -r ${TMPDIR}/target install -qyf test
test -f ${TMPDIR}/target/${TMPDIR}/a.pkgsave && atf_fail "file saved when it should not have"
return 0
}
find_conflicts_body() {
touch a
atf_check -s exit:0 sh ${RESOURCEDIR}/test_subr.sh new_manifest test 1 /
cat << EOF >> +MANIFEST
files: {
${TMPDIR}/a: "",
}
EOF
atf_check \
-o match:".*Installing.*\.\.\.$" \
-e empty \
-s exit:0 \
pkg register -M +MANIFEST
atf_check -s exit:0 sh ${RESOURCEDIR}/test_subr.sh new_manifest test2 1 /
cat << EOF >> +MANIFEST
files: {
${TMPDIR}/a: "",
}
EOF
atf_check \
-o empty \
-e empty \
-s exit:0 \
pkg create -M +MANIFEST -o .
atf_check \
-o inline:"Creating repository in .: done\nPacking files for repository: done\n" \
-e empty \
-s exit:0 \
pkg repo .
mkdir reposconf
cat << EOF >> reposconf/repo.conf
local: {
url: file:///${TMPDIR},
enabled: true
}
EOF
OUTPUT="Updating local repository catalogue...
${JAILED}Fetching meta.conf: done
${JAILED}Fetching data.pkg: done
Processing entries: done
local repository update completed. 1 packages processed.
All repositories are up to date.
Updating database digests format: done
Checking integrity... done (1 conflicting)
- test2-1 conflicts with test-1 on ${TMPDIR}/a
Checking integrity... done (0 conflicting)
The following 2 package(s) will be affected (of 0 checked):
Installed packages to be REMOVED:
test: 1
New packages to be INSTALLED:
test2: 1
Number of packages to be removed: 1
Number of packages to be installed: 1
${JAILED}[1/2] Deinstalling test-1...
${JAILED}[1/2] Deleting files for test-1: done
${JAILED}[2/2] Installing test2-1...
${JAILED}[2/2] Extracting test2-1: done
"
atf_check \
-o inline:"${OUTPUT}" \
-s exit:0 \
pkg -o REPOS_DIR="${TMPDIR}/reposconf" -o PKG_CACHEDIR="${TMPDIR}" install -y test2-1
}
digest_pkg() {
printf "%s\n" "$1" > a
atf_check -s exit:0 sh ${RESOURCEDIR}/test_subr.sh new_manifest test 1 /
cat << EOF >> +MANIFEST
files: {
${TMPDIR}/a: "",
}
EOF
atf_check \
-o empty \
-e empty \
-s exit:0 \
pkg create -M +MANIFEST -o .
atf_check \
-o inline:"Creating repository in .: done\nPacking files for repository: done\n" \
-e empty \
-s exit:0 \
pkg repo .
rm -rf reposconf
mkdir reposconf
cat << EOF >> reposconf/repo.conf
local: {
url: file:///${TMPDIR},
enabled: true
}
EOF
}
find_conflicts_digest_body() {
digest_pkg a
cp -p test-1.pkg /tmp/t1a.pkg
digest_pkg_a=$(pkg -o REPOS_DIR="${TMPDIR}/reposconf" -o PKG_CACHEDIR="${TMPDIR}" query -F test-1.pkg %X)
# rquery_pkg_a=$(pkg -o REPOS_DIR="${TMPDIR}/reposconf" -o PKG_CACHEDIR="${TMPDIR}" rquery %X test)
atf_check \
-o ignore \
-e ignore \
-s exit:0 \
pkg -o REPOS_DIR="${TMPDIR}/reposconf" -o PKG_CACHEDIR="${TMPDIR}" install -y test-1
query_pkg_a=$(pkg -o REPOS_DIR="${TMPDIR}/reposconf" -o PKG_CACHEDIR="${TMPDIR}" query %X test)
# Same package, different contents, different checksum
digest_pkg b
cp -p test-1.pkg /tmp/t1b.pkg
digest_pkg_b=$(pkg -o REPOS_DIR="${TMPDIR}/reposconf" -o PKG_CACHEDIR="${TMPDIR}" query -F test-1.pkg %X)
# rquery_pkg_b=$(pkg -o REPOS_DIR="${TMPDIR}/reposconf" -o PKG_CACHEDIR="${TMPDIR}" rquery %X test)
atf_check \
-o ignore \
-e ignore \
-s exit:0 \
pkg -o REPOS_DIR="${TMPDIR}/reposconf" -o PKG_CACHEDIR="${TMPDIR}" upgrade -y
query_pkg_b=$(pkg -o REPOS_DIR="${TMPDIR}/reposconf" -o PKG_CACHEDIR="${TMPDIR}" query %X test)
atf_check_equal "${digest_pkg_a}" "${query_pkg_a}"
atf_check_equal "${digest_pkg_b}" "${query_pkg_b}"
atf_check_not_equal "${query_pkg_a}" "${query_pkg_b}"
}