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"
19 # Build some files/dirs/links to copy
21 makepath "$fromdir/foo/down/to/you"
22 makepath "$fromdir/bar/down/to/foo/too"
23 makepath "$fromdir/bar/down/to/bar/baz"
24 makepath "$fromdir/mid/for/foo/and/that/is/who"
25 cat >"$fromdir/.filt" <<EOF
33 echo kept >"$fromdir/foo/file1"
34 echo removed >"$fromdir/foo/file2"
35 echo cvsout >"$fromdir/foo/file2.old"
36 cat >"$fromdir/foo/.filt" <<EOF
40 cat >"$fromdir/bar/.filt" <<EOF
45 echo cvsout >"$fromdir/bar/down/to/home-cvs-exclude"
46 cat >"$fromdir/bar/down/to/.filt2" <<EOF
49 cat >"$fromdir/bar/down/to/foo/.filt2" <<EOF
52 echo keeper >"$fromdir/bar/down/to/foo/file1"
53 echo cvsout >"$fromdir/bar/down/to/foo/file1.bak"
54 echo gone >"$fromdir/bar/down/to/foo/file3"
55 echo lost >"$fromdir/bar/down/to/foo/file4"
56 echo weird >"$fromdir/bar/down/to/foo/+ file3"
57 echo cvsout-but-filtin >"$fromdir/bar/down/to/foo/file4.junk"
58 echo smashed >"$fromdir/bar/down/to/foo/to"
59 cat >"$fromdir/bar/down/to/bar/.filt2" <<EOF
62 echo filtout >"$fromdir/bar/down/to/bar/baz/file5.deep"
63 # This one should be ineffectual
64 cat >"$fromdir/mid/.filt2" <<EOF
67 echo cvsout >"$fromdir/mid/one-in-one-out"
68 echo one-in-one-out >"$fromdir/mid/.cvsignore"
69 echo cvsin >"$fromdir/mid/one-for-all"
70 cat >"$fromdir/mid/.filt" <<EOF
73 echo cvsin >"$fromdir/mid/for/one-in-one-out"
74 echo expunged >"$fromdir/mid/for/foo/extra"
75 echo retained >"$fromdir/mid/for/foo/keep"
76 ln -s too "$fromdir/bar/down/to/foo/sym"
78 # Setup our test exclude/include files.
80 excl="$scratchdir/exclude-from"
83 # If the second line of these two lines does anything, it's a bug.
86 # This should match against the whole path, not just the name.
88 # This should float at the end of the path.
90 # Test some normal excludes. Competing lines are paired.
98 cat >"$scratchdir/.cvsignore" <<EOF
102 # Create the chk dir with what we expect to be excluded
104 checkit "$RSYNC -avv \"$fromdir/\" \"$chkdir/\"" "$fromdir" "$chkdir"
106 sleep 1 # Ensures that the rm commands will tweak the directory times.
108 rm -r "$chkdir"/foo/down
109 rm -r "$chkdir"/mid/for/foo/and
110 rm "$chkdir"/foo/file[235-9]
111 rm "$chkdir"/bar/down/to/foo/to "$chkdir"/bar/down/to/foo/file[235-9]
112 rm "$chkdir"/mid/for/foo/extra
114 # Un-tweak the directory times in our first (weak) exclude test (though
115 # it's a good test of the --existing option).
116 $RSYNC -av --existing --include='*/' --exclude='*' "$fromdir/" "$chkdir/"
118 # Now, test if rsync excludes the same files.
120 checkit "$RSYNC -avv --exclude-from=\"$excl\" \
121 --delete-during \"$fromdir/\" \"$todir/\"" "$chkdir" "$todir"
123 # Modify the chk dir by removing cvs-ignored files and then tweaking the dir times.
125 rm "$chkdir"/foo/*.old
126 rm "$chkdir"/bar/down/to/foo/*.bak
127 rm "$chkdir"/bar/down/to/foo/*.junk
128 rm "$chkdir"/bar/down/to/home-cvs-exclude
129 rm "$chkdir"/mid/one-in-one-out
131 $RSYNC -av --existing --filter='exclude,! */' "$fromdir/" "$chkdir/"
133 # Now, test if rsync excludes the same files, this time with --cvs-exclude
134 # and --delete-excluded.
136 checkit "$RSYNC -avvC --filter=\"merge $excl\" --delete-excluded \
137 --delete-during \"$fromdir/\" \"$todir/\"" "$chkdir" "$todir"
139 # Modify the chk dir for our merge-exclude test and then tweak the dir times.
141 rm "$chkdir"/foo/file1
142 rm "$chkdir"/bar/down/to/bar/baz/*.deep
143 cp -p "$fromdir"/bar/down/to/foo/*.junk "$chkdir"/bar/down/to/foo
144 cp -p "$fromdir"/bar/down/to/foo/to "$chkdir"/bar/down/to/foo
146 $RSYNC -av --existing -f 'show .filt*' -f 'hide,! */' --del "$fromdir/" "$todir/"
148 echo retained >"$todir"/bar/down/to/bar/baz/nodel.deep
149 cp -p "$todir"/bar/down/to/bar/baz/nodel.deep "$chkdir"/bar/down/to/bar/baz
151 $RSYNC -av --existing --filter='-! */' "$fromdir/" "$chkdir/"
153 # Now, test if rsync excludes the same files, this time with a merge-exclude
156 checkit "sed '/!/d' \"$excl\" |
157 $RSYNC -avv -f dir-merge_.filt -f merge_- \
158 --delete-during \"$fromdir/\" \"$todir/\"" "$chkdir" "$todir"
160 # Remove the files that will be deleted.
163 rm "$chkdir"/bar/.filt
164 rm "$chkdir"/bar/down/to/.filt2
165 rm "$chkdir"/bar/down/to/foo/.filt2
166 rm "$chkdir"/bar/down/to/bar/.filt2
167 rm "$chkdir"/mid/.filt
169 $RSYNC -av --existing --filter='-! */' "$fromdir/" "$chkdir/"
171 # Now, try the prior command with --delete-before and some side-specific
174 checkit "sed '/!/d' \"$excl\" |
175 $RSYNC -avv -f :s_.filt -f .s_- -f P_nodel.deep \
176 --delete-before \"$fromdir/\" \"$todir/\"" "$chkdir" "$todir"
178 # Next, we'll test some rule-restricted filter files.
180 cat >"$fromdir/bar/down/.excl" <<EOF
183 cat >"$fromdir/bar/down/to/foo/.excl" <<EOF
187 $RSYNC -av --del "$fromdir/" "$chkdir/"
188 rm "$chkdir/bar/down/to/foo/file1.bak"
189 rm "$chkdir/bar/down/to/foo/file3"
190 rm "$chkdir/bar/down/to/foo/+ file3"
191 $RSYNC -av --existing --filter='-! */' "$fromdir/" "$chkdir/"
192 $RSYNC -av --delete-excluded --exclude='*' "$fromdir/" "$todir/"
194 checkit "$RSYNC -avv -f dir-merge,-_.excl \
195 \"$fromdir/\" \"$todir/\"" "$chkdir" "$todir"
197 # The script would have aborted on error, so getting here means we've won.