- For every file that we send off to the receiver, mark it with
[rsync/rsync.git] / testsuite / exclude.test
... / ...
CommitLineData
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
15set -x
16
17HOME="$scratchdir"
18CVSIGNORE='*.junk'
19export HOME CVSIGNORE
20
21# Build some files/dirs/links to copy
22
23makepath "$fromdir/foo/down/to/you"
24makepath "$fromdir/bar/down/to/foo/too"
25makepath "$fromdir/bar/down/to/bar/baz"
26makepath "$fromdir/mid/for/foo/and/that/is/who"
27cat >"$fromdir/.filt" <<EOF
28exclude down
29: .filt-temp
30clear
31- .filt
32- *.bak
33- *.old
34EOF
35echo kept >"$fromdir/foo/file1"
36echo removed >"$fromdir/foo/file2"
37echo cvsout >"$fromdir/foo/file2.old"
38cat >"$fromdir/foo/.filt" <<EOF
39include .filt
40- file1
41EOF
42cat >"$fromdir/bar/.filt" <<EOF
43- home-cvs-exclude
44dir-merge .filt2
45+ to
46EOF
47echo cvsout >"$fromdir/bar/down/to/home-cvs-exclude"
48cat >"$fromdir/bar/down/to/.filt2" <<EOF
49- .filt2
50EOF
51cat >"$fromdir/bar/down/to/foo/.filt2" <<EOF
52+ *.junk
53EOF
54echo keeper >"$fromdir/bar/down/to/foo/file1"
55echo cvsout >"$fromdir/bar/down/to/foo/file1.bak"
56echo gone >"$fromdir/bar/down/to/foo/file3"
57echo lost >"$fromdir/bar/down/to/foo/file4"
58echo weird >"$fromdir/bar/down/to/foo/+ file3"
59echo cvsout-but-filtin >"$fromdir/bar/down/to/foo/file4.junk"
60echo smashed >"$fromdir/bar/down/to/foo/to"
61cat >"$fromdir/bar/down/to/bar/.filt2" <<EOF
62- *.deep
63EOF
64echo filtout >"$fromdir/bar/down/to/bar/baz/file5.deep"
65# This one should be ineffectual
66cat >"$fromdir/mid/.filt2" <<EOF
67- extra
68EOF
69echo cvsout >"$fromdir/mid/one-in-one-out"
70echo one-in-one-out >"$fromdir/mid/.cvsignore"
71echo cvsin >"$fromdir/mid/one-for-all"
72cat >"$fromdir/mid/.filt" <<EOF
73:C
74EOF
75echo cvsin >"$fromdir/mid/for/one-in-one-out"
76echo expunged >"$fromdir/mid/for/foo/extra"
77echo retained >"$fromdir/mid/for/foo/keep"
78ln -s too "$fromdir/bar/down/to/foo/sym"
79
80# Setup our test exclude/include files.
81
82excl="$scratchdir/exclude-from"
83cat >"$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
98EOF
99
100cat >"$scratchdir/.cvsignore" <<EOF
101home-cvs-exclude
102EOF
103
104# Create the chk dir with what we expect to be excluded
105
106checkit "$RSYNC -avv \"$fromdir/\" \"$chkdir/\"" "$fromdir" "$chkdir"
107
108sleep 1 # Ensures that the rm commands will tweak the directory times.
109
110rm -r "$chkdir"/foo/down
111rm -r "$chkdir"/mid/for/foo/and
112rm "$chkdir"/foo/file[235-9]
113rm "$chkdir"/bar/down/to/foo/to "$chkdir"/bar/down/to/foo/file[235-9]
114rm "$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
122checkit "$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
127rm "$chkdir"/foo/*.old
128rm "$chkdir"/bar/down/to/foo/*.bak
129rm "$chkdir"/bar/down/to/foo/*.junk
130rm "$chkdir"/bar/down/to/home-cvs-exclude
131rm "$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
138checkit "$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
143rm "$chkdir"/foo/file1
144rm "$chkdir"/bar/down/to/bar/baz/*.deep
145cp -p "$fromdir"/bar/down/to/foo/*.junk "$chkdir"/bar/down/to/foo
146cp -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
150echo retained >"$todir"/bar/down/to/bar/baz/nodel.deep
151cp -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
158checkit "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
164rm "$chkdir"/.filt
165rm "$chkdir"/bar/.filt
166rm "$chkdir"/bar/down/to/.filt2
167rm "$chkdir"/bar/down/to/foo/.filt2
168rm "$chkdir"/bar/down/to/bar/.filt2
169rm "$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
176checkit "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
182cat >"$fromdir/bar/down/.excl" <<EOF
183file3
184EOF
185cat >"$fromdir/bar/down/to/foo/.excl" <<EOF
186+ file3
187*.bak
188EOF
189$RSYNC -av --del "$fromdir/" "$chkdir/"
190rm "$chkdir/bar/down/to/foo/file1.bak"
191rm "$chkdir/bar/down/to/foo/file3"
192rm "$chkdir/bar/down/to/foo/+ file3"
193$RSYNC -av --existing --filter='-! */' "$fromdir/" "$chkdir/"
194$RSYNC -av --delete-excluded --exclude='*' "$fromdir/" "$todir/"
195
196checkit "$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.
200exit 0