Forgot to make sure that the dir-times on the chkdir got synced
[rsync/rsync.git] / testsuite / exclude.test
1 #! /bin/sh
2
3 # Copyright (C) 2003 by Wayne Davison <wayned@samba.org>
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
13 . "$suitedir/rsync.fns"
14
15 set -x
16
17 HOME="$scratchdir"
18 CVSIGNORE='*.junk'
19 export HOME CVSIGNORE
20
21 # Build some files/dirs/links to copy
22
23 makepath "$fromdir/foo/down/to/you"
24 makepath "$fromdir/bar/down/to/foo/too"
25 makepath "$fromdir/bar/down/to/bar/baz"
26 makepath "$fromdir/mid/for/foo/and/that/is/who"
27 cat >"$fromdir/.filt" <<EOF
28 exclude down
29 : .filt-temp
30 clear
31 - .filt
32 - *.bak
33 - *.old
34 EOF
35 echo kept >"$fromdir/foo/file1"
36 echo removed >"$fromdir/foo/file2"
37 echo cvsout >"$fromdir/foo/file2.old"
38 cat >"$fromdir/foo/.filt" <<EOF
39 include .filt
40 - file1
41 EOF
42 cat >"$fromdir/bar/.filt" <<EOF
43 - home-cvs-exclude
44 dir-merge .filt2
45 + to
46 EOF
47 echo cvsout >"$fromdir/bar/down/to/home-cvs-exclude"
48 cat >"$fromdir/bar/down/to/.filt2" <<EOF
49 - .filt2
50 EOF
51 cat >"$fromdir/bar/down/to/foo/.filt2" <<EOF
52 + *.junk
53 EOF
54 echo keeper >"$fromdir/bar/down/to/foo/file1"
55 echo cvsout >"$fromdir/bar/down/to/foo/file1.bak"
56 echo gone >"$fromdir/bar/down/to/foo/file3"
57 echo lost >"$fromdir/bar/down/to/foo/file4"
58 echo weird >"$fromdir/bar/down/to/foo/+ file3"
59 echo cvsout-but-filtin >"$fromdir/bar/down/to/foo/file4.junk"
60 echo smashed >"$fromdir/bar/down/to/foo/to"
61 cat >"$fromdir/bar/down/to/bar/.filt2" <<EOF
62 - *.deep
63 EOF
64 echo filtout >"$fromdir/bar/down/to/bar/baz/file5.deep"
65 # This one should be ineffectual
66 cat >"$fromdir/mid/.filt2" <<EOF
67 - extra
68 EOF
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"
72 cat >"$fromdir/mid/.filt" <<EOF
73 :C
74 EOF
75 echo cvsin >"$fromdir/mid/for/one-in-one-out"
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
80 # Setup our test exclude/include files.
81
82 excl="$scratchdir/exclude-from"
83 cat >"$excl" <<EOF
84 !
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
100 cat >"$scratchdir/.cvsignore" <<EOF
101 home-cvs-exclude
102 EOF
103
104 # Create the chk dir with what we expect to be excluded
105
106 checkit "$RSYNC -avv \"$fromdir/\" \"$chkdir/\"" "$fromdir" "$chkdir"
107
108 sleep 1 # Ensures that the rm commands will tweak the directory times.
109
110 rm -r "$chkdir"/foo/down
111 rm -r "$chkdir"/mid/for/foo/and
112 rm "$chkdir"/foo/file[235-9]
113 rm "$chkdir"/bar/down/to/foo/to "$chkdir"/bar/down/to/foo/file[235-9]
114 rm "$chkdir"/mid/for/foo/extra
115
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/"
119
120 # Now, test if rsync excludes the same files.
121
122 checkit "$RSYNC -avv --exclude-from=\"$excl\" \
123     --delete-during \"$fromdir/\" \"$todir/\"" "$chkdir" "$todir"
124
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
133 $RSYNC -av --existing --filter='exclude,! */' "$fromdir/" "$chkdir/"
134
135 # Now, test if rsync excludes the same files, this time with --cvs-exclude
136 # and --delete-excluded.
137
138 checkit "$RSYNC -avvC --filter=\"merge $excl\" --delete-excluded \
139     --delete-during \"$fromdir/\" \"$todir/\"" "$chkdir" "$todir"
140
141 # Modify the chk dir for our merge-exclude test and then tweak the dir times.
142
143 rm "$chkdir"/foo/file1
144 rm "$chkdir"/bar/down/to/bar/baz/*.deep
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
148 $RSYNC -av --existing -f 'show .filt*' -f 'hide,! */' --del "$fromdir/" "$todir/"
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
153 $RSYNC -av --existing --filter='-! */' "$fromdir/" "$chkdir/"
154
155 # Now, test if rsync excludes the same files, this time with a merge-exclude
156 # file.
157
158 checkit "sed '/!/d' \"$excl\" |
159     $RSYNC -avv -f dir-merge_.filt -f merge_- \
160     --delete-during \"$fromdir/\" \"$todir/\"" "$chkdir" "$todir"
161
162 # Remove the files that will be deleted.
163
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
170
171 $RSYNC -av --existing --filter='-! */' "$fromdir/" "$chkdir/"
172
173 # Now, try the prior command with --delete-before and some side-specific
174 # rules.
175
176 checkit "sed '/!/d' \"$excl\" |
177     $RSYNC -avv -f :s_.filt -f .s_- -f P_nodel.deep \
178     --delete-before \"$fromdir/\" \"$todir/\"" "$chkdir" "$todir"
179
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"
193 $RSYNC -av --existing --filter='-! */' "$fromdir/" "$chkdir/"
194 $RSYNC -av --delete-excluded --exclude='*' "$fromdir/" "$todir/"
195
196 checkit "$RSYNC -avv -f dir-merge,-_.excl \
197     \"$fromdir/\" \"$todir/\"" "$chkdir" "$todir"
198
199 # The script would have aborted on error, so getting here means we've won.
200 exit 0