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