| 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 | . "$suitedir/rsync.fns" |
| 14 | |
| 15 | set -x |
| 16 | |
| 17 | HOME="$scratchdir" |
| 18 | CVSIGNORE='*.junk' |
| 19 | export HOME CVSIGNORE |
| 20 | |
| 21 | # Build some files/dirs/links to copy |
| 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 cvsout >"$fromdir/foo/file2.old" |
| 29 | echo cvsout >"$fromdir/bar/down/to/home-cvs-exclude" |
| 30 | echo keeper >"$fromdir/bar/down/to/foo/file1" |
| 31 | echo cvsout >"$fromdir/bar/down/to/foo/file1.bak" |
| 32 | echo gone >"$fromdir/bar/down/to/foo/file3" |
| 33 | echo lost >"$fromdir/bar/down/to/foo/file4" |
| 34 | echo cvsout >"$fromdir/bar/down/to/foo/file4.junk" |
| 35 | echo smashed >"$fromdir/bar/down/to/foo/to" |
| 36 | echo cvsout >"$fromdir/mid/one-in-one-out" |
| 37 | echo one-in-one-out >"$fromdir/mid/.cvsignore" |
| 38 | echo cvsin >"$fromdir/mid/one-for-all" |
| 39 | echo cvsin >"$fromdir/mid/for/one-in-one-out" |
| 40 | echo expunged >"$fromdir/mid/for/foo/extra" |
| 41 | echo retained >"$fromdir/mid/for/foo/keep" |
| 42 | ln -s too "$fromdir/bar/down/to/foo/sym" |
| 43 | |
| 44 | # Setup our test exclude/include files. |
| 45 | |
| 46 | excl="$scratchdir/exclude-from" |
| 47 | cat >"$excl" <<EOF |
| 48 | # If the second line of these two lines does anything, it's a bug. |
| 49 | + **/bar |
| 50 | - /bar |
| 51 | # This should match against the whole path, not just the name. |
| 52 | + foo**too |
| 53 | # This should float at the end of the path. |
| 54 | - foo/*/ |
| 55 | # Test some normal excludes. Competing lines are paired. |
| 56 | + t[o]/ |
| 57 | - to |
| 58 | + file4 |
| 59 | - file[2-9] |
| 60 | - /mid/for/foo/extra |
| 61 | EOF |
| 62 | |
| 63 | cat >"$scratchdir/.cvsignore" <<EOF |
| 64 | home-cvs-exclude |
| 65 | EOF |
| 66 | |
| 67 | # Create the chk dir with what we expect to be excluded |
| 68 | |
| 69 | checkit "$RSYNC -avv \"$fromdir/\" \"$chkdir/\"" "$fromdir" "$chkdir" |
| 70 | |
| 71 | sleep 1 # Ensures that the rm commands will tweak the directory times. |
| 72 | |
| 73 | rm -r "$chkdir"/foo/down |
| 74 | rm -r "$chkdir"/mid/for/foo/and |
| 75 | rm "$chkdir"/foo/file[235-9] |
| 76 | rm "$chkdir"/bar/down/to/foo/to "$chkdir"/bar/down/to/foo/file[235-9] |
| 77 | rm "$chkdir"/mid/for/foo/extra |
| 78 | |
| 79 | # Un-tweak the directory times in our first (weak) exclude test (though |
| 80 | # it's a good test of the --existing option). |
| 81 | $RSYNC -av --existing --include='*/' --exclude='*' "$fromdir/" "$chkdir/" |
| 82 | |
| 83 | # Now, test if rsync excludes the same files. |
| 84 | |
| 85 | checkit "$RSYNC -avv --exclude-from=\"$excl\" \"$fromdir/\" \"$todir/\"" "$chkdir" "$todir" |
| 86 | |
| 87 | # Modify the chk dir by removing cvs-ignored files and then tweaking the dir times. |
| 88 | |
| 89 | rm "$chkdir"/foo/*.old |
| 90 | rm "$chkdir"/bar/down/to/foo/*.bak |
| 91 | rm "$chkdir"/bar/down/to/foo/*.junk |
| 92 | rm "$chkdir"/bar/down/to/home-cvs-exclude |
| 93 | rm "$chkdir"/mid/one-in-one-out |
| 94 | |
| 95 | $RSYNC -av --existing --include='*/' --exclude='*' "$fromdir/" "$chkdir/" |
| 96 | |
| 97 | # Now, test if rsync excludes the same files, this time with --cvs-exclude |
| 98 | # and --delete-excluded. |
| 99 | |
| 100 | checkit "$RSYNC -avvC --exclude-from=\"$excl\" \ |
| 101 | --delete-excluded \"$fromdir/\" \"$todir/\"" "$chkdir" "$todir" |
| 102 | |
| 103 | # The script would have aborted on error, so getting here means we've won. |
| 104 | exit 0 |