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 | ||
7892e5ac | 13 | . "$suitedir/rsync.fns" |
ff570659 WD |
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 | ||
ff570659 WD |
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" | |
201a2fe5 WD |
26 | cat >"$fromdir/.excl" <<EOF |
27 | - down | |
28 | : .excl-temp | |
29 | ! | |
30 | - .excl | |
31 | - *.bak | |
32 | - *.old | |
33 | - *.junk | |
34 | EOF | |
ff570659 WD |
35 | echo kept >"$fromdir/foo/file1" |
36 | echo removed >"$fromdir/foo/file2" | |
43a9d0e7 | 37 | echo cvsout >"$fromdir/foo/file2.old" |
201a2fe5 WD |
38 | cat >"$fromdir/foo/.excl" <<EOF |
39 | + .excl | |
40 | - file1 | |
41 | EOF | |
42 | cat >"$fromdir/bar/.excl" <<EOF | |
43 | - home-cvs-exclude | |
44 | : .excl2 | |
45 | + to | |
46 | EOF | |
ead751c6 | 47 | echo cvsout >"$fromdir/bar/down/to/home-cvs-exclude" |
201a2fe5 WD |
48 | cat >"$fromdir/bar/down/to/.excl2" <<EOF |
49 | - .excl2 | |
50 | EOF | |
ff570659 | 51 | echo keeper >"$fromdir/bar/down/to/foo/file1" |
43a9d0e7 | 52 | echo cvsout >"$fromdir/bar/down/to/foo/file1.bak" |
ff570659 WD |
53 | echo gone >"$fromdir/bar/down/to/foo/file3" |
54 | echo lost >"$fromdir/bar/down/to/foo/file4" | |
43a9d0e7 | 55 | echo cvsout >"$fromdir/bar/down/to/foo/file4.junk" |
ff570659 | 56 | echo smashed >"$fromdir/bar/down/to/foo/to" |
201a2fe5 WD |
57 | cat >"$fromdir/bar/down/to/foo/.excl2" <<EOF |
58 | + *.junk | |
59 | EOF | |
60 | # This one should be ineffectual | |
61 | cat >"$fromdir/mid/.excl2" <<EOF | |
62 | - extra | |
63 | EOF | |
43a9d0e7 WD |
64 | echo cvsout >"$fromdir/mid/one-in-one-out" |
65 | echo one-in-one-out >"$fromdir/mid/.cvsignore" | |
66 | echo cvsin >"$fromdir/mid/one-for-all" | |
201a2fe5 WD |
67 | cat >"$fromdir/mid/.excl" <<EOF |
68 | :C | |
69 | EOF | |
ead751c6 | 70 | echo cvsin >"$fromdir/mid/for/one-in-one-out" |
ff570659 WD |
71 | echo expunged >"$fromdir/mid/for/foo/extra" |
72 | echo retained >"$fromdir/mid/for/foo/keep" | |
73 | ln -s too "$fromdir/bar/down/to/foo/sym" | |
74 | ||
f1dd0f27 | 75 | # Setup our test exclude/include files. |
ff570659 | 76 | |
ff570659 WD |
77 | excl="$scratchdir/exclude-from" |
78 | cat >"$excl" <<EOF | |
201a2fe5 | 79 | ! |
ff570659 WD |
80 | # If the second line of these two lines does anything, it's a bug. |
81 | + **/bar | |
82 | - /bar | |
83 | # This should match against the whole path, not just the name. | |
84 | + foo**too | |
85 | # This should float at the end of the path. | |
86 | - foo/*/ | |
87 | # Test some normal excludes. Competing lines are paired. | |
88 | + t[o]/ | |
89 | - to | |
90 | + file4 | |
91 | - file[2-9] | |
92 | - /mid/for/foo/extra | |
93 | EOF | |
94 | ||
f1dd0f27 WD |
95 | cat >"$scratchdir/.cvsignore" <<EOF |
96 | home-cvs-exclude | |
97 | EOF | |
98 | ||
ff570659 | 99 | # Create the chk dir with what we expect to be excluded |
337a1a86 | 100 | |
ff570659 WD |
101 | checkit "$RSYNC -avv \"$fromdir/\" \"$chkdir/\"" "$fromdir" "$chkdir" |
102 | ||
337a1a86 | 103 | sleep 1 # Ensures that the rm commands will tweak the directory times. |
ff570659 | 104 | |
ff570659 | 105 | rm -r "$chkdir"/foo/down |
093acc5d | 106 | rm -r "$chkdir"/mid/for/foo/and |
ff570659 | 107 | rm "$chkdir"/foo/file[235-9] |
093acc5d | 108 | rm "$chkdir"/bar/down/to/foo/to "$chkdir"/bar/down/to/foo/file[235-9] |
ff570659 WD |
109 | rm "$chkdir"/mid/for/foo/extra |
110 | ||
337a1a86 WD |
111 | # Un-tweak the directory times in our first (weak) exclude test (though |
112 | # it's a good test of the --existing option). | |
113 | $RSYNC -av --existing --include='*/' --exclude='*' "$fromdir/" "$chkdir/" | |
ff570659 | 114 | |
337a1a86 | 115 | # Now, test if rsync excludes the same files. |
ff570659 | 116 | |
201a2fe5 WD |
117 | checkit "$RSYNC -avv --exclude-from=\"$excl\" \ |
118 | --delete \"$fromdir/\" \"$todir/\"" "$chkdir" "$todir" | |
ff570659 | 119 | |
43a9d0e7 WD |
120 | # Modify the chk dir by removing cvs-ignored files and then tweaking the dir times. |
121 | ||
122 | rm "$chkdir"/foo/*.old | |
123 | rm "$chkdir"/bar/down/to/foo/*.bak | |
124 | rm "$chkdir"/bar/down/to/foo/*.junk | |
125 | rm "$chkdir"/bar/down/to/home-cvs-exclude | |
126 | rm "$chkdir"/mid/one-in-one-out | |
127 | ||
128 | $RSYNC -av --existing --include='*/' --exclude='*' "$fromdir/" "$chkdir/" | |
129 | ||
130 | # Now, test if rsync excludes the same files, this time with --cvs-exclude | |
131 | # and --delete-excluded. | |
132 | ||
201a2fe5 WD |
133 | checkit "$RSYNC -avvC --filter=\". $excl\" \ |
134 | --delete-excluded \"$fromdir/\" \"$todir/\"" "$chkdir" "$todir" | |
135 | ||
136 | # Modify the chk dir for our merge-exclude test and then tweak the dir times. | |
137 | ||
138 | rm "$chkdir"/.excl | |
139 | rm "$chkdir"/foo/file1 | |
140 | rm "$chkdir"/bar/.excl | |
141 | rm "$chkdir"/bar/down/to/.excl2 | |
142 | rm "$chkdir"/bar/down/to/foo/.excl2 | |
143 | rm "$chkdir"/mid/.excl | |
144 | cp -p "$fromdir"/bar/down/to/foo/*.junk "$chkdir"/bar/down/to/foo | |
145 | cp -p "$fromdir"/bar/down/to/foo/to "$chkdir"/bar/down/to/foo | |
146 | ||
147 | $RSYNC -av --existing --include='*/' --exclude='*' "$fromdir/" "$chkdir/" | |
148 | ||
149 | # Now, test if rsync excludes the same files, this time with a merge-exclude | |
150 | # file. | |
151 | ||
152 | checkit "sed '/!/d' \"$excl\" | $RSYNC -avv -f :_.excl -f ._- \ | |
f1dd0f27 | 153 | --delete-excluded \"$fromdir/\" \"$todir/\"" "$chkdir" "$todir" |
43a9d0e7 | 154 | |
05118158 | 155 | # The script would have aborted on error, so getting here means we've won. |
ff570659 | 156 | exit 0 |