| 1 | #! /bin/sh |
| 2 | |
| 3 | # Copyright (C) 2003 by Wayne Davison <wayned@samba.org> |
| 4 | |
| 5 | # This program is distributable under the terms of the GNU GPL see |
| 6 | # COPYING). |
| 7 | |
| 8 | # Test rsync handling of exclude/include directives. |
| 9 | |
| 10 | # Test some of the more obscure wildcard handling of exclude/include |
| 11 | # processing. |
| 12 | |
| 13 | . $srcdir/testsuite/rsync.fns |
| 14 | |
| 15 | set -x |
| 16 | |
| 17 | # Build some files/dirs/links to copy |
| 18 | |
| 19 | fromdir="$scratchdir/from" |
| 20 | todir="$scratchdir/to" |
| 21 | chkdir="$scratchdir/chk" |
| 22 | |
| 23 | makepath "$fromdir/foo/down/to/you" |
| 24 | makepath "$fromdir/bar/down/to/foo/too" |
| 25 | makepath "$fromdir/mid/for/foo/and/that/is/who" |
| 26 | echo kept >"$fromdir/foo/file1" |
| 27 | echo removed >"$fromdir/foo/file2" |
| 28 | echo keeper >"$fromdir/bar/down/to/foo/file1" |
| 29 | echo gone >"$fromdir/bar/down/to/foo/file3" |
| 30 | echo lost >"$fromdir/bar/down/to/foo/file4" |
| 31 | echo smashed >"$fromdir/bar/down/to/foo/to" |
| 32 | echo expunged >"$fromdir/mid/for/foo/extra" |
| 33 | echo retained >"$fromdir/mid/for/foo/keep" |
| 34 | ln -s too "$fromdir/bar/down/to/foo/sym" |
| 35 | |
| 36 | # Setup our test exclude/include file. |
| 37 | |
| 38 | excl="$scratchdir/exclude-from" |
| 39 | cat >"$excl" <<EOF |
| 40 | # If the second line of these two lines does anything, it's a bug. |
| 41 | + **/bar |
| 42 | - /bar |
| 43 | # This should match against the whole path, not just the name. |
| 44 | + foo**too |
| 45 | # This should float at the end of the path. |
| 46 | - foo/*/ |
| 47 | # Test some normal excludes. Competing lines are paired. |
| 48 | + t[o]/ |
| 49 | - to |
| 50 | + file4 |
| 51 | - file[2-9] |
| 52 | - /mid/for/foo/extra |
| 53 | EOF |
| 54 | |
| 55 | # Create the chk dir with what we expect to be excluded |
| 56 | |
| 57 | checkit "$RSYNC -avv \"$fromdir/\" \"$chkdir/\"" "$fromdir" "$chkdir" |
| 58 | |
| 59 | sleep 1 # Ensures that the rm commands will tweak the directory times. |
| 60 | |
| 61 | rm -r "$chkdir"/foo/down |
| 62 | rm -r "$chkdir"/mid/for/foo/and |
| 63 | rm "$chkdir"/foo/file[235-9] |
| 64 | rm "$chkdir"/bar/down/to/foo/to "$chkdir"/bar/down/to/foo/file[235-9] |
| 65 | rm "$chkdir"/mid/for/foo/extra |
| 66 | |
| 67 | # Un-tweak the directory times in our first (weak) exclude test (though |
| 68 | # it's a good test of the --existing option). |
| 69 | $RSYNC -av --existing --include='*/' --exclude='*' "$fromdir/" "$chkdir/" |
| 70 | |
| 71 | # Now, test if rsync excludes the same files. |
| 72 | |
| 73 | checkit "$RSYNC -avv --exclude-from=$excl \"$fromdir/\" \"$todir/\"" "$chkdir" "$todir" |
| 74 | |
| 75 | # The script would have aborted on error, so getting here means we've won. |
| 76 | exit 0 |