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