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 cat >"$fromdir/.filt" <<EOF
36 echo filtered-1 >"$fromdir/foo/file1"
37 echo removed >"$fromdir/foo/file2"
38 echo cvsout >"$fromdir/foo/file2.old"
39 cat >"$fromdir/foo/.filt" <<EOF
43 echo not-filtered-1 >"$fromdir/foo/sub/file1"
44 cat >"$fromdir/bar/.filt" <<EOF
49 echo cvsout >"$fromdir/bar/down/to/home-cvs-exclude"
50 cat >"$fromdir/bar/down/to/.filt2" <<EOF
53 cat >"$fromdir/bar/down/to/foo/.filt2" <<EOF
56 echo keeper >"$fromdir/bar/down/to/foo/file1"
57 echo cvsout >"$fromdir/bar/down/to/foo/file1.bak"
58 echo gone >"$fromdir/bar/down/to/foo/file3"
59 echo lost >"$fromdir/bar/down/to/foo/file4"
60 echo weird >"$fromdir/bar/down/to/foo/+ file3"
61 echo cvsout-but-filtin >"$fromdir/bar/down/to/foo/file4.junk"
62 echo smashed >"$fromdir/bar/down/to/foo/to"
63 cat >"$fromdir/bar/down/to/bar/.filt2" <<EOF
66 echo filtout >"$fromdir/bar/down/to/bar/baz/file5.deep"
67 # This one should be ineffectual
68 cat >"$fromdir/mid/.filt2" <<EOF
71 echo cvsout >"$fromdir/mid/one-in-one-out"
72 echo one-in-one-out >"$fromdir/mid/.cvsignore"
73 echo cvsin >"$fromdir/mid/one-for-all"
74 cat >"$fromdir/mid/.filt" <<EOF
77 echo cvsin >"$fromdir/mid/for/one-in-one-out"
78 echo expunged >"$fromdir/mid/for/foo/extra"
79 echo retained >"$fromdir/mid/for/foo/keep"
80 ln -s too "$fromdir/bar/down/to/foo/sym"
82 # Setup our test exclude/include files.
84 excl="$scratchdir/exclude-from"
87 # If the second line of these two lines does anything, it's a bug.
90 # This should match against the whole path, not just the name.
92 # These should float at the end of the path.
95 # Test some normal excludes. Competing lines are paired.
103 cat >"$scratchdir/.cvsignore" <<EOF
107 # Create the chk dir with what we expect to be excluded
109 checkit "$RSYNC -avv \"$fromdir/\" \"$chkdir/\"" "$fromdir" "$chkdir"
111 sleep 1 # Ensures that the rm commands will tweak the directory times.
113 rm -r "$chkdir"/foo/down
114 rm -r "$chkdir"/mid/for/foo/and
115 rm "$chkdir"/foo/file[235-9]
116 rm "$chkdir"/bar/down/to/foo/to "$chkdir"/bar/down/to/foo/file[235-9]
117 rm "$chkdir"/mid/for/foo/extra
119 # Un-tweak the directory times in our first (weak) exclude test (though
120 # it's a good test of the --existing option).
121 $RSYNC -av --existing --include='*/' --exclude='*' "$fromdir/" "$chkdir/"
123 # Now, test if rsync excludes the same files.
125 checkit "$RSYNC -avv --exclude-from=\"$excl\" \
126 --delete-during \"$fromdir/\" \"$todir/\"" "$chkdir" "$todir"
128 # Modify the chk dir by removing cvs-ignored files and then tweaking the dir times.
130 rm "$chkdir"/foo/*.old
131 rm "$chkdir"/bar/down/to/foo/*.bak
132 rm "$chkdir"/bar/down/to/foo/*.junk
133 rm "$chkdir"/bar/down/to/home-cvs-exclude
134 rm "$chkdir"/mid/one-in-one-out
136 $RSYNC -av --existing --filter='exclude,! */' "$fromdir/" "$chkdir/"
138 # Now, test if rsync excludes the same files, this time with --cvs-exclude
139 # and --delete-excluded.
141 checkit "$RSYNC -avvC --filter=\"merge $excl\" --delete-excluded \
142 --delete-during \"$fromdir/\" \"$todir/\"" "$chkdir" "$todir"
144 # Modify the chk dir for our merge-exclude test and then tweak the dir times.
146 rm "$chkdir"/foo/file1
147 rm "$chkdir"/bar/down/to/bar/baz/*.deep
148 cp -p "$fromdir"/bar/down/to/foo/*.junk "$chkdir"/bar/down/to/foo
149 cp -p "$fromdir"/bar/down/to/foo/to "$chkdir"/bar/down/to/foo
151 $RSYNC -av --existing -f 'show .filt*' -f 'hide,! */' --del "$fromdir/" "$todir/"
153 echo retained >"$todir"/bar/down/to/bar/baz/nodel.deep
154 cp -p "$todir"/bar/down/to/bar/baz/nodel.deep "$chkdir"/bar/down/to/bar/baz
156 $RSYNC -av --existing --filter='-! */' "$fromdir/" "$chkdir/"
158 # Now, test if rsync excludes the same files, this time with a merge-exclude
161 checkit "sed '/!/d' \"$excl\" |
162 $RSYNC -avv -f dir-merge_.filt -f merge_- \
163 --delete-during \"$fromdir/\" \"$todir/\"" "$chkdir" "$todir"
165 # Remove the files that will be deleted.
168 rm "$chkdir"/bar/.filt
169 rm "$chkdir"/bar/down/to/.filt2
170 rm "$chkdir"/bar/down/to/foo/.filt2
171 rm "$chkdir"/bar/down/to/bar/.filt2
172 rm "$chkdir"/mid/.filt
174 $RSYNC -av --protocol=28 --existing --include='*/' --exclude='*' "$fromdir/" "$chkdir/"
176 # Now, try the prior command with --delete-before and some side-specific
179 checkit "sed '/!/d' \"$excl\" |
180 $RSYNC -avv -f :s_.filt -f .s_- -f P_nodel.deep \
181 --delete-before \"$fromdir/\" \"$todir/\"" "$chkdir" "$todir"
183 # Next, we'll test some rule-restricted filter files.
185 cat >"$fromdir/bar/down/.excl" <<EOF
188 cat >"$fromdir/bar/down/to/foo/.excl" <<EOF
192 $RSYNC -av --del "$fromdir/" "$chkdir/"
193 rm "$chkdir/bar/down/to/foo/file1.bak"
194 rm "$chkdir/bar/down/to/foo/file3"
195 rm "$chkdir/bar/down/to/foo/+ file3"
196 $RSYNC -av --existing --filter='-! */' "$fromdir/" "$chkdir/"
197 $RSYNC -av --delete-excluded --exclude='*' "$fromdir/" "$todir/"
199 checkit "$RSYNC -avv -f dir-merge,-_.excl \
200 \"$fromdir/\" \"$todir/\"" "$chkdir" "$todir"
202 # The script would have aborted on error, so getting here means we've won.