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