3 # Copyright (c) 2010 Hudson River Trading LLC
4 # Written by: John H. Baldwin <jhb@FreeBSD.org>
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions
10 # 1. Redistributions of source code must retain the above copyright
11 # notice, this list of conditions and the following disclaimer.
12 # 2. Redistributions in binary form must reproduce the above copyright
13 # notice, this list of conditions and the following disclaimer in the
14 # documentation and/or other materials provided with the distribution.
16 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 # Various regression tests to test the -A flag to the 'update' command.
36 echo "Usage: always.sh [-s script] [-w workdir]"
40 # Allow the user to specify an alternate work directory or script.
42 while getopts "s:w:" option; do
61 CONFLICTS=$WORKDIR/conflicts
66 # The various states of the comparison of a file between two trees.
67 states="equal first second difftype difflinks difffiles"
69 # These tests deal with ignoring certain patterns of files. We run
70 # the test multiple times forcing the install of different patterns.
75 rm -rf $OLD $NEW $TEST $CONFLICTS
80 mkdir -p $OLD/$i/$j/$k $NEW/$i/$j/$k \
86 # What follows are the various warning/conflict cases from the
87 # larger regression tests. These results of many of these
88 # tests should be changed when installation is forced. The
89 # cases when these updates should still fail even when forced
90 # are: 1) it should not force the removal of a modified file
91 # and 2) it should not remove a subdirectory that contains a
92 # modified or added file.
94 # /first/difftype/second: File with different local type
95 # removed. Should generate a warning.
96 mkfifo $OLD/first/difftype/second/fifo
97 mkdir $TEST/first/difftype/second/fifo
99 # /first/difflinks/second: Modified link removed. Should
100 # generate a warning.
101 ln -s "old link" $OLD/first/difflinks/second/link
102 ln -s "test link" $TEST/first/difflinks/second/link
104 # /first/difffiles/second: Modified file removed. Should
105 # generate a warning.
106 echo "foo" > $OLD/first/difffiles/second/file
107 echo "bar" > $TEST/first/difffiles/second/file
109 # /second/second/difftype: Newly added file conflicts with
110 # existing file in test tree of a different type. Should
111 # generate a warning.
112 mkdir $NEW/second/second/difftype/dir
113 mkfifo $TEST/second/second/difftype/dir
115 # /second/second/difflinks: Newly added link conflicts with
116 # existing link in test tree. Should generate a warning.
117 ln -s "new link" $NEW/second/second/difflinks/link
118 ln -s "test link" $TEST/second/second/difflinks/link
120 # /second/second/difffiles: Newly added file conflicts with
121 # existing file in test tree. Should generate a warning.
122 echo "new" > $NEW/second/second/difffiles/file
123 echo "test" > $TEST/second/second/difffiles/file
125 # /difftype/first/first: A removed file has changed type.
126 # This should generate a warning.
127 mkfifo $OLD/difftype/first/first/fifo
128 mkdir $NEW/difftype/first/first/fifo
130 # /difftype/difftype/difftype: All three files (old, new, and
131 # test) are different types from each other. This should
132 # generate a warning.
133 mkfifo $OLD/difftype/difftype/difftype/one
134 mkdir $NEW/difftype/difftype/difftype/one
135 echo "foo" > $TEST/difftype/difftype/difftype/one
136 mkdir $OLD/difftype/difftype/difftype/two
137 echo "baz" > $NEW/difftype/difftype/difftype/two
138 ln -s "bar" $TEST/difftype/difftype/difftype/two
140 # /difftype/difftype/difflinks: A file has changed from a
141 # non-link to a link in both the new and test trees, but the
142 # target of the new and test links differ. This should
143 # generate a new link conflict.
144 mkfifo $OLD/difftype/difftype/difflinks/link
145 ln -s "new" $NEW/difftype/difftype/difflinks/link
146 ln -s "test" $TEST/difftype/difftype/difflinks/link
148 # /difftype/difftype/difffile: A file has changed from a
149 # non-regular file to a regular file in both the new and test
150 # trees, but the contents in the new and test files differ.
151 # This should generate a new file conflict.
152 ln -s "old" $OLD/difftype/difftype/difffiles/file
153 echo "foo" > $NEW/difftype/difftype/difffiles/file
154 echo "bar" > $TEST/difftype/difftype/difffiles/file
156 # /difflinks/first/first: A modified link is missing in the
157 # test tree. This should generate a warning.
158 ln -s "old" $OLD/difflinks/first/first/link
159 ln -s "new" $NEW/difflinks/first/first/link
161 # /difflinks/difftype/difftype: An updated link has been
162 # changed to a different file type in the test tree. This
163 # should generate a warning.
164 ln -s "old" $OLD/difflinks/difftype/difftype/link
165 ln -s "new" $NEW/difflinks/difftype/difftype/link
166 echo "test" > $TEST/difflinks/difftype/difftype/link
168 # /difflinks/difflinks/difflinks: An updated link has been
169 # modified in the test tree and doesn't match either the old
170 # or new links. This should generate a warning.
171 ln -s "old" $OLD/difflinks/difflinks/difflinks/link
172 ln -s "new" $NEW/difflinks/difflinks/difflinks/link
173 ln -s "test" $TEST/difflinks/difflinks/difflinks/link
175 # /difffiles/first/first: A removed file has been changed in
176 # the new tree. This should generate a warning.
177 echo "foo" > $OLD/difffiles/first/first/file
178 echo "bar" > $NEW/difffiles/first/first/file
180 # /difffiles/difftype/difftype: An updated regular file has
181 # been changed to a different file type in the test tree.
182 # This should generate a warning.
183 echo "old" > $OLD/difffiles/difftype/difftype/file
184 echo "new" > $NEW/difffiles/difftype/difftype/file
185 mkfifo $TEST/difffiles/difftype/difftype/file
187 # /difffiles/difffiles/difffiles: A modified regular file was
188 # updated in the new tree. The changes should be merged into
189 # to the new file if possible. If the merge fails, a conflict
190 # should be generated. For this test we just include the
192 cat > $OLD/difffiles/difffiles/difffiles/conflict <<EOF
195 cat > $NEW/difffiles/difffiles/difffiles/conflict <<EOF
198 cat > $TEST/difffiles/difffiles/difffiles/conflict <<EOF
202 ## Tests for adding directories
203 mkdir -p $OLD/adddir $NEW/adddir $TEST/adddir
205 # /adddir/conflict: Add a new file in a directory that already
206 # exists as a file. This should generate two warnings.
207 mkdir $NEW/adddir/conflict
208 touch $NEW/adddir/conflict/newfile
209 touch $TEST/adddir/conflict
211 ## Tests for removing directories
212 mkdir -p $OLD/rmdir $NEW/rmdir $TEST/rmdir
214 # /rmdir/extra: Do not remove a directory with an extra local file.
215 # This should generate a warning.
216 for i in $OLD $TEST; do
219 echo "foo" > $TEST/rmdir/extra/localfile.txt
221 # /rmdir/conflict: Do not remove a directory with a conflicted
222 # remove file. This should generate a warning.
223 for i in $OLD $TEST; do
224 mkdir $i/rmdir/conflict
226 mkfifo $OLD/rmdir/conflict/difftype
227 mkdir $TEST/rmdir/conflict/difftype
229 ## Tests for converting files to directories and vice versa
230 for i in $OLD $NEW $TEST; do
231 for j in already old fromdir todir; do
232 mkdir -p $i/dirchange/$j
236 # /dirchange/fromdir/extradir: Convert a directory tree to a
237 # file. The test tree includes an extra file in the directory
238 # that is not present in the old tree. This should generate a
240 for i in $OLD $TEST; do
241 mkdir $i/dirchange/fromdir/extradir
242 echo "foo" > $i/dirchange/fromdir/extradir/file
244 mkfifo $TEST/dirchange/fromdir/extradir/fifo
245 ln -s "bar" $NEW/dirchange/fromdir/extradir
247 # /dirchange/fromdir/conflict: Convert a directory tree to a
248 # file. The test tree includes a local change that generates
249 # a warning and prevents the removal of the directory.
250 for i in $OLD $TEST; do
251 mkdir $i/dirchange/fromdir/conflict
253 echo "foo" > $OLD/dirchange/fromdir/conflict/somefile
254 echo "bar" > $TEST/dirchange/fromdir/conflict/somefile
255 mkfifo $NEW/dirchange/fromdir/conflict
257 # /dirchange/todir/difffile: Convert a file to a directory
258 # tree. The test tree has a locally modified version of the
259 # file so that the conversion fails with a warning.
260 echo "foo" > $OLD/dirchange/todir/difffile
261 mkdir $NEW/dirchange/todir/difffile
262 echo "baz" > $NEW/dirchange/todir/difffile/file
263 echo "bar" > $TEST/dirchange/todir/difffile
265 # /dirchange/todir/difftype: Similar to the previous test, but
266 # the conflict is due to a change in the file type.
267 echo "foo" > $OLD/dirchange/todir/difftype
268 mkdir $NEW/dirchange/todir/difftype
269 echo "baz" > $NEW/dirchange/todir/difftype/file
270 mkfifo $TEST/dirchange/todir/difftype
273 # $1 - relative path to file that should be missing from TEST
276 if [ -e $TEST/$1 -o -L $TEST/$1 ]; then
277 echo "File $1 should be missing"
281 # $1 - relative path to file that should be present in TEST
284 if ! [ -e $TEST/$1 -o -L $TEST/$1 ]; then
285 echo "File $1 should be present"
289 # $1 - relative path to file that should be a fifo in TEST
292 if ! [ -p $TEST/$1 ]; then
293 echo "File $1 should be a FIFO"
297 # $1 - relative path to file that should be a directory in TEST
300 if ! [ -d $TEST/$1 ]; then
301 echo "File $1 should be a directory"
305 # $1 - relative path to file that should be a symlink in TEST
306 # $2 - optional value of the link
311 if ! [ -L $TEST/$1 ]; then
312 echo "File $1 should be a link"
313 elif [ $# -gt 1 ]; then
314 val=`readlink $TEST/$1`
315 if [ "$val" != "$2" ]; then
316 echo "Link $1 should link to \"$2\""
321 # $1 - relative path to regular file that should be present in TEST
322 # $2 - optional string that should match file contents
323 # $3 - optional MD5 of the flie contents, overrides $2 if present
328 if ! [ -f $TEST/$1 ]; then
329 echo "File $1 should be a regular file"
330 elif [ $# -eq 2 ]; then
331 contents=`cat $TEST/$1`
332 if [ "$contents" != "$2" ]; then
333 echo "File $1 has wrong contents"
335 elif [ $# -eq 3 ]; then
336 sum=`md5 -q $TEST/$1`
337 if [ "$sum" != "$3" ]; then
338 echo "File $1 has wrong contents"
343 # $1 - relative path to a regular file that should have a conflict
344 # $2 - optional MD5 of the conflict file contents
349 if ! [ -f $CONFLICTS/$1 ]; then
350 echo "File $1 missing conflict"
351 elif [ $# -gt 1 ]; then
352 sum=`md5 -q $CONFLICTS/$1`
353 if [ "$sum" != "$2" ]; then
354 echo "Conflict $1 has wrong contents"
359 # $1 - relative path to a regular file that should not have a conflict
362 if [ -f $CONFLICTS/$1 ]; then
363 echo "File $1 should not have a conflict"
367 if [ `id -u` -ne 0 ]; then
371 if [ -r /etc/etcupdate.conf ]; then
372 echo "WARNING: /etc/etcupdate.conf settings may break some tests."
375 # First run the test ignoring no patterns.
379 $COMMAND -r -d $WORKDIR -D $TEST > $WORKDIR/test.out
381 cat > $WORKDIR/correct.out <<EOF
382 D /dirchange/fromdir/extradir/file
383 C /difffiles/difffiles/difffiles/conflict
384 C /difftype/difftype/difffiles/file
385 C /second/second/difffiles/file
387 Modified regular file remains: /dirchange/fromdir/conflict/somefile
388 Modified regular file remains: /first/difffiles/second/file
389 Modified symbolic link remains: /first/difflinks/second/link
390 Modified directory remains: /first/difftype/second/fifo
391 Modified directory remains: /rmdir/conflict/difftype
392 Non-empty directory remains: /rmdir/extra
393 Non-empty directory remains: /rmdir/conflict
394 Modified mismatch: /difffiles/difftype/difftype/file (regular file vs fifo file)
395 Removed file changed: /difffiles/first/first/file
396 Modified link changed: /difflinks/difflinks/difflinks/link ("old" became "new")
397 Modified mismatch: /difflinks/difftype/difftype/link (symbolic link vs regular file)
398 Removed link changed: /difflinks/first/first/link ("old" became "new")
399 New link conflict: /difftype/difftype/difflinks/link ("new" vs "test")
400 Modified regular file changed: /difftype/difftype/difftype/one (fifo file became directory)
401 Modified symbolic link changed: /difftype/difftype/difftype/two (directory became regular file)
402 Remove mismatch: /difftype/first/first/fifo (fifo file became directory)
403 Modified directory changed: /dirchange/fromdir/conflict (directory became fifo file)
404 Modified directory changed: /dirchange/fromdir/extradir (directory became symbolic link)
405 Modified regular file changed: /dirchange/todir/difffile (regular file became directory)
406 Modified fifo file changed: /dirchange/todir/difftype (regular file became directory)
407 New file mismatch: /adddir/conflict (directory vs regular file)
408 Directory mismatch: $TEST/adddir/conflict (regular file)
409 Directory mismatch: $TEST/dirchange/todir/difffile (regular file)
410 Directory mismatch: $TEST/dirchange/todir/difftype (fifo file)
411 New link conflict: /second/second/difflinks/link ("new link" vs "test link")
412 New file mismatch: /second/second/difftype/dir (directory vs fifo file)
415 echo "Differences for regular:"
416 diff -u -L "correct" $WORKDIR/correct.out -L "test" $WORKDIR/test.out
418 ## /first/difftype/second:
419 present /first/difftype/second/fifo
421 ## /first/difflinks/second:
422 link /first/difflinks/second/link "test link"
424 ## /first/difffiles/second:
425 file /first/difffiles/second/file "bar"
427 ## /second/second/difftype:
428 fifo /second/second/difftype/dir
430 ## /second/second/difflinks:
431 link /second/second/difflinks/link "test link"
433 ## /second/second/difffiles:
434 file /second/second/difffiles/file "test"
435 conflict /second/second/difffiles/file 4f2ee8620a251fd53f06bb6112eb6ffa
437 ## /difftype/first/first:
438 missing /difftype/first/first/fifo
440 ## /difftype/difftype/difftype:
441 file /difftype/difftype/difftype/one "foo"
442 link /difftype/difftype/difftype/two "bar"
444 ## /difftype/difftype/difflinks:
445 link /difftype/difftype/difflinks/link "test"
447 ## /difftype/difftype/difffile:
448 conflict /difftype/difftype/difffiles/file 117f2bcd1f6491f6044e79e5a57a9229
450 ## /difflinks/first/first:
451 missing /difflinks/first/first/link
453 ## /difflinks/difftype/difftype:
454 file /difflinks/difftype/difftype/link "test"
456 ## /difflinks/difflinks/difflinks:
457 link /difflinks/difflinks/difflinks/link "test"
459 ## /difffiles/first/first:
460 missing /difffiles/first/first/file
462 ## /difffiles/difftype/difftype:
463 fifo /difffiles/difftype/difftype/file
465 ## /difffiles/difffiles/difffiles:
466 file /difffiles/difffiles/difffiles/conflict "this is a test file"
467 conflict /difffiles/difffiles/difffiles/conflict \
468 8261cfdd89280c4a6c26e4ac86541fe9
471 file /adddir/conflict
475 file /rmdir/extra/localfile.txt "foo"
478 dir /rmdir/conflict/difftype
479 present /rmdir/conflict
481 ## /dirchange/fromdir/extradir:
482 missing /dirchange/fromdir/extradir/file
483 fifo /dirchange/fromdir/extradir/fifo
485 ## /dirchange/fromdir/conflict:
486 file /dirchange/fromdir/conflict/somefile "bar"
488 ## /dirchange/todir/difffile:
489 file /dirchange/todir/difffile "bar"
491 ## /dirchange/todir/difftype:
492 fifo /dirchange/todir/difftype
494 # Now test with -A '/first*' -A '/second* /*di*'. This should remove
495 # most of the warnings and conflicts.
499 $COMMAND -r -A '/first*' -A '/second* /*di*' -d $WORKDIR -D $TEST > \
502 cat > $WORKDIR/correct1.out <<EOF
503 D /dirchange/fromdir/extradir/file
504 U /difffiles/difffiles/difffiles/conflict
505 U /difffiles/difftype/difftype/file
506 A /difffiles/first/first/file
507 U /difflinks/difflinks/difflinks/link
508 U /difflinks/difftype/difftype/link
509 A /difflinks/first/first/link
510 U /difftype/difftype/difffiles/file
511 U /difftype/difftype/difflinks/link
512 D /difftype/difftype/difftype/one
513 U /difftype/difftype/difftype/two
514 U /dirchange/todir/difffile
515 U /dirchange/todir/difftype
517 A /adddir/conflict/newfile
518 A /dirchange/todir/difffile/file
519 A /dirchange/todir/difftype/file
520 U /second/second/difffiles/file
521 U /second/second/difflinks/link
522 D /second/second/difftype/dir
524 Modified regular file remains: /dirchange/fromdir/conflict/somefile
525 Modified regular file remains: /first/difffiles/second/file
526 Modified symbolic link remains: /first/difflinks/second/link
527 Modified directory remains: /first/difftype/second/fifo
528 Modified directory remains: /rmdir/conflict/difftype
529 Non-empty directory remains: /rmdir/extra
530 Non-empty directory remains: /rmdir/conflict
531 Modified directory changed: /dirchange/fromdir/conflict (directory became fifo file)
532 Modified directory changed: /dirchange/fromdir/extradir (directory became symbolic link)
535 echo "Differences for -A '/first*' -A '/second* /*di*':"
536 diff -u -L "correct" $WORKDIR/correct1.out -L "test" $WORKDIR/test1.out
538 ## /first/difftype/second:
539 present /first/difftype/second/fifo
541 ## /first/difflinks/second:
542 link /first/difflinks/second/link "test link"
544 ## /first/difffiles/second:
545 file /first/difffiles/second/file "bar"
547 ## /second/second/difftype:
548 missing /second/second/difftype/dir
550 ## /second/second/difflinks:
551 link /second/second/difflinks/link "new link"
553 ## /second/second/difffiles:
554 file /second/second/difffiles/file "new"
555 noconflict /second/second/difffiles/file
557 ## /difftype/first/first:
558 missing /difftype/first/first/fifo
560 ## /difftype/difftype/difftype:
561 missing /difftype/difftype/difftype/one
562 file /difftype/difftype/difftype/two "baz"
564 ## /difftype/difftype/difflinks:
565 link /difftype/difftype/difflinks/link "new"
567 ## /difftype/difftype/difffile:
568 noconflict /difftype/difftype/difffiles/file
569 file /difftype/difftype/difffiles/file "foo"
571 ## /difflinks/first/first:
572 link /difflinks/first/first/link "new"
574 ## /difflinks/difftype/difftype:
575 link /difflinks/difftype/difftype/link "new"
577 ## /difflinks/difflinks/difflinks:
578 link /difflinks/difflinks/difflinks/link "new"
580 ## /difffiles/first/first:
581 file /difffiles/first/first/file "bar"
583 ## /difffiles/difftype/difftype:
584 file /difffiles/difftype/difftype/file "new"
586 ## /difffiles/difffiles/difffiles:
587 noconflict /difffiles/difffiles/difffiles/conflict
588 file /difffiles/difffiles/difffiles/conflict "this is a new file"
591 file /adddir/conflict/newfile
595 file /rmdir/extra/localfile.txt "foo"
598 dir /rmdir/conflict/difftype
599 present /rmdir/conflict
601 ## /dirchange/fromdir/extradir:
602 missing /dirchange/fromdir/extradir/file
603 fifo /dirchange/fromdir/extradir/fifo
605 ## /dirchange/fromdir/conflict:
606 file /dirchange/fromdir/conflict/somefile "bar"
608 ## /dirchange/todir/difffile:
609 file /dirchange/todir/difffile/file "baz"
611 ## /dirchange/todir/difftype:
612 file /dirchange/todir/difftype/file "baz"