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