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