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"
20 # Build some files/dirs/links to copy
22 makepath "$fromdir/foo/down/to/you"
23 makepath "$fromdir/foo/sub"
24 makepath "$fromdir/bar/down/to/foo/too"
25 makepath "$fromdir/bar/down/to/bar/baz"
26 makepath "$fromdir/mid/for/foo/and/that/is/who"
27 makepath "$fromdir/new/keep/this"
28 makepath "$fromdir/new/lose/this"
29 cat >"$fromdir/.filt" <<EOF
37 echo filtered-1 >"$fromdir/foo/file1"
38 echo removed >"$fromdir/foo/file2"
39 echo cvsout >"$fromdir/foo/file2.old"
40 cat >"$fromdir/foo/.filt" <<EOF
44 echo not-filtered-1 >"$fromdir/foo/sub/file1"
45 cat >"$fromdir/bar/.filt" <<EOF
50 echo cvsout >"$fromdir/bar/down/to/home-cvs-exclude"
51 cat >"$fromdir/bar/down/to/.filt2" <<EOF
54 cat >"$fromdir/bar/down/to/foo/.filt2" <<EOF
57 echo keeper >"$fromdir/bar/down/to/foo/file1"
58 echo cvsout >"$fromdir/bar/down/to/foo/file1.bak"
59 echo gone >"$fromdir/bar/down/to/foo/file3"
60 echo lost >"$fromdir/bar/down/to/foo/file4"
61 echo weird >"$fromdir/bar/down/to/foo/+ file3"
62 echo cvsout-but-filtin >"$fromdir/bar/down/to/foo/file4.junk"
63 echo smashed >"$fromdir/bar/down/to/foo/to"
64 cat >"$fromdir/bar/down/to/bar/.filt2" <<EOF
67 echo filtout >"$fromdir/bar/down/to/bar/baz/file5.deep"
68 # This one should be ineffectual
69 cat >"$fromdir/mid/.filt2" <<EOF
72 echo cvsout >"$fromdir/mid/one-in-one-out"
73 echo one-in-one-out >"$fromdir/mid/.cvsignore"
74 echo cvsin >"$fromdir/mid/one-for-all"
75 cat >"$fromdir/mid/.filt" <<EOF
78 echo cvsin >"$fromdir/mid/for/one-in-one-out"
79 echo expunged >"$fromdir/mid/for/foo/extra"
80 echo retained >"$fromdir/mid/for/foo/keep"
81 ln -s too "$fromdir/bar/down/to/foo/sym"
83 # Setup our test exclude/include files.
85 excl="$scratchdir/exclude-from"
88 # If the second line of these two lines does anything, it's a bug.
91 # This should match against the whole path, not just the name.
93 # These should float at the end of the path.
96 # Test how /** differs from /***
99 # Test some normal excludes. Competing lines are paired.
107 cat >"$scratchdir/.cvsignore" <<EOF
111 # Create the chk dir with what we expect to be excluded
113 checkit "$RSYNC -avv \"$fromdir/\" \"$chkdir/\"" "$fromdir" "$chkdir"
115 sleep 1 # Ensures that the rm commands will tweak the directory times.
117 rm -r "$chkdir"/foo/down
118 rm -r "$chkdir"/mid/for/foo/and
119 rm -r "$chkdir"/new/keep/this
120 rm -r "$chkdir"/new/lose
121 rm "$chkdir"/foo/file[235-9]
122 rm "$chkdir"/bar/down/to/foo/to "$chkdir"/bar/down/to/foo/file[235-9]
123 rm "$chkdir"/mid/for/foo/extra
125 # Un-tweak the directory times in our first (weak) exclude test (though
126 # it's a good test of the --existing option).
127 $RSYNC -av --existing --include='*/' --exclude='*' "$fromdir/" "$chkdir/"
129 # Now, test if rsync excludes the same files.
131 checkit "$RSYNC -avv --exclude-from=\"$excl\" \
132 --delete-during \"$fromdir/\" \"$todir/\"" "$chkdir" "$todir"
134 # Modify the chk dir by removing cvs-ignored files and then tweaking the dir times.
136 rm "$chkdir"/foo/*.old
137 rm "$chkdir"/bar/down/to/foo/*.bak
138 rm "$chkdir"/bar/down/to/foo/*.junk
139 rm "$chkdir"/bar/down/to/home-cvs-exclude
140 rm "$chkdir"/mid/one-in-one-out
142 $RSYNC -av --existing --filter='exclude,! */' "$fromdir/" "$chkdir/"
144 # Now, test if rsync excludes the same files, this time with --cvs-exclude
145 # and --delete-excluded.
147 checkit "$RSYNC -avvC --filter=\"merge $excl\" --delete-excluded \
148 --delete-during \"$fromdir/\" \"$todir/\"" "$chkdir" "$todir"
150 # Modify the chk dir for our merge-exclude test and then tweak the dir times.
152 rm "$chkdir"/foo/file1
153 rm "$chkdir"/bar/down/to/bar/baz/*.deep
154 cp -p "$fromdir"/bar/down/to/foo/*.junk "$chkdir"/bar/down/to/foo
155 cp -p "$fromdir"/bar/down/to/foo/to "$chkdir"/bar/down/to/foo
157 $RSYNC -av --existing -f 'show .filt*' -f 'hide,! */' --del "$fromdir/" "$todir/"
159 echo retained >"$todir"/bar/down/to/bar/baz/nodel.deep
160 cp -p "$todir"/bar/down/to/bar/baz/nodel.deep "$chkdir"/bar/down/to/bar/baz
162 $RSYNC -av --existing --filter='-! */' "$fromdir/" "$chkdir/"
164 # Now, test if rsync excludes the same files, this time with a merge-exclude
167 checkit "sed '/!/d' \"$excl\" |
168 $RSYNC -avv -f dir-merge_.filt -f merge_- \
169 --delete-during \"$fromdir/\" \"$todir/\"" "$chkdir" "$todir"
171 # Remove the files that will be deleted.
174 rm "$chkdir"/bar/.filt
175 rm "$chkdir"/bar/down/to/.filt2
176 rm "$chkdir"/bar/down/to/foo/.filt2
177 rm "$chkdir"/bar/down/to/bar/.filt2
178 rm "$chkdir"/mid/.filt
180 $RSYNC -av --protocol=28 --existing --include='*/' --exclude='*' "$fromdir/" "$chkdir/"
182 # Now, try the prior command with --delete-before and some side-specific
185 checkit "sed '/!/d' \"$excl\" |
186 $RSYNC -avv -f :s_.filt -f .s_- -f P_nodel.deep \
187 --delete-before \"$fromdir/\" \"$todir/\"" "$chkdir" "$todir"
189 # Next, we'll test some rule-restricted filter files.
191 cat >"$fromdir/bar/down/.excl" <<EOF
194 cat >"$fromdir/bar/down/to/foo/.excl" <<EOF
198 $RSYNC -av --del "$fromdir/" "$chkdir/"
199 rm "$chkdir/bar/down/to/foo/file1.bak"
200 rm "$chkdir/bar/down/to/foo/file3"
201 rm "$chkdir/bar/down/to/foo/+ file3"
202 $RSYNC -av --existing --filter='-! */' "$fromdir/" "$chkdir/"
203 $RSYNC -av --delete-excluded --exclude='*' "$fromdir/" "$todir/"
205 checkit "$RSYNC -avv -f dir-merge,-_.excl \
206 \"$fromdir/\" \"$todir/\"" "$chkdir" "$todir"
208 # The script would have aborted on error, so getting here means we've won.