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.
37 echo "Usage: always.sh [-s script] [-w workdir]"
41 # Allow the user to specify an alternate work directory or script.
43 while getopts "s:w:" option; do
62 CONFLICTS=$WORKDIR/conflicts
67 # The various states of the comparison of a file between two trees.
68 states="equal first second difftype difflinks difffiles"
70 # These tests deal with ignoring certain patterns of files. We run
71 # the test multiple times forcing the install of different patterns.
76 rm -rf $OLD $NEW $TEST $CONFLICTS
81 mkdir -p $OLD/$i/$j/$k $NEW/$i/$j/$k \
87 # What follows are the various warning/conflict cases from the
88 # larger regression tests. These results of many of these
89 # tests should be changed when installation is forced. The
90 # cases when these updates should still fail even when forced
91 # are: 1) it should not force the removal of a modified file
92 # and 2) it should not remove a subdirectory that contains a
93 # modified or added file.
95 # /first/difftype/second: File with different local type
96 # removed. Should generate a warning.
97 mkfifo $OLD/first/difftype/second/fifo
98 mkdir $TEST/first/difftype/second/fifo
100 # /first/difflinks/second: Modified link removed. Should
101 # generate a warning.
102 ln -s "old link" $OLD/first/difflinks/second/link
103 ln -s "test link" $TEST/first/difflinks/second/link
105 # /first/difffiles/second: Modified file removed. Should
106 # generate a warning.
107 echo "foo" > $OLD/first/difffiles/second/file
108 echo "bar" > $TEST/first/difffiles/second/file
110 # /second/second/difftype: Newly added file conflicts with
111 # existing file in test tree of a different type. Should
112 # generate a warning.
113 mkdir $NEW/second/second/difftype/dir
114 mkfifo $TEST/second/second/difftype/dir
116 # /second/second/difflinks: Newly added link conflicts with
117 # existing link in test tree. Should generate a warning.
118 ln -s "new link" $NEW/second/second/difflinks/link
119 ln -s "test link" $TEST/second/second/difflinks/link
121 # /second/second/difffiles: Newly added file conflicts with
122 # existing file in test tree. Should generate a warning.
123 echo "new" > $NEW/second/second/difffiles/file
124 echo "test" > $TEST/second/second/difffiles/file
126 # /difftype/first/first: A removed file has changed type.
127 # This should generate a warning.
128 mkfifo $OLD/difftype/first/first/fifo
129 mkdir $NEW/difftype/first/first/fifo
131 # /difftype/difftype/difftype: All three files (old, new, and
132 # test) are different types from each other. This should
133 # generate a warning.
134 mkfifo $OLD/difftype/difftype/difftype/one
135 mkdir $NEW/difftype/difftype/difftype/one
136 echo "foo" > $TEST/difftype/difftype/difftype/one
137 mkdir $OLD/difftype/difftype/difftype/two
138 echo "baz" > $NEW/difftype/difftype/difftype/two
139 ln -s "bar" $TEST/difftype/difftype/difftype/two
141 # /difftype/difftype/difflinks: A file has changed from a
142 # non-link to a link in both the new and test trees, but the
143 # target of the new and test links differ. This should
144 # generate a new link conflict.
145 mkfifo $OLD/difftype/difftype/difflinks/link
146 ln -s "new" $NEW/difftype/difftype/difflinks/link
147 ln -s "test" $TEST/difftype/difftype/difflinks/link
149 # /difftype/difftype/difffile: A file has changed from a
150 # non-regular file to a regular file in both the new and test
151 # trees, but the contents in the new and test files differ.
152 # This should generate a new file conflict.
153 ln -s "old" $OLD/difftype/difftype/difffiles/file
154 echo "foo" > $NEW/difftype/difftype/difffiles/file
155 echo "bar" > $TEST/difftype/difftype/difffiles/file
157 # /difflinks/first/first: A modified link is missing in the
158 # test tree. This should generate a warning.
159 ln -s "old" $OLD/difflinks/first/first/link
160 ln -s "new" $NEW/difflinks/first/first/link
162 # /difflinks/difftype/difftype: An updated link has been
163 # changed to a different file type in the test tree. This
164 # should generate a warning.
165 ln -s "old" $OLD/difflinks/difftype/difftype/link
166 ln -s "new" $NEW/difflinks/difftype/difftype/link
167 echo "test" > $TEST/difflinks/difftype/difftype/link
169 # /difflinks/difflinks/difflinks: An updated link has been
170 # modified in the test tree and doesn't match either the old
171 # or new links. This should generate a warning.
172 ln -s "old" $OLD/difflinks/difflinks/difflinks/link
173 ln -s "new" $NEW/difflinks/difflinks/difflinks/link
174 ln -s "test" $TEST/difflinks/difflinks/difflinks/link
176 # /difffiles/first/first: A removed file has been changed in
177 # the new tree. This should generate a warning.
178 echo "foo" > $OLD/difffiles/first/first/file
179 echo "bar" > $NEW/difffiles/first/first/file
181 # /difffiles/difftype/difftype: An updated regular file has
182 # been changed to a different file type in the test tree.
183 # This should generate a warning.
184 echo "old" > $OLD/difffiles/difftype/difftype/file
185 echo "new" > $NEW/difffiles/difftype/difftype/file
186 mkfifo $TEST/difffiles/difftype/difftype/file
188 # /difffiles/difffiles/difffiles: A modified regular file was
189 # updated in the new tree. The changes should be merged into
190 # to the new file if possible. If the merge fails, a conflict
191 # should be generated. For this test we just include the
193 cat > $OLD/difffiles/difffiles/difffiles/conflict <<EOF
196 cat > $NEW/difffiles/difffiles/difffiles/conflict <<EOF
199 cat > $TEST/difffiles/difffiles/difffiles/conflict <<EOF
203 ## Tests for adding directories
204 mkdir -p $OLD/adddir $NEW/adddir $TEST/adddir
206 # /adddir/conflict: Add a new file in a directory that already
207 # exists as a file. This should generate two warnings.
208 mkdir $NEW/adddir/conflict
209 touch $NEW/adddir/conflict/newfile
210 touch $TEST/adddir/conflict
212 ## Tests for removing directories
213 mkdir -p $OLD/rmdir $NEW/rmdir $TEST/rmdir
215 # /rmdir/extra: Do not remove a directory with an extra local file.
216 # This should generate a warning.
217 for i in $OLD $TEST; do
220 echo "foo" > $TEST/rmdir/extra/localfile.txt
222 # /rmdir/conflict: Do not remove a directory with a conflicted
223 # remove file. This should generate a warning.
224 for i in $OLD $TEST; do
225 mkdir $i/rmdir/conflict
227 mkfifo $OLD/rmdir/conflict/difftype
228 mkdir $TEST/rmdir/conflict/difftype
230 ## Tests for converting files to directories and vice versa
231 for i in $OLD $NEW $TEST; do
232 for j in already old fromdir todir; do
233 mkdir -p $i/dirchange/$j
237 # /dirchange/fromdir/extradir: Convert a directory tree to a
238 # file. The test tree includes an extra file in the directory
239 # that is not present in the old tree. This should generate a
241 for i in $OLD $TEST; do
242 mkdir $i/dirchange/fromdir/extradir
243 echo "foo" > $i/dirchange/fromdir/extradir/file
245 mkfifo $TEST/dirchange/fromdir/extradir/fifo
246 ln -s "bar" $NEW/dirchange/fromdir/extradir
248 # /dirchange/fromdir/conflict: Convert a directory tree to a
249 # file. The test tree includes a local change that generates
250 # a warning and prevents the removal of the directory.
251 for i in $OLD $TEST; do
252 mkdir $i/dirchange/fromdir/conflict
254 echo "foo" > $OLD/dirchange/fromdir/conflict/somefile
255 echo "bar" > $TEST/dirchange/fromdir/conflict/somefile
256 mkfifo $NEW/dirchange/fromdir/conflict
258 # /dirchange/todir/difffile: Convert a file to a directory
259 # tree. The test tree has a locally modified version of the
260 # file so that the conversion fails with a warning.
261 echo "foo" > $OLD/dirchange/todir/difffile
262 mkdir $NEW/dirchange/todir/difffile
263 echo "baz" > $NEW/dirchange/todir/difffile/file
264 echo "bar" > $TEST/dirchange/todir/difffile
266 # /dirchange/todir/difftype: Similar to the previous test, but
267 # the conflict is due to a change in the file type.
268 echo "foo" > $OLD/dirchange/todir/difftype
269 mkdir $NEW/dirchange/todir/difftype
270 echo "baz" > $NEW/dirchange/todir/difftype/file
271 mkfifo $TEST/dirchange/todir/difftype
274 # $1 - relative path to file that should be missing from TEST
277 if [ -e $TEST/$1 -o -L $TEST/$1 ]; then
278 echo "File $1 should be missing"
283 # $1 - relative path to file that should be present in TEST
286 if ! [ -e $TEST/$1 -o -L $TEST/$1 ]; then
287 echo "File $1 should be present"
292 # $1 - relative path to file that should be a fifo in TEST
295 if ! [ -p $TEST/$1 ]; then
296 echo "File $1 should be a FIFO"
301 # $1 - relative path to file that should be a directory in TEST
304 if ! [ -d $TEST/$1 ]; then
305 echo "File $1 should be a directory"
310 # $1 - relative path to file that should be a symlink in TEST
311 # $2 - optional value of the link
316 if ! [ -L $TEST/$1 ]; then
317 echo "File $1 should be a link"
319 elif [ $# -gt 1 ]; then
320 val=`readlink $TEST/$1`
321 if [ "$val" != "$2" ]; then
322 echo "Link $1 should link to \"$2\""
328 # $1 - relative path to regular file that should be present in TEST
329 # $2 - optional string that should match file contents
330 # $3 - optional MD5 of the flie contents, overrides $2 if present
335 if ! [ -f $TEST/$1 ]; then
336 echo "File $1 should be a regular file"
338 elif [ $# -eq 2 ]; then
339 contents=`cat $TEST/$1`
340 if [ "$contents" != "$2" ]; then
341 echo "File $1 has wrong contents"
344 elif [ $# -eq 3 ]; then
345 sum=`md5 -q $TEST/$1`
346 if [ "$sum" != "$3" ]; then
347 echo "File $1 has wrong contents"
353 # $1 - relative path to a regular file that should have a conflict
354 # $2 - optional MD5 of the conflict file contents
359 if ! [ -f $CONFLICTS/$1 ]; then
360 echo "File $1 missing conflict"
362 elif [ $# -gt 1 ]; then
363 sum=`md5 -q $CONFLICTS/$1`
364 if [ "$sum" != "$2" ]; then
365 echo "Conflict $1 has wrong contents"
371 # $1 - relative path to a regular file that should not have a conflict
374 if [ -f $CONFLICTS/$1 ]; then
375 echo "File $1 should not have a conflict"
380 if [ `id -u` -ne 0 ]; then
385 if [ -r /etc/etcupdate.conf ]; then
386 echo "WARNING: /etc/etcupdate.conf settings may break some tests."
389 # First run the test ignoring no patterns.
393 $COMMAND -r -d $WORKDIR -D $TEST > $WORKDIR/test.out
395 cat > $WORKDIR/correct.out <<EOF
396 D /dirchange/fromdir/extradir/file
397 C /difffiles/difffiles/difffiles/conflict
398 C /difftype/difftype/difffiles/file
399 C /second/second/difffiles/file
401 Modified regular file remains: /dirchange/fromdir/conflict/somefile
402 Modified regular file remains: /first/difffiles/second/file
403 Modified symbolic link remains: /first/difflinks/second/link
404 Modified directory remains: /first/difftype/second/fifo
405 Modified directory remains: /rmdir/conflict/difftype
406 Non-empty directory remains: /rmdir/extra
407 Non-empty directory remains: /rmdir/conflict
408 Modified mismatch: /difffiles/difftype/difftype/file (regular file vs fifo file)
409 Removed file changed: /difffiles/first/first/file
410 Modified link changed: /difflinks/difflinks/difflinks/link ("old" became "new")
411 Modified mismatch: /difflinks/difftype/difftype/link (symbolic link vs regular file)
412 Removed link changed: /difflinks/first/first/link ("old" became "new")
413 New link conflict: /difftype/difftype/difflinks/link ("new" vs "test")
414 Modified regular file changed: /difftype/difftype/difftype/one (fifo file became directory)
415 Modified symbolic link changed: /difftype/difftype/difftype/two (directory became regular file)
416 Remove mismatch: /difftype/first/first/fifo (fifo file became directory)
417 Modified directory changed: /dirchange/fromdir/conflict (directory became fifo file)
418 Modified directory changed: /dirchange/fromdir/extradir (directory became symbolic link)
419 Modified regular file changed: /dirchange/todir/difffile (regular file became directory)
420 Modified fifo file changed: /dirchange/todir/difftype (regular file became directory)
421 New file mismatch: /adddir/conflict (directory vs regular file)
422 Directory mismatch: $TEST/adddir/conflict (regular file)
423 Directory mismatch: $TEST/dirchange/todir/difffile (regular file)
424 Directory mismatch: $TEST/dirchange/todir/difftype (fifo file)
425 New link conflict: /second/second/difflinks/link ("new link" vs "test link")
426 New file mismatch: /second/second/difftype/dir (directory vs fifo file)
429 echo "Differences for regular:"
430 diff -u -L "correct" $WORKDIR/correct.out -L "test" $WORKDIR/test.out \
433 ## /first/difftype/second:
434 present /first/difftype/second/fifo
436 ## /first/difflinks/second:
437 link /first/difflinks/second/link "test link"
439 ## /first/difffiles/second:
440 file /first/difffiles/second/file "bar"
442 ## /second/second/difftype:
443 fifo /second/second/difftype/dir
445 ## /second/second/difflinks:
446 link /second/second/difflinks/link "test link"
448 ## /second/second/difffiles:
449 file /second/second/difffiles/file "test"
450 conflict /second/second/difffiles/file 4f2ee8620a251fd53f06bb6112eb6ffa
452 ## /difftype/first/first:
453 missing /difftype/first/first/fifo
455 ## /difftype/difftype/difftype:
456 file /difftype/difftype/difftype/one "foo"
457 link /difftype/difftype/difftype/two "bar"
459 ## /difftype/difftype/difflinks:
460 link /difftype/difftype/difflinks/link "test"
462 ## /difftype/difftype/difffile:
463 conflict /difftype/difftype/difffiles/file 117f2bcd1f6491f6044e79e5a57a9229
465 ## /difflinks/first/first:
466 missing /difflinks/first/first/link
468 ## /difflinks/difftype/difftype:
469 file /difflinks/difftype/difftype/link "test"
471 ## /difflinks/difflinks/difflinks:
472 link /difflinks/difflinks/difflinks/link "test"
474 ## /difffiles/first/first:
475 missing /difffiles/first/first/file
477 ## /difffiles/difftype/difftype:
478 fifo /difffiles/difftype/difftype/file
480 ## /difffiles/difffiles/difffiles:
481 file /difffiles/difffiles/difffiles/conflict "this is a test file"
482 conflict /difffiles/difffiles/difffiles/conflict \
483 8261cfdd89280c4a6c26e4ac86541fe9
486 file /adddir/conflict
490 file /rmdir/extra/localfile.txt "foo"
493 dir /rmdir/conflict/difftype
494 present /rmdir/conflict
496 ## /dirchange/fromdir/extradir:
497 missing /dirchange/fromdir/extradir/file
498 fifo /dirchange/fromdir/extradir/fifo
500 ## /dirchange/fromdir/conflict:
501 file /dirchange/fromdir/conflict/somefile "bar"
503 ## /dirchange/todir/difffile:
504 file /dirchange/todir/difffile "bar"
506 ## /dirchange/todir/difftype:
507 fifo /dirchange/todir/difftype
509 # Now test with -A '/first*' -A '/second* /*di*'. This should remove
510 # most of the warnings and conflicts.
514 $COMMAND -r -A '/first*' -A '/second* /*di*' -d $WORKDIR -D $TEST > \
517 cat > $WORKDIR/correct1.out <<EOF
518 D /dirchange/fromdir/extradir/file
519 U /difffiles/difffiles/difffiles/conflict
520 U /difffiles/difftype/difftype/file
521 A /difffiles/first/first/file
522 U /difflinks/difflinks/difflinks/link
523 U /difflinks/difftype/difftype/link
524 A /difflinks/first/first/link
525 U /difftype/difftype/difffiles/file
526 U /difftype/difftype/difflinks/link
527 D /difftype/difftype/difftype/one
528 U /difftype/difftype/difftype/two
529 U /dirchange/todir/difffile
530 U /dirchange/todir/difftype
532 A /adddir/conflict/newfile
533 A /dirchange/todir/difffile/file
534 A /dirchange/todir/difftype/file
535 U /second/second/difffiles/file
536 U /second/second/difflinks/link
537 D /second/second/difftype/dir
539 Modified regular file remains: /dirchange/fromdir/conflict/somefile
540 Modified regular file remains: /first/difffiles/second/file
541 Modified symbolic link remains: /first/difflinks/second/link
542 Modified directory remains: /first/difftype/second/fifo
543 Modified directory remains: /rmdir/conflict/difftype
544 Non-empty directory remains: /rmdir/extra
545 Non-empty directory remains: /rmdir/conflict
546 Modified directory changed: /dirchange/fromdir/conflict (directory became fifo file)
547 Modified directory changed: /dirchange/fromdir/extradir (directory became symbolic link)
550 echo "Differences for -A '/first*' -A '/second* /*di*':"
551 diff -u -L "correct" $WORKDIR/correct1.out -L "test" $WORKDIR/test1.out \
554 ## /first/difftype/second:
555 present /first/difftype/second/fifo
557 ## /first/difflinks/second:
558 link /first/difflinks/second/link "test link"
560 ## /first/difffiles/second:
561 file /first/difffiles/second/file "bar"
563 ## /second/second/difftype:
564 missing /second/second/difftype/dir
566 ## /second/second/difflinks:
567 link /second/second/difflinks/link "new link"
569 ## /second/second/difffiles:
570 file /second/second/difffiles/file "new"
571 noconflict /second/second/difffiles/file
573 ## /difftype/first/first:
574 missing /difftype/first/first/fifo
576 ## /difftype/difftype/difftype:
577 missing /difftype/difftype/difftype/one
578 file /difftype/difftype/difftype/two "baz"
580 ## /difftype/difftype/difflinks:
581 link /difftype/difftype/difflinks/link "new"
583 ## /difftype/difftype/difffile:
584 noconflict /difftype/difftype/difffiles/file
585 file /difftype/difftype/difffiles/file "foo"
587 ## /difflinks/first/first:
588 link /difflinks/first/first/link "new"
590 ## /difflinks/difftype/difftype:
591 link /difflinks/difftype/difftype/link "new"
593 ## /difflinks/difflinks/difflinks:
594 link /difflinks/difflinks/difflinks/link "new"
596 ## /difffiles/first/first:
597 file /difffiles/first/first/file "bar"
599 ## /difffiles/difftype/difftype:
600 file /difffiles/difftype/difftype/file "new"
602 ## /difffiles/difffiles/difffiles:
603 noconflict /difffiles/difffiles/difffiles/conflict
604 file /difffiles/difffiles/difffiles/conflict "this is a new file"
607 file /adddir/conflict/newfile
611 file /rmdir/extra/localfile.txt "foo"
614 dir /rmdir/conflict/difftype
615 present /rmdir/conflict
617 ## /dirchange/fromdir/extradir:
618 missing /dirchange/fromdir/extradir/file
619 fifo /dirchange/fromdir/extradir/fifo
621 ## /dirchange/fromdir/conflict:
622 file /dirchange/fromdir/conflict/somefile "bar"
624 ## /dirchange/todir/difffile:
625 file /dirchange/todir/difffile/file "baz"
627 ## /dirchange/todir/difftype:
628 file /dirchange/todir/difftype/file "baz"