Factor out common logic of unchanged_attrs and itemize into report_ATTR
[rsync/rsync.git] / testsuite / exclude.test
... / ...
CommitLineData
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
15CVSIGNORE='*.junk'
16export CVSIGNORE
17
18# Build some files/dirs/links to copy
19
20makepath "$fromdir/foo/down/to/you"
21makepath "$fromdir/foo/sub"
22makepath "$fromdir/bar/down/to/foo/too"
23makepath "$fromdir/bar/down/to/bar/baz"
24makepath "$fromdir/mid/for/foo/and/that/is/who"
25makepath "$fromdir/new/keep/this"
26makepath "$fromdir/new/lose/this"
27cat >"$fromdir/.filt" <<EOF
28exclude down
29: .filt-temp
30clear
31- .filt
32- *.bak
33- *.old
34EOF
35echo filtered-1 >"$fromdir/foo/file1"
36echo removed >"$fromdir/foo/file2"
37echo cvsout >"$fromdir/foo/file2.old"
38cat >"$fromdir/foo/.filt" <<EOF
39include .filt
40- /file1
41EOF
42echo not-filtered-1 >"$fromdir/foo/sub/file1"
43cat >"$fromdir/bar/.filt" <<EOF
44- home-cvs-exclude
45dir-merge .filt2
46+ to
47EOF
48echo cvsout >"$fromdir/bar/down/to/home-cvs-exclude"
49cat >"$fromdir/bar/down/to/.filt2" <<EOF
50- .filt2
51EOF
52cat >"$fromdir/bar/down/to/foo/.filt2" <<EOF
53+ *.junk
54EOF
55echo keeper >"$fromdir/bar/down/to/foo/file1"
56echo cvsout >"$fromdir/bar/down/to/foo/file1.bak"
57echo gone >"$fromdir/bar/down/to/foo/file3"
58echo lost >"$fromdir/bar/down/to/foo/file4"
59echo weird >"$fromdir/bar/down/to/foo/+ file3"
60echo cvsout-but-filtin >"$fromdir/bar/down/to/foo/file4.junk"
61echo smashed >"$fromdir/bar/down/to/foo/to"
62cat >"$fromdir/bar/down/to/bar/.filt2" <<EOF
63- *.deep
64EOF
65echo filtout >"$fromdir/bar/down/to/bar/baz/file5.deep"
66# This one should be ineffectual
67cat >"$fromdir/mid/.filt2" <<EOF
68- extra
69EOF
70echo cvsout >"$fromdir/mid/one-in-one-out"
71echo one-in-one-out >"$fromdir/mid/.cvsignore"
72echo cvsin >"$fromdir/mid/one-for-all"
73cat >"$fromdir/mid/.filt" <<EOF
74:C
75EOF
76echo cvsin >"$fromdir/mid/for/one-in-one-out"
77echo expunged >"$fromdir/mid/for/foo/extra"
78echo retained >"$fromdir/mid/for/foo/keep"
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# These should float at the end of the path.
91+ foo/s?b/
92- foo/*/
93# Test how /** differs from /***
94- new/keep/**
95- new/lose/***
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
102EOF
103
104cat >"$scratchdir/.cvsignore" <<EOF
105home-cvs-exclude
106EOF
107
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/"
110checkit "$RSYNC -av --prune-empty-dirs '$fromdir/' '$todir/'" "$chkdir" "$todir"
111rm -rf "$todir"
112
113# Add a directory symlink.
114ln -s too "$fromdir/bar/down/to/foo/sym"
115
116# Create chkdir with what we expect to be excluded.
117checkit "$RSYNC -avv '$fromdir/' '$chkdir/'" "$fromdir" "$chkdir"
118sleep 1 # Ensures that the rm commands will tweak the directory times.
119rm -r "$chkdir"/foo/down
120rm -r "$chkdir"/mid/for/foo/and
121rm -r "$chkdir"/new/keep/this
122rm -r "$chkdir"/new/lose
123rm "$chkdir"/foo/file[235-9]
124rm "$chkdir"/bar/down/to/foo/to "$chkdir"/bar/down/to/foo/file[235-9]
125rm "$chkdir"/mid/for/foo/extra
126
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/"
130
131# Now, test if rsync excludes the same files.
132
133checkit "$RSYNC -avv --exclude-from='$excl' \
134 --delete-during '$fromdir/' '$todir/'" "$chkdir" "$todir"
135
136# Modify the chk dir by removing cvs-ignored files and then tweaking the dir times.
137
138rm "$chkdir"/foo/*.old
139rm "$chkdir"/bar/down/to/foo/*.bak
140rm "$chkdir"/bar/down/to/foo/*.junk
141rm "$chkdir"/bar/down/to/home-cvs-exclude
142rm "$chkdir"/mid/one-in-one-out
143
144$RSYNC -av --existing --filter='exclude,! */' "$fromdir/" "$chkdir/"
145
146# Now, test if rsync excludes the same files, this time with --cvs-exclude
147# and --delete-excluded.
148
149checkit "$RSYNC -avvC --filter='merge $excl' --delete-excluded \
150 --delete-during '$fromdir/' '$todir/'" "$chkdir" "$todir"
151
152# Modify the chk dir for our merge-exclude test and then tweak the dir times.
153
154rm "$chkdir"/foo/file1
155rm "$chkdir"/bar/down/to/bar/baz/*.deep
156cp_touch "$fromdir"/bar/down/to/foo/*.junk "$chkdir"/bar/down/to/foo
157cp_touch "$fromdir"/bar/down/to/foo/to "$chkdir"/bar/down/to/foo
158
159$RSYNC -av --existing -f 'show .filt*' -f 'hide,! */' --del "$fromdir/" "$todir/"
160
161echo retained >"$todir"/bar/down/to/bar/baz/nodel.deep
162cp_touch "$todir"/bar/down/to/bar/baz/nodel.deep "$chkdir"/bar/down/to/bar/baz
163
164$RSYNC -av --existing --filter='-! */' "$fromdir/" "$chkdir/"
165
166# Now, test if rsync excludes the same files, this time with a merge-exclude
167# file.
168
169checkit "sed '/!/d' '$excl' |
170 $RSYNC -avv -f dir-merge_.filt -f merge_- \
171 --delete-during '$fromdir/' '$todir/'" "$chkdir" "$todir"
172
173# Remove the files that will be deleted.
174
175rm "$chkdir"/.filt
176rm "$chkdir"/bar/.filt
177rm "$chkdir"/bar/down/to/.filt2
178rm "$chkdir"/bar/down/to/foo/.filt2
179rm "$chkdir"/bar/down/to/bar/.filt2
180rm "$chkdir"/mid/.filt
181
182$RSYNC -av --protocol=28 --existing --include='*/' --exclude='*' "$fromdir/" "$chkdir/"
183
184# Now, try the prior command with --delete-before and some side-specific
185# rules.
186
187checkit "sed '/!/d' '$excl' |
188 $RSYNC -avv -f :s_.filt -f .s_- -f P_nodel.deep \
189 --delete-before '$fromdir/' '$todir/'" "$chkdir" "$todir"
190
191# Next, we'll test some rule-restricted filter files.
192
193cat >"$fromdir/bar/down/.excl" <<EOF
194file3
195EOF
196cat >"$fromdir/bar/down/to/foo/.excl" <<EOF
197+ file3
198*.bak
199EOF
200$RSYNC -av --del "$fromdir/" "$chkdir/"
201rm "$chkdir/bar/down/to/foo/file1.bak"
202rm "$chkdir/bar/down/to/foo/file3"
203rm "$chkdir/bar/down/to/foo/+ file3"
204$RSYNC -av --existing --filter='-! */' "$fromdir/" "$chkdir/"
205$RSYNC -av --delete-excluded --exclude='*' "$fromdir/" "$todir/"
206
207checkit "$RSYNC -avv -f dir-merge,-_.excl \
208 '$fromdir/' '$todir/'" "$chkdir" "$todir"
209
210relative_opts='--relative --chmod=Du+w --copy-unsafe-links'
211$RSYNC -av $relative_opts "$fromdir/foo" "$chkdir/"
212rm -rf "$chkdir$fromdir/foo/down"
213$RSYNC -av $relative_opts --existing --filter='-! */' "$fromdir/foo" "$chkdir/"
214
215checkit "$RSYNC -avv $relative_opts --exclude='$fromdir/foo/down' \
216 '$fromdir/foo' '$todir'" "$chkdir$fromdir/foo" "$todir$fromdir/foo"
217
218# The script would have aborted on error, so getting here means we've won.
219exit 0