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"
18 # Build some files/dirs/links to copy
20 makepath
"$fromdir/foo/down/to/you"
21 makepath
"$fromdir/foo/sub"
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 makepath
"$fromdir/new/keep/this"
26 makepath
"$fromdir/new/lose/this"
27 cat >"$fromdir/.filt" <<EOF
35 echo filtered-1
>"$fromdir/foo/file1"
36 echo removed
>"$fromdir/foo/file2"
37 echo cvsout
>"$fromdir/foo/file2.old"
38 cat >"$fromdir/foo/.filt" <<EOF
42 echo not-filtered-1
>"$fromdir/foo/sub/file1"
43 cat >"$fromdir/bar/.filt" <<EOF
48 echo cvsout
>"$fromdir/bar/down/to/home-cvs-exclude"
49 cat >"$fromdir/bar/down/to/.filt2" <<EOF
52 cat >"$fromdir/bar/down/to/foo/.filt2" <<EOF
55 echo keeper
>"$fromdir/bar/down/to/foo/file1"
56 echo cvsout
>"$fromdir/bar/down/to/foo/file1.bak"
57 echo gone
>"$fromdir/bar/down/to/foo/file3"
58 echo lost
>"$fromdir/bar/down/to/foo/file4"
59 echo weird
>"$fromdir/bar/down/to/foo/+ file3"
60 echo cvsout-but-filtin
>"$fromdir/bar/down/to/foo/file4.junk"
61 echo smashed
>"$fromdir/bar/down/to/foo/to"
62 cat >"$fromdir/bar/down/to/bar/.filt2" <<EOF
65 echo filtout
>"$fromdir/bar/down/to/bar/baz/file5.deep"
66 # This one should be ineffectual
67 cat >"$fromdir/mid/.filt2" <<EOF
70 echo cvsout
>"$fromdir/mid/one-in-one-out"
71 echo one-in-one-out
>"$fromdir/mid/.cvsignore"
72 echo cvsin
>"$fromdir/mid/one-for-all"
73 cat >"$fromdir/mid/.filt" <<EOF
76 echo cvsin
>"$fromdir/mid/for/one-in-one-out"
77 echo expunged
>"$fromdir/mid/for/foo/extra"
78 echo retained
>"$fromdir/mid/for/foo/keep"
80 # Setup our test exclude/include files.
82 excl
="$scratchdir/exclude-from"
85 # If the second line of these two lines does anything, it's a bug.
88 # This should match against the whole path, not just the name.
90 # These should float at the end of the path.
93 # Test how /** differs from /***
96 # Test some normal excludes. Competing lines are paired.
104 cat >"$scratchdir/.cvsignore" <<EOF
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/"
110 checkit
"$RSYNC -av --prune-empty-dirs '$fromdir/' '$todir/'" "$chkdir" "$todir"
113 # Add a directory symlink.
114 ln -s too
"$fromdir/bar/down/to/foo/sym"
116 # Create chkdir with what we expect to be excluded.
117 checkit
"$RSYNC -avv '$fromdir/' '$chkdir/'" "$fromdir" "$chkdir"
118 sleep 1 # Ensures that the rm commands will tweak the directory times.
119 rm -r "$chkdir"/foo
/down
120 rm -r "$chkdir"/mid
/for
/foo
/and
121 rm -r "$chkdir"/new
/keep
/this
122 rm -r "$chkdir"/new
/lose
123 rm "$chkdir"/foo
/file[235-9]
124 rm "$chkdir"/bar
/down
/to
/foo
/to
"$chkdir"/bar
/down
/to
/foo
/file[235-9]
125 rm "$chkdir"/mid
/for
/foo
/extra
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/"
131 # Now, test if rsync excludes the same files.
133 checkit
"$RSYNC -avv --exclude-from='$excl' \
134 --delete-during '$fromdir/' '$todir/'" "$chkdir" "$todir"
136 # Modify the chk dir by removing cvs-ignored files and then tweaking the dir times.
138 rm "$chkdir"/foo
/*.old
139 rm "$chkdir"/bar
/down
/to
/foo
/*.bak
140 rm "$chkdir"/bar
/down
/to
/foo
/*.junk
141 rm "$chkdir"/bar
/down
/to
/home-cvs-exclude
142 rm "$chkdir"/mid
/one-in-one-out
144 $RSYNC -av --existing --filter='exclude,! */' "$fromdir/" "$chkdir/"
146 # Now, test if rsync excludes the same files, this time with --cvs-exclude
147 # and --delete-excluded.
149 checkit
"$RSYNC -avvC --filter='merge $excl' --delete-excluded \
150 --delete-during '$fromdir/' '$todir/'" "$chkdir" "$todir"
152 # Modify the chk dir for our merge-exclude test and then tweak the dir times.
154 rm "$chkdir"/foo
/file1
155 rm "$chkdir"/bar
/down
/to
/bar
/baz
/*.deep
156 cp -p "$fromdir"/bar
/down
/to
/foo
/*.junk
"$chkdir"/bar
/down
/to
/foo
157 cp -p "$fromdir"/bar
/down
/to
/foo
/to
"$chkdir"/bar
/down
/to
/foo
159 $RSYNC -av --existing -f 'show .filt*' -f 'hide,! */' --del "$fromdir/" "$todir/"
161 echo retained
>"$todir"/bar
/down
/to
/bar
/baz
/nodel.deep
162 cp -p "$todir"/bar
/down
/to
/bar
/baz
/nodel.deep
"$chkdir"/bar
/down
/to
/bar
/baz
164 $RSYNC -av --existing --filter='-! */' "$fromdir/" "$chkdir/"
166 # Now, test if rsync excludes the same files, this time with a merge-exclude
169 checkit
"sed '/!/d' '$excl' |
170 $RSYNC -avv -f dir-merge_.filt -f merge_- \
171 --delete-during '$fromdir/' '$todir/'" "$chkdir" "$todir"
173 # Remove the files that will be deleted.
176 rm "$chkdir"/bar
/.filt
177 rm "$chkdir"/bar
/down
/to
/.filt2
178 rm "$chkdir"/bar
/down
/to
/foo
/.filt2
179 rm "$chkdir"/bar
/down
/to
/bar
/.filt2
180 rm "$chkdir"/mid
/.filt
182 $RSYNC -av --protocol=28 --existing --include='*/' --exclude='*' "$fromdir/" "$chkdir/"
184 # Now, try the prior command with --delete-before and some side-specific
187 checkit
"sed '/!/d' '$excl' |
188 $RSYNC -avv -f :s_.filt -f .s_- -f P_nodel.deep \
189 --delete-before '$fromdir/' '$todir/'" "$chkdir" "$todir"
191 # Next, we'll test some rule-restricted filter files.
193 cat >"$fromdir/bar/down/.excl" <<EOF
196 cat >"$fromdir/bar/down/to/foo/.excl" <<EOF
200 $RSYNC -av --del "$fromdir/" "$chkdir/"
201 rm "$chkdir/bar/down/to/foo/file1.bak"
202 rm "$chkdir/bar/down/to/foo/file3"
203 rm "$chkdir/bar/down/to/foo/+ file3"
204 $RSYNC -av --existing --filter='-! */' "$fromdir/" "$chkdir/"
205 $RSYNC -av --delete-excluded --exclude='*' "$fromdir/" "$todir/"
207 checkit
"$RSYNC -avv -f dir-merge,-_.excl \
208 '$fromdir/' '$todir/'" "$chkdir" "$todir"
210 relative_opts
='--relative --chmod=Du+w --copy-unsafe-links'
211 $RSYNC -av $relative_opts "$fromdir/foo" "$chkdir/"
212 rm -rf "$chkdir$fromdir/foo/down"
213 $RSYNC -av $relative_opts --existing --filter='-! */' "$fromdir/foo" "$chkdir/"
215 checkit
"$RSYNC -avv $relative_opts --exclude='$fromdir/foo/down' \
216 '$fromdir/foo' '$todir'" "$chkdir$fromdir/foo" "$todir$fromdir/foo"
218 # The script would have aborted on error, so getting here means we've won.