3 # Copyright (C) 2003 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/bar/down/to/foo/too"
25 makepath "$fromdir/bar/down/to/bar/baz"
26 makepath "$fromdir/mid/for/foo/and/that/is/who"
27 cat >"$fromdir/.excl" <<EOF
35 echo kept >"$fromdir/foo/file1"
36 echo removed >"$fromdir/foo/file2"
37 echo cvsout >"$fromdir/foo/file2.old"
38 cat >"$fromdir/foo/.excl" <<EOF
42 cat >"$fromdir/bar/.excl" <<EOF
47 echo cvsout >"$fromdir/bar/down/to/home-cvs-exclude"
48 cat >"$fromdir/bar/down/to/.excl2" <<EOF
51 cat >"$fromdir/bar/down/to/foo/.excl2" <<EOF
54 echo keeper >"$fromdir/bar/down/to/foo/file1"
55 echo cvsout >"$fromdir/bar/down/to/foo/file1.bak"
56 echo gone >"$fromdir/bar/down/to/foo/file3"
57 echo lost >"$fromdir/bar/down/to/foo/file4"
58 echo cvsout-but-filtin >"$fromdir/bar/down/to/foo/file4.junk"
59 echo smashed >"$fromdir/bar/down/to/foo/to"
60 cat >"$fromdir/bar/down/to/bar/.excl2" <<EOF
63 echo filtout >"$fromdir/bar/down/to/bar/baz/file5.deep"
64 # This one should be ineffectual
65 cat >"$fromdir/mid/.excl2" <<EOF
68 echo cvsout >"$fromdir/mid/one-in-one-out"
69 echo one-in-one-out >"$fromdir/mid/.cvsignore"
70 echo cvsin >"$fromdir/mid/one-for-all"
71 cat >"$fromdir/mid/.excl" <<EOF
74 echo cvsin >"$fromdir/mid/for/one-in-one-out"
75 echo expunged >"$fromdir/mid/for/foo/extra"
76 echo retained >"$fromdir/mid/for/foo/keep"
77 ln -s too "$fromdir/bar/down/to/foo/sym"
79 # Setup our test exclude/include files.
81 excl="$scratchdir/exclude-from"
84 # If the second line of these two lines does anything, it's a bug.
87 # This should match against the whole path, not just the name.
89 # This should float at the end of the path.
91 # Test some normal excludes. Competing lines are paired.
99 cat >"$scratchdir/.cvsignore" <<EOF
103 # Create the chk dir with what we expect to be excluded
105 checkit "$RSYNC -avv \"$fromdir/\" \"$chkdir/\"" "$fromdir" "$chkdir"
107 sleep 1 # Ensures that the rm commands will tweak the directory times.
109 rm -r "$chkdir"/foo/down
110 rm -r "$chkdir"/mid/for/foo/and
111 rm "$chkdir"/foo/file[235-9]
112 rm "$chkdir"/bar/down/to/foo/to "$chkdir"/bar/down/to/foo/file[235-9]
113 rm "$chkdir"/mid/for/foo/extra
115 # Un-tweak the directory times in our first (weak) exclude test (though
116 # it's a good test of the --existing option).
117 $RSYNC -av --existing --include='*/' --exclude='*' "$fromdir/" "$chkdir/"
119 # Now, test if rsync excludes the same files.
121 checkit "$RSYNC -avv --exclude-from=\"$excl\" \
122 --delete-during \"$fromdir/\" \"$todir/\"" "$chkdir" "$todir"
124 # Modify the chk dir by removing cvs-ignored files and then tweaking the dir times.
126 rm "$chkdir"/foo/*.old
127 rm "$chkdir"/bar/down/to/foo/*.bak
128 rm "$chkdir"/bar/down/to/foo/*.junk
129 rm "$chkdir"/bar/down/to/home-cvs-exclude
130 rm "$chkdir"/mid/one-in-one-out
132 $RSYNC -av --existing --filter='-! */' "$fromdir/" "$chkdir/"
134 # Now, test if rsync excludes the same files, this time with --cvs-exclude
135 # and --delete-excluded.
137 checkit "$RSYNC -avvC --filter=\". $excl\" --delete-excluded \
138 --delete-during \"$fromdir/\" \"$todir/\"" "$chkdir" "$todir"
140 # Modify the chk dir for our merge-exclude test and then tweak the dir times.
142 rm "$chkdir"/foo/file1
143 rm "$chkdir"/bar/down/to/bar/baz/*.deep
144 cp -p "$fromdir"/bar/down/to/foo/*.junk "$chkdir"/bar/down/to/foo
145 cp -p "$fromdir"/bar/down/to/foo/to "$chkdir"/bar/down/to/foo
147 $RSYNC -av --existing --delete-excluded \
148 --include='.excl*' --filter='-! */' "$fromdir/" "$todir/"
150 echo retained >"$todir"/bar/down/to/bar/baz/nodel.deep
151 cp -p "$todir"/bar/down/to/bar/baz/nodel.deep "$chkdir"/bar/down/to/bar/baz
153 $RSYNC -av --existing --filter='-! */' "$fromdir/" "$chkdir/"
155 # Now, test if rsync excludes the same files, this time with a merge-exclude
158 checkit "sed '/!/d' \"$excl\" |
159 $RSYNC -avv -f :_.excl -f ._- \
160 --delete-during \"$fromdir/\" \"$todir/\"" "$chkdir" "$todir"
162 # Remove the files that --delete-excluded will delete.
165 rm "$chkdir"/bar/.excl
166 rm "$chkdir"/bar/down/to/.excl2
167 rm "$chkdir"/bar/down/to/foo/.excl2
168 rm "$chkdir"/bar/down/to/bar/.excl2
169 rm "$chkdir"/mid/.excl
170 rm "$chkdir"/bar/down/to/bar/baz/nodel.deep
172 $RSYNC -av --existing --filter='-! */' "$fromdir/" "$chkdir/"
174 # Finally, try the prior command with --delete-before and --delete-excluded.
176 checkit "sed '/!/d' \"$excl\" |
177 $RSYNC -avv -f :_.excl -f ._- --delete-excluded \
178 --delete-before \"$fromdir/\" \"$todir/\"" "$chkdir" "$todir"
180 # The script would have aborted on error, so getting here means we've won.