Commit | Line | Data |
---|---|---|
ff570659 WD |
1 | #! /bin/sh |
2 | ||
b62fd393 | 3 | # Copyright (C) 2003, 2004, 2005 by Wayne Davison <wayned@samba.org> |
ff570659 WD |
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 | 14 | |
43a9d0e7 | 15 | CVSIGNORE='*.junk' |
2b7dab68 | 16 | export CVSIGNORE |
43a9d0e7 | 17 | |
13725744 WD |
18 | set -x |
19 | ||
ff570659 WD |
20 | # Build some files/dirs/links to copy |
21 | ||
ff570659 | 22 | makepath "$fromdir/foo/down/to/you" |
0314302e | 23 | makepath "$fromdir/foo/sub" |
ff570659 | 24 | makepath "$fromdir/bar/down/to/foo/too" |
408aa7b2 | 25 | makepath "$fromdir/bar/down/to/bar/baz" |
ff570659 | 26 | makepath "$fromdir/mid/for/foo/and/that/is/who" |
90d5b12e WD |
27 | makepath "$fromdir/new/keep/this" |
28 | makepath "$fromdir/new/lose/this" | |
bb558f67 | 29 | cat >"$fromdir/.filt" <<EOF |
e7966626 | 30 | exclude down |
bb558f67 | 31 | : .filt-temp |
e7966626 | 32 | clear |
bb558f67 | 33 | - .filt |
201a2fe5 WD |
34 | - *.bak |
35 | - *.old | |
201a2fe5 | 36 | EOF |
0314302e | 37 | echo filtered-1 >"$fromdir/foo/file1" |
ff570659 | 38 | echo removed >"$fromdir/foo/file2" |
43a9d0e7 | 39 | echo cvsout >"$fromdir/foo/file2.old" |
bb558f67 WD |
40 | cat >"$fromdir/foo/.filt" <<EOF |
41 | include .filt | |
0314302e | 42 | - /file1 |
201a2fe5 | 43 | EOF |
0314302e | 44 | echo not-filtered-1 >"$fromdir/foo/sub/file1" |
bb558f67 | 45 | cat >"$fromdir/bar/.filt" <<EOF |
201a2fe5 | 46 | - home-cvs-exclude |
bb558f67 | 47 | dir-merge .filt2 |
201a2fe5 WD |
48 | + to |
49 | EOF | |
ead751c6 | 50 | echo cvsout >"$fromdir/bar/down/to/home-cvs-exclude" |
bb558f67 WD |
51 | cat >"$fromdir/bar/down/to/.filt2" <<EOF |
52 | - .filt2 | |
201a2fe5 | 53 | EOF |
bb558f67 | 54 | cat >"$fromdir/bar/down/to/foo/.filt2" <<EOF |
408aa7b2 WD |
55 | + *.junk |
56 | EOF | |
ff570659 | 57 | echo keeper >"$fromdir/bar/down/to/foo/file1" |
43a9d0e7 | 58 | echo cvsout >"$fromdir/bar/down/to/foo/file1.bak" |
ff570659 WD |
59 | echo gone >"$fromdir/bar/down/to/foo/file3" |
60 | echo lost >"$fromdir/bar/down/to/foo/file4" | |
bb558f67 | 61 | echo weird >"$fromdir/bar/down/to/foo/+ file3" |
408aa7b2 | 62 | echo cvsout-but-filtin >"$fromdir/bar/down/to/foo/file4.junk" |
ff570659 | 63 | echo smashed >"$fromdir/bar/down/to/foo/to" |
bb558f67 | 64 | cat >"$fromdir/bar/down/to/bar/.filt2" <<EOF |
408aa7b2 | 65 | - *.deep |
201a2fe5 | 66 | EOF |
408aa7b2 | 67 | echo filtout >"$fromdir/bar/down/to/bar/baz/file5.deep" |
201a2fe5 | 68 | # This one should be ineffectual |
bb558f67 | 69 | cat >"$fromdir/mid/.filt2" <<EOF |
201a2fe5 WD |
70 | - extra |
71 | EOF | |
43a9d0e7 WD |
72 | echo cvsout >"$fromdir/mid/one-in-one-out" |
73 | echo one-in-one-out >"$fromdir/mid/.cvsignore" | |
74 | echo cvsin >"$fromdir/mid/one-for-all" | |
bb558f67 | 75 | cat >"$fromdir/mid/.filt" <<EOF |
201a2fe5 WD |
76 | :C |
77 | EOF | |
ead751c6 | 78 | echo cvsin >"$fromdir/mid/for/one-in-one-out" |
ff570659 WD |
79 | echo expunged >"$fromdir/mid/for/foo/extra" |
80 | echo retained >"$fromdir/mid/for/foo/keep" | |
81 | ln -s too "$fromdir/bar/down/to/foo/sym" | |
82 | ||
f1dd0f27 | 83 | # Setup our test exclude/include files. |
ff570659 | 84 | |
ff570659 WD |
85 | excl="$scratchdir/exclude-from" |
86 | cat >"$excl" <<EOF | |
201a2fe5 | 87 | ! |
ff570659 WD |
88 | # If the second line of these two lines does anything, it's a bug. |
89 | + **/bar | |
90 | - /bar | |
91 | # This should match against the whole path, not just the name. | |
92 | + foo**too | |
0314302e WD |
93 | # These should float at the end of the path. |
94 | + foo/s?b/ | |
ff570659 | 95 | - foo/*/ |
90d5b12e WD |
96 | # Test how /** differs from /*** |
97 | - new/keep/** | |
98 | - new/lose/*** | |
ff570659 WD |
99 | # Test some normal excludes. Competing lines are paired. |
100 | + t[o]/ | |
101 | - to | |
102 | + file4 | |
103 | - file[2-9] | |
104 | - /mid/for/foo/extra | |
105 | EOF | |
106 | ||
f1dd0f27 WD |
107 | cat >"$scratchdir/.cvsignore" <<EOF |
108 | home-cvs-exclude | |
109 | EOF | |
110 | ||
ff570659 | 111 | # Create the chk dir with what we expect to be excluded |
337a1a86 | 112 | |
ff570659 WD |
113 | checkit "$RSYNC -avv \"$fromdir/\" \"$chkdir/\"" "$fromdir" "$chkdir" |
114 | ||
337a1a86 | 115 | sleep 1 # Ensures that the rm commands will tweak the directory times. |
ff570659 | 116 | |
ff570659 | 117 | rm -r "$chkdir"/foo/down |
093acc5d | 118 | rm -r "$chkdir"/mid/for/foo/and |
90d5b12e WD |
119 | rm -r "$chkdir"/new/keep/this |
120 | rm -r "$chkdir"/new/lose | |
ff570659 | 121 | rm "$chkdir"/foo/file[235-9] |
093acc5d | 122 | rm "$chkdir"/bar/down/to/foo/to "$chkdir"/bar/down/to/foo/file[235-9] |
ff570659 WD |
123 | rm "$chkdir"/mid/for/foo/extra |
124 | ||
337a1a86 WD |
125 | # Un-tweak the directory times in our first (weak) exclude test (though |
126 | # it's a good test of the --existing option). | |
127 | $RSYNC -av --existing --include='*/' --exclude='*' "$fromdir/" "$chkdir/" | |
ff570659 | 128 | |
337a1a86 | 129 | # Now, test if rsync excludes the same files. |
ff570659 | 130 | |
201a2fe5 | 131 | checkit "$RSYNC -avv --exclude-from=\"$excl\" \ |
408aa7b2 | 132 | --delete-during \"$fromdir/\" \"$todir/\"" "$chkdir" "$todir" |
ff570659 | 133 | |
43a9d0e7 WD |
134 | # Modify the chk dir by removing cvs-ignored files and then tweaking the dir times. |
135 | ||
136 | rm "$chkdir"/foo/*.old | |
137 | rm "$chkdir"/bar/down/to/foo/*.bak | |
138 | rm "$chkdir"/bar/down/to/foo/*.junk | |
139 | rm "$chkdir"/bar/down/to/home-cvs-exclude | |
140 | rm "$chkdir"/mid/one-in-one-out | |
141 | ||
e7966626 | 142 | $RSYNC -av --existing --filter='exclude,! */' "$fromdir/" "$chkdir/" |
43a9d0e7 WD |
143 | |
144 | # Now, test if rsync excludes the same files, this time with --cvs-exclude | |
145 | # and --delete-excluded. | |
146 | ||
e7966626 | 147 | checkit "$RSYNC -avvC --filter=\"merge $excl\" --delete-excluded \ |
408aa7b2 | 148 | --delete-during \"$fromdir/\" \"$todir/\"" "$chkdir" "$todir" |
201a2fe5 WD |
149 | |
150 | # Modify the chk dir for our merge-exclude test and then tweak the dir times. | |
151 | ||
201a2fe5 | 152 | rm "$chkdir"/foo/file1 |
408aa7b2 | 153 | rm "$chkdir"/bar/down/to/bar/baz/*.deep |
201a2fe5 WD |
154 | cp -p "$fromdir"/bar/down/to/foo/*.junk "$chkdir"/bar/down/to/foo |
155 | cp -p "$fromdir"/bar/down/to/foo/to "$chkdir"/bar/down/to/foo | |
156 | ||
bb558f67 | 157 | $RSYNC -av --existing -f 'show .filt*' -f 'hide,! */' --del "$fromdir/" "$todir/" |
408aa7b2 WD |
158 | |
159 | echo retained >"$todir"/bar/down/to/bar/baz/nodel.deep | |
160 | cp -p "$todir"/bar/down/to/bar/baz/nodel.deep "$chkdir"/bar/down/to/bar/baz | |
161 | ||
346402dd | 162 | $RSYNC -av --existing --filter='-! */' "$fromdir/" "$chkdir/" |
201a2fe5 WD |
163 | |
164 | # Now, test if rsync excludes the same files, this time with a merge-exclude | |
165 | # file. | |
166 | ||
408aa7b2 | 167 | checkit "sed '/!/d' \"$excl\" | |
bb558f67 | 168 | $RSYNC -avv -f dir-merge_.filt -f merge_- \ |
408aa7b2 WD |
169 | --delete-during \"$fromdir/\" \"$todir/\"" "$chkdir" "$todir" |
170 | ||
bb558f67 | 171 | # Remove the files that will be deleted. |
408aa7b2 | 172 | |
bb558f67 WD |
173 | rm "$chkdir"/.filt |
174 | rm "$chkdir"/bar/.filt | |
175 | rm "$chkdir"/bar/down/to/.filt2 | |
176 | rm "$chkdir"/bar/down/to/foo/.filt2 | |
177 | rm "$chkdir"/bar/down/to/bar/.filt2 | |
178 | rm "$chkdir"/mid/.filt | |
408aa7b2 | 179 | |
a3e1363a | 180 | $RSYNC -av --protocol=28 --existing --include='*/' --exclude='*' "$fromdir/" "$chkdir/" |
408aa7b2 | 181 | |
bb558f67 WD |
182 | # Now, try the prior command with --delete-before and some side-specific |
183 | # rules. | |
408aa7b2 WD |
184 | |
185 | checkit "sed '/!/d' \"$excl\" | | |
bb558f67 | 186 | $RSYNC -avv -f :s_.filt -f .s_- -f P_nodel.deep \ |
408aa7b2 | 187 | --delete-before \"$fromdir/\" \"$todir/\"" "$chkdir" "$todir" |
43a9d0e7 | 188 | |
bb558f67 WD |
189 | # Next, we'll test some rule-restricted filter files. |
190 | ||
191 | cat >"$fromdir/bar/down/.excl" <<EOF | |
192 | file3 | |
193 | EOF | |
194 | cat >"$fromdir/bar/down/to/foo/.excl" <<EOF | |
195 | + file3 | |
196 | *.bak | |
197 | EOF | |
198 | $RSYNC -av --del "$fromdir/" "$chkdir/" | |
199 | rm "$chkdir/bar/down/to/foo/file1.bak" | |
200 | rm "$chkdir/bar/down/to/foo/file3" | |
201 | rm "$chkdir/bar/down/to/foo/+ file3" | |
9a338344 | 202 | $RSYNC -av --existing --filter='-! */' "$fromdir/" "$chkdir/" |
bb558f67 WD |
203 | $RSYNC -av --delete-excluded --exclude='*' "$fromdir/" "$todir/" |
204 | ||
205 | checkit "$RSYNC -avv -f dir-merge,-_.excl \ | |
206 | \"$fromdir/\" \"$todir/\"" "$chkdir" "$todir" | |
207 | ||
05118158 | 208 | # The script would have aborted on error, so getting here means we've won. |
ff570659 | 209 | exit 0 |