Commit | Line | Data |
---|---|---|
ff570659 WD |
1 | #! /bin/sh |
2 | ||
b62fd393 | 3 | # Copyright (C) 2003, 2004, 2005 by Wayne Davison <wayned@samba.org> |
ff570659 | 4 | |
c8d19f90 | 5 | # This program is distributable under the terms of the GNU GPL (see |
ff570659 WD |
6 | # COPYING). |
7 | ||
d048c2f2 | 8 | # Test rsync handling of exclude/include directives. |
ff570659 WD |
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 | |
ff570659 WD |
18 | # Build some files/dirs/links to copy |
19 | ||
ff570659 | 20 | makepath "$fromdir/foo/down/to/you" |
0314302e | 21 | makepath "$fromdir/foo/sub" |
ff570659 | 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" |
90d5b12e WD |
25 | makepath "$fromdir/new/keep/this" |
26 | makepath "$fromdir/new/lose/this" | |
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 |
0314302e | 35 | echo filtered-1 >"$fromdir/foo/file1" |
ff570659 | 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 | |
0314302e | 40 | - /file1 |
201a2fe5 | 41 | EOF |
0314302e | 42 | echo not-filtered-1 >"$fromdir/foo/sub/file1" |
bb558f67 | 43 | cat >"$fromdir/bar/.filt" <<EOF |
201a2fe5 | 44 | - home-cvs-exclude |
bb558f67 | 45 | dir-merge .filt2 |
201a2fe5 WD |
46 | + to |
47 | EOF | |
ead751c6 | 48 | echo cvsout >"$fromdir/bar/down/to/home-cvs-exclude" |
bb558f67 WD |
49 | cat >"$fromdir/bar/down/to/.filt2" <<EOF |
50 | - .filt2 | |
201a2fe5 | 51 | EOF |
bb558f67 | 52 | cat >"$fromdir/bar/down/to/foo/.filt2" <<EOF |
408aa7b2 WD |
53 | + *.junk |
54 | EOF | |
ff570659 | 55 | echo keeper >"$fromdir/bar/down/to/foo/file1" |
43a9d0e7 | 56 | echo cvsout >"$fromdir/bar/down/to/foo/file1.bak" |
ff570659 WD |
57 | echo gone >"$fromdir/bar/down/to/foo/file3" |
58 | echo lost >"$fromdir/bar/down/to/foo/file4" | |
bb558f67 | 59 | echo weird >"$fromdir/bar/down/to/foo/+ file3" |
408aa7b2 | 60 | echo cvsout-but-filtin >"$fromdir/bar/down/to/foo/file4.junk" |
ff570659 | 61 | echo smashed >"$fromdir/bar/down/to/foo/to" |
bb558f67 | 62 | cat >"$fromdir/bar/down/to/bar/.filt2" <<EOF |
408aa7b2 | 63 | - *.deep |
201a2fe5 | 64 | EOF |
408aa7b2 | 65 | echo filtout >"$fromdir/bar/down/to/bar/baz/file5.deep" |
201a2fe5 | 66 | # This one should be ineffectual |
bb558f67 | 67 | cat >"$fromdir/mid/.filt2" <<EOF |
201a2fe5 WD |
68 | - extra |
69 | EOF | |
43a9d0e7 WD |
70 | echo cvsout >"$fromdir/mid/one-in-one-out" |
71 | echo one-in-one-out >"$fromdir/mid/.cvsignore" | |
72 | echo cvsin >"$fromdir/mid/one-for-all" | |
bb558f67 | 73 | cat >"$fromdir/mid/.filt" <<EOF |
201a2fe5 WD |
74 | :C |
75 | EOF | |
ead751c6 | 76 | echo cvsin >"$fromdir/mid/for/one-in-one-out" |
ff570659 WD |
77 | echo expunged >"$fromdir/mid/for/foo/extra" |
78 | echo retained >"$fromdir/mid/for/foo/keep" | |
ff570659 | 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 | |
0314302e WD |
90 | # These should float at the end of the path. |
91 | + foo/s?b/ | |
ff570659 | 92 | - foo/*/ |
90d5b12e WD |
93 | # Test how /** differs from /*** |
94 | - new/keep/** | |
95 | - new/lose/*** | |
ff570659 WD |
96 | # Test some normal excludes. Competing lines are paired. |
97 | + t[o]/ | |
98 | - to | |
99 | + file4 | |
100 | - file[2-9] | |
101 | - /mid/for/foo/extra | |
102 | EOF | |
103 | ||
f1dd0f27 WD |
104 | cat >"$scratchdir/.cvsignore" <<EOF |
105 | home-cvs-exclude | |
106 | EOF | |
107 | ||
d048c2f2 WD |
108 | # Start with a check of --prune-empty-dirs: |
109 | $RSYNC -av -f -_foo/too/ -f -_foo/down/ -f -_foo/and/ -f -_new/ "$fromdir/" "$chkdir/" | |
7918f244 | 110 | checkit "$RSYNC -av --prune-empty-dirs '$fromdir/' '$todir/'" "$chkdir" "$todir" |
d048c2f2 | 111 | rm -rf "$todir" |
337a1a86 | 112 | |
d048c2f2 WD |
113 | # Add a directory symlink. |
114 | ln -s too "$fromdir/bar/down/to/foo/sym" | |
ff570659 | 115 | |
d048c2f2 | 116 | # Create chkdir with what we expect to be excluded. |
7918f244 | 117 | checkit "$RSYNC -avv '$fromdir/' '$chkdir/'" "$fromdir" "$chkdir" |
337a1a86 | 118 | sleep 1 # Ensures that the rm commands will tweak the directory times. |
ff570659 | 119 | rm -r "$chkdir"/foo/down |
093acc5d | 120 | rm -r "$chkdir"/mid/for/foo/and |
90d5b12e WD |
121 | rm -r "$chkdir"/new/keep/this |
122 | rm -r "$chkdir"/new/lose | |
ff570659 | 123 | rm "$chkdir"/foo/file[235-9] |
093acc5d | 124 | rm "$chkdir"/bar/down/to/foo/to "$chkdir"/bar/down/to/foo/file[235-9] |
ff570659 WD |
125 | rm "$chkdir"/mid/for/foo/extra |
126 | ||
337a1a86 WD |
127 | # Un-tweak the directory times in our first (weak) exclude test (though |
128 | # it's a good test of the --existing option). | |
129 | $RSYNC -av --existing --include='*/' --exclude='*' "$fromdir/" "$chkdir/" | |
ff570659 | 130 | |
337a1a86 | 131 | # Now, test if rsync excludes the same files. |
ff570659 | 132 | |
7918f244 WD |
133 | checkit "$RSYNC -avv --exclude-from='$excl' \ |
134 | --delete-during '$fromdir/' '$todir/'" "$chkdir" "$todir" | |
ff570659 | 135 | |
43a9d0e7 WD |
136 | # Modify the chk dir by removing cvs-ignored files and then tweaking the dir times. |
137 | ||
138 | rm "$chkdir"/foo/*.old | |
139 | rm "$chkdir"/bar/down/to/foo/*.bak | |
140 | rm "$chkdir"/bar/down/to/foo/*.junk | |
141 | rm "$chkdir"/bar/down/to/home-cvs-exclude | |
142 | rm "$chkdir"/mid/one-in-one-out | |
143 | ||
e7966626 | 144 | $RSYNC -av --existing --filter='exclude,! */' "$fromdir/" "$chkdir/" |
43a9d0e7 WD |
145 | |
146 | # Now, test if rsync excludes the same files, this time with --cvs-exclude | |
147 | # and --delete-excluded. | |
148 | ||
7918f244 WD |
149 | checkit "$RSYNC -avvC --filter='merge $excl' --delete-excluded \ |
150 | --delete-during '$fromdir/' '$todir/'" "$chkdir" "$todir" | |
201a2fe5 WD |
151 | |
152 | # Modify the chk dir for our merge-exclude test and then tweak the dir times. | |
153 | ||
201a2fe5 | 154 | rm "$chkdir"/foo/file1 |
408aa7b2 | 155 | rm "$chkdir"/bar/down/to/bar/baz/*.deep |
844810d6 WD |
156 | cp_touch "$fromdir"/bar/down/to/foo/*.junk "$chkdir"/bar/down/to/foo |
157 | cp_touch "$fromdir"/bar/down/to/foo/to "$chkdir"/bar/down/to/foo | |
201a2fe5 | 158 | |
bb558f67 | 159 | $RSYNC -av --existing -f 'show .filt*' -f 'hide,! */' --del "$fromdir/" "$todir/" |
408aa7b2 WD |
160 | |
161 | echo retained >"$todir"/bar/down/to/bar/baz/nodel.deep | |
844810d6 | 162 | cp_touch "$todir"/bar/down/to/bar/baz/nodel.deep "$chkdir"/bar/down/to/bar/baz |
408aa7b2 | 163 | |
346402dd | 164 | $RSYNC -av --existing --filter='-! */' "$fromdir/" "$chkdir/" |
201a2fe5 WD |
165 | |
166 | # Now, test if rsync excludes the same files, this time with a merge-exclude | |
167 | # file. | |
168 | ||
7918f244 | 169 | checkit "sed '/!/d' '$excl' | |
bb558f67 | 170 | $RSYNC -avv -f dir-merge_.filt -f merge_- \ |
7918f244 | 171 | --delete-during '$fromdir/' '$todir/'" "$chkdir" "$todir" |
408aa7b2 | 172 | |
bb558f67 | 173 | # Remove the files that will be deleted. |
408aa7b2 | 174 | |
bb558f67 WD |
175 | rm "$chkdir"/.filt |
176 | rm "$chkdir"/bar/.filt | |
177 | rm "$chkdir"/bar/down/to/.filt2 | |
178 | rm "$chkdir"/bar/down/to/foo/.filt2 | |
179 | rm "$chkdir"/bar/down/to/bar/.filt2 | |
180 | rm "$chkdir"/mid/.filt | |
408aa7b2 | 181 | |
a3e1363a | 182 | $RSYNC -av --protocol=28 --existing --include='*/' --exclude='*' "$fromdir/" "$chkdir/" |
408aa7b2 | 183 | |
bb558f67 WD |
184 | # Now, try the prior command with --delete-before and some side-specific |
185 | # rules. | |
408aa7b2 | 186 | |
7918f244 | 187 | checkit "sed '/!/d' '$excl' | |
bb558f67 | 188 | $RSYNC -avv -f :s_.filt -f .s_- -f P_nodel.deep \ |
7918f244 | 189 | --delete-before '$fromdir/' '$todir/'" "$chkdir" "$todir" |
43a9d0e7 | 190 | |
bb558f67 WD |
191 | # Next, we'll test some rule-restricted filter files. |
192 | ||
193 | cat >"$fromdir/bar/down/.excl" <<EOF | |
194 | file3 | |
195 | EOF | |
196 | cat >"$fromdir/bar/down/to/foo/.excl" <<EOF | |
197 | + file3 | |
198 | *.bak | |
199 | EOF | |
200 | $RSYNC -av --del "$fromdir/" "$chkdir/" | |
201 | rm "$chkdir/bar/down/to/foo/file1.bak" | |
202 | rm "$chkdir/bar/down/to/foo/file3" | |
203 | rm "$chkdir/bar/down/to/foo/+ file3" | |
9a338344 | 204 | $RSYNC -av --existing --filter='-! */' "$fromdir/" "$chkdir/" |
bb558f67 WD |
205 | $RSYNC -av --delete-excluded --exclude='*' "$fromdir/" "$todir/" |
206 | ||
207 | checkit "$RSYNC -avv -f dir-merge,-_.excl \ | |
7918f244 | 208 | '$fromdir/' '$todir/'" "$chkdir" "$todir" |
bb558f67 | 209 | |
4209f079 WD |
210 | relative_opts='--relative --chmod=Du+w --copy-unsafe-links' |
211 | $RSYNC -av $relative_opts "$fromdir/foo" "$chkdir/" | |
50cf2567 | 212 | rm -rf "$chkdir$fromdir/foo/down" |
4209f079 | 213 | $RSYNC -av $relative_opts --existing --filter='-! */' "$fromdir/foo" "$chkdir/" |
50cf2567 | 214 | |
7918f244 WD |
215 | checkit "$RSYNC -avv $relative_opts --exclude='$fromdir/foo/down' \ |
216 | '$fromdir/foo' '$todir'" "$chkdir$fromdir/foo" "$todir$fromdir/foo" | |
50cf2567 | 217 | |
05118158 | 218 | # The script would have aborted on error, so getting here means we've won. |
ff570659 | 219 | exit 0 |