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