3 # Copyright (C) 2003-2022 Wayne Davison
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 # Start to prep an --update test dir
117 mkdir
"$scratchdir/up1" "$scratchdir/up2"
118 touch "$scratchdir/up1/dst-newness" "$scratchdir/up2/src-newness"
119 touch "$scratchdir/up1/same-newness" "$scratchdir/up2/same-newness"
120 touch "$scratchdir/up1/extra-src" "$scratchdir/up2/extra-dest"
122 # Create chkdir with what we expect to be excluded.
123 checkit
"$RSYNC -avv '$fromdir/' '$chkdir/'" "$fromdir" "$chkdir"
124 sleep 1 # Ensures that the rm commands will tweak the directory times.
125 rm -r "$chkdir"/foo
/down
126 rm -r "$chkdir"/mid
/for
/foo
/and
127 rm -r "$chkdir"/new
/keep
/this
128 rm -r "$chkdir"/new
/lose
129 rm "$chkdir"/foo
/file[235-9]
130 rm "$chkdir"/bar
/down
/to
/foo
/to
"$chkdir"/bar
/down
/to
/foo
/file[235-9]
131 rm "$chkdir"/mid
/for
/foo
/extra
133 # Finish prep for the --update test (run last)
134 touch "$scratchdir/up1/src-newness" "$scratchdir/up2/dst-newness"
136 # Un-tweak the directory times in our first (weak) exclude test (though
137 # it's a good test of the --existing option).
138 $RSYNC -av --existing --include='*/' --exclude='*' "$fromdir/" "$chkdir/"
140 # Now, test if rsync excludes the same files.
142 checkit
"$RSYNC -avv --exclude-from='$excl' \
143 --delete-during '$fromdir/' '$todir/'" "$chkdir" "$todir"
145 # Modify the chk dir by removing cvs-ignored files and then tweaking the dir times.
147 rm "$chkdir"/foo
/*.old
148 rm "$chkdir"/bar
/down
/to
/foo
/*.bak
149 rm "$chkdir"/bar
/down
/to
/foo
/*.junk
150 rm "$chkdir"/bar
/down
/to
/home-cvs-exclude
151 rm "$chkdir"/mid
/one-in-one-out
153 $RSYNC -av --existing --filter='exclude,! */' "$fromdir/" "$chkdir/"
155 # Now, test if rsync excludes the same files, this time with --cvs-exclude
156 # and --delete-excluded.
158 checkit
"$RSYNC -avvC --filter='merge $excl' --delete-excluded \
159 --delete-during '$fromdir/' '$todir/'" "$chkdir" "$todir"
161 # Modify the chk dir for our merge-exclude test and then tweak the dir times.
163 rm "$chkdir"/foo
/file1
164 rm "$chkdir"/bar
/down
/to
/bar
/baz
/*.deep
165 cp_touch
"$fromdir"/bar
/down
/to
/foo
/*.junk
"$chkdir"/bar
/down
/to
/foo
166 cp_touch
"$fromdir"/bar
/down
/to
/foo
/to
"$chkdir"/bar
/down
/to
/foo
168 $RSYNC -av --existing -f 'show .filt*' -f 'hide,! */' --del "$fromdir/" "$todir/"
170 echo retained
>"$todir"/bar
/down
/to
/bar
/baz
/nodel.deep
171 cp_touch
"$todir"/bar
/down
/to
/bar
/baz
/nodel.deep
"$chkdir"/bar
/down
/to
/bar
/baz
173 $RSYNC -av --existing --filter='-! */' "$fromdir/" "$chkdir/"
175 # Now, test if rsync excludes the same files, this time with a merge-exclude
178 checkit
"sed '/!/d' '$excl' |
179 $RSYNC -avv -f dir-merge_.filt -f merge_- \
180 --delete-during '$fromdir/' '$todir/'" "$chkdir" "$todir"
182 # Remove the files that will be deleted.
185 rm "$chkdir"/bar
/.filt
186 rm "$chkdir"/bar
/down
/to
/.filt2
187 rm "$chkdir"/bar
/down
/to
/foo
/.filt2
188 rm "$chkdir"/bar
/down
/to
/bar
/.filt2
189 rm "$chkdir"/mid
/.filt
191 $RSYNC -av --existing --include='*/' --exclude='*' "$fromdir/" "$chkdir/"
193 # Now, try the prior command with --delete-before and some side-specific
196 checkit
"sed '/!/d' '$excl' |
197 $RSYNC -avv -f :s_.filt -f .s_- -f P_nodel.deep \
198 --delete-before '$fromdir/' '$todir/'" "$chkdir" "$todir"
200 # Next, we'll test some rule-restricted filter files.
202 cat >"$fromdir/bar/down/.excl" <<EOF
205 cat >"$fromdir/bar/down/to/foo/.excl" <<EOF
209 $RSYNC -av --del "$fromdir/" "$chkdir/"
210 rm "$chkdir/bar/down/to/foo/file1.bak"
211 rm "$chkdir/bar/down/to/foo/file3"
212 rm "$chkdir/bar/down/to/foo/+ file3"
213 $RSYNC -av --existing --filter='-! */' "$fromdir/" "$chkdir/"
214 $RSYNC -av --delete-excluded --exclude='*' "$fromdir/" "$todir/"
216 checkit
"$RSYNC -avv -f dir-merge,-_.excl \
217 '$fromdir/' '$todir/'" "$chkdir" "$todir"
219 relative_opts
='--relative --chmod=Du+w --copy-unsafe-links'
220 $RSYNC -av $relative_opts "$fromdir/foo" "$chkdir/"
221 rm -rf "$chkdir$fromdir/foo/down"
222 $RSYNC -av $relative_opts --existing --filter='-! */' "$fromdir/foo" "$chkdir/"
224 checkit
"$RSYNC -avv $relative_opts --exclude='$fromdir/foo/down' \
225 '$fromdir/foo' '$todir'" "$chkdir$fromdir/foo" "$todir$fromdir/foo"
227 # Now we'll test the --update option.
228 checkdiff
"$RSYNC -aiiO --update --info=skip '$scratchdir/up1/' '$scratchdir/up2/'" \
229 "grep -v '^\.d$allspace'" <<EOT
231 >f$all_plus extra-src
232 .f$allspace same-newness
233 >f..t.$dots src-newness
236 # The script would have aborted on error, so getting here means we've won.