3 # Copyright (C) 2003, 2004, 2005 by Wayne Davison <wayned@samba.org>
5 # This program is distributable under the terms of the GNU GPL see
8 # Test rsync handling of exclude/include directives.
10 # Test some of the more obscure wildcard handling of exclude/include
13 . "$suitedir/rsync.fns"
21 # Build some files/dirs/links to copy
23 makepath "$fromdir/foo/down/to/you"
24 makepath "$fromdir/foo/sub"
25 makepath "$fromdir/bar/down/to/foo/too"
26 makepath "$fromdir/bar/down/to/bar/baz"
27 makepath "$fromdir/mid/for/foo/and/that/is/who"
28 makepath "$fromdir/new/keep/this"
29 makepath "$fromdir/new/lose/this"
30 cat >"$fromdir/.filt" <<EOF
38 echo filtered-1 >"$fromdir/foo/file1"
39 echo removed >"$fromdir/foo/file2"
40 echo cvsout >"$fromdir/foo/file2.old"
41 cat >"$fromdir/foo/.filt" <<EOF
45 echo not-filtered-1 >"$fromdir/foo/sub/file1"
46 cat >"$fromdir/bar/.filt" <<EOF
51 echo cvsout >"$fromdir/bar/down/to/home-cvs-exclude"
52 cat >"$fromdir/bar/down/to/.filt2" <<EOF
55 cat >"$fromdir/bar/down/to/foo/.filt2" <<EOF
58 echo keeper >"$fromdir/bar/down/to/foo/file1"
59 echo cvsout >"$fromdir/bar/down/to/foo/file1.bak"
60 echo gone >"$fromdir/bar/down/to/foo/file3"
61 echo lost >"$fromdir/bar/down/to/foo/file4"
62 echo weird >"$fromdir/bar/down/to/foo/+ file3"
63 echo cvsout-but-filtin >"$fromdir/bar/down/to/foo/file4.junk"
64 echo smashed >"$fromdir/bar/down/to/foo/to"
65 cat >"$fromdir/bar/down/to/bar/.filt2" <<EOF
68 echo filtout >"$fromdir/bar/down/to/bar/baz/file5.deep"
69 # This one should be ineffectual
70 cat >"$fromdir/mid/.filt2" <<EOF
73 echo cvsout >"$fromdir/mid/one-in-one-out"
74 echo one-in-one-out >"$fromdir/mid/.cvsignore"
75 echo cvsin >"$fromdir/mid/one-for-all"
76 cat >"$fromdir/mid/.filt" <<EOF
79 echo cvsin >"$fromdir/mid/for/one-in-one-out"
80 echo expunged >"$fromdir/mid/for/foo/extra"
81 echo retained >"$fromdir/mid/for/foo/keep"
82 ln -s too "$fromdir/bar/down/to/foo/sym"
84 # Setup our test exclude/include files.
86 excl="$scratchdir/exclude-from"
89 # If the second line of these two lines does anything, it's a bug.
92 # This should match against the whole path, not just the name.
94 # These should float at the end of the path.
97 # Test how /** differs from /***
100 # Test some normal excludes. Competing lines are paired.
108 cat >"$scratchdir/.cvsignore" <<EOF
112 # Create the chk dir with what we expect to be excluded
114 checkit "$RSYNC -avv \"$fromdir/\" \"$chkdir/\"" "$fromdir" "$chkdir"
116 sleep 1 # Ensures that the rm commands will tweak the directory times.
118 rm -r "$chkdir"/foo/down
119 rm -r "$chkdir"/mid/for/foo/and
120 rm -r "$chkdir"/new/keep/this
121 rm -r "$chkdir"/new/lose
122 rm "$chkdir"/foo/file[235-9]
123 rm "$chkdir"/bar/down/to/foo/to "$chkdir"/bar/down/to/foo/file[235-9]
124 rm "$chkdir"/mid/for/foo/extra
126 # Un-tweak the directory times in our first (weak) exclude test (though
127 # it's a good test of the --existing option).
128 $RSYNC -av --existing --include='*/' --exclude='*' "$fromdir/" "$chkdir/"
130 # Now, test if rsync excludes the same files.
132 checkit "$RSYNC -avv --exclude-from=\"$excl\" \
133 --delete-during \"$fromdir/\" \"$todir/\"" "$chkdir" "$todir"
135 # Modify the chk dir by removing cvs-ignored files and then tweaking the dir times.
137 rm "$chkdir"/foo/*.old
138 rm "$chkdir"/bar/down/to/foo/*.bak
139 rm "$chkdir"/bar/down/to/foo/*.junk
140 rm "$chkdir"/bar/down/to/home-cvs-exclude
141 rm "$chkdir"/mid/one-in-one-out
143 $RSYNC -av --existing --filter='exclude,! */' "$fromdir/" "$chkdir/"
145 # Now, test if rsync excludes the same files, this time with --cvs-exclude
146 # and --delete-excluded.
148 checkit "$RSYNC -avvC --filter=\"merge $excl\" --delete-excluded \
149 --delete-during \"$fromdir/\" \"$todir/\"" "$chkdir" "$todir"
151 # Modify the chk dir for our merge-exclude test and then tweak the dir times.
153 rm "$chkdir"/foo/file1
154 rm "$chkdir"/bar/down/to/bar/baz/*.deep
155 cp -p "$fromdir"/bar/down/to/foo/*.junk "$chkdir"/bar/down/to/foo
156 cp -p "$fromdir"/bar/down/to/foo/to "$chkdir"/bar/down/to/foo
158 $RSYNC -av --existing -f 'show .filt*' -f 'hide,! */' --del "$fromdir/" "$todir/"
160 echo retained >"$todir"/bar/down/to/bar/baz/nodel.deep
161 cp -p "$todir"/bar/down/to/bar/baz/nodel.deep "$chkdir"/bar/down/to/bar/baz
163 $RSYNC -av --existing --filter='-! */' "$fromdir/" "$chkdir/"
165 # Now, test if rsync excludes the same files, this time with a merge-exclude
168 checkit "sed '/!/d' \"$excl\" |
169 $RSYNC -avv -f dir-merge_.filt -f merge_- \
170 --delete-during \"$fromdir/\" \"$todir/\"" "$chkdir" "$todir"
172 # Remove the files that will be deleted.
175 rm "$chkdir"/bar/.filt
176 rm "$chkdir"/bar/down/to/.filt2
177 rm "$chkdir"/bar/down/to/foo/.filt2
178 rm "$chkdir"/bar/down/to/bar/.filt2
179 rm "$chkdir"/mid/.filt
181 $RSYNC -av --protocol=28 --existing --include='*/' --exclude='*' "$fromdir/" "$chkdir/"
183 # Now, try the prior command with --delete-before and some side-specific
186 checkit "sed '/!/d' \"$excl\" |
187 $RSYNC -avv -f :s_.filt -f .s_- -f P_nodel.deep \
188 --delete-before \"$fromdir/\" \"$todir/\"" "$chkdir" "$todir"
190 # Next, we'll test some rule-restricted filter files.
192 cat >"$fromdir/bar/down/.excl" <<EOF
195 cat >"$fromdir/bar/down/to/foo/.excl" <<EOF
199 $RSYNC -av --del "$fromdir/" "$chkdir/"
200 rm "$chkdir/bar/down/to/foo/file1.bak"
201 rm "$chkdir/bar/down/to/foo/file3"
202 rm "$chkdir/bar/down/to/foo/+ file3"
203 $RSYNC -av --existing --filter='-! */' "$fromdir/" "$chkdir/"
204 $RSYNC -av --delete-excluded --exclude='*' "$fromdir/" "$todir/"
206 checkit "$RSYNC -avv -f dir-merge,-_.excl \
207 \"$fromdir/\" \"$todir/\"" "$chkdir" "$todir"
209 # The script would have aborted on error, so getting here means we've won.