Commit | Line | Data |
---|---|---|
ff570659 WD |
1 | #! /bin/sh |
2 | ||
3 | # Copyright (C) 2003 by Wayne Davison <wayned@samba.org> | |
4 | ||
5 | # This program is distributable under the terms of the GNU GPL see | |
6 | # COPYING). | |
7 | ||
8 | # Test rsync handling of exclude/include directives. | |
9 | ||
10 | # Test some of the more obscure wildcard handling of exclude/include | |
11 | # processing. | |
12 | ||
7892e5ac | 13 | . "$suitedir/rsync.fns" |
ff570659 WD |
14 | |
15 | set -x | |
16 | ||
43a9d0e7 WD |
17 | HOME="$scratchdir" |
18 | CVSIGNORE='*.junk' | |
19 | export HOME CVSIGNORE | |
20 | ||
ff570659 WD |
21 | # Build some files/dirs/links to copy |
22 | ||
ff570659 WD |
23 | makepath "$fromdir/foo/down/to/you" |
24 | makepath "$fromdir/bar/down/to/foo/too" | |
408aa7b2 | 25 | makepath "$fromdir/bar/down/to/bar/baz" |
ff570659 | 26 | makepath "$fromdir/mid/for/foo/and/that/is/who" |
201a2fe5 WD |
27 | cat >"$fromdir/.excl" <<EOF |
28 | - down | |
29 | : .excl-temp | |
30 | ! | |
31 | - .excl | |
32 | - *.bak | |
33 | - *.old | |
201a2fe5 | 34 | EOF |
ff570659 WD |
35 | echo kept >"$fromdir/foo/file1" |
36 | echo removed >"$fromdir/foo/file2" | |
43a9d0e7 | 37 | echo cvsout >"$fromdir/foo/file2.old" |
201a2fe5 WD |
38 | cat >"$fromdir/foo/.excl" <<EOF |
39 | + .excl | |
40 | - file1 | |
41 | EOF | |
42 | cat >"$fromdir/bar/.excl" <<EOF | |
43 | - home-cvs-exclude | |
44 | : .excl2 | |
45 | + to | |
46 | EOF | |
ead751c6 | 47 | echo cvsout >"$fromdir/bar/down/to/home-cvs-exclude" |
201a2fe5 WD |
48 | cat >"$fromdir/bar/down/to/.excl2" <<EOF |
49 | - .excl2 | |
50 | EOF | |
408aa7b2 WD |
51 | cat >"$fromdir/bar/down/to/foo/.excl2" <<EOF |
52 | + *.junk | |
53 | EOF | |
ff570659 | 54 | echo keeper >"$fromdir/bar/down/to/foo/file1" |
43a9d0e7 | 55 | echo cvsout >"$fromdir/bar/down/to/foo/file1.bak" |
ff570659 WD |
56 | echo gone >"$fromdir/bar/down/to/foo/file3" |
57 | echo lost >"$fromdir/bar/down/to/foo/file4" | |
408aa7b2 | 58 | echo cvsout-but-filtin >"$fromdir/bar/down/to/foo/file4.junk" |
ff570659 | 59 | echo smashed >"$fromdir/bar/down/to/foo/to" |
408aa7b2 WD |
60 | cat >"$fromdir/bar/down/to/bar/.excl2" <<EOF |
61 | - *.deep | |
201a2fe5 | 62 | EOF |
408aa7b2 | 63 | echo filtout >"$fromdir/bar/down/to/bar/baz/file5.deep" |
201a2fe5 WD |
64 | # This one should be ineffectual |
65 | cat >"$fromdir/mid/.excl2" <<EOF | |
66 | - extra | |
67 | EOF | |
43a9d0e7 WD |
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" | |
201a2fe5 WD |
71 | cat >"$fromdir/mid/.excl" <<EOF |
72 | :C | |
73 | EOF | |
ead751c6 | 74 | echo cvsin >"$fromdir/mid/for/one-in-one-out" |
ff570659 WD |
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" | |
78 | ||
f1dd0f27 | 79 | # Setup our test exclude/include files. |
ff570659 | 80 | |
ff570659 WD |
81 | excl="$scratchdir/exclude-from" |
82 | cat >"$excl" <<EOF | |
201a2fe5 | 83 | ! |
ff570659 WD |
84 | # If the second line of these two lines does anything, it's a bug. |
85 | + **/bar | |
86 | - /bar | |
87 | # This should match against the whole path, not just the name. | |
88 | + foo**too | |
89 | # This should float at the end of the path. | |
90 | - foo/*/ | |
91 | # Test some normal excludes. Competing lines are paired. | |
92 | + t[o]/ | |
93 | - to | |
94 | + file4 | |
95 | - file[2-9] | |
96 | - /mid/for/foo/extra | |
97 | EOF | |
98 | ||
f1dd0f27 WD |
99 | cat >"$scratchdir/.cvsignore" <<EOF |
100 | home-cvs-exclude | |
101 | EOF | |
102 | ||
ff570659 | 103 | # Create the chk dir with what we expect to be excluded |
337a1a86 | 104 | |
ff570659 WD |
105 | checkit "$RSYNC -avv \"$fromdir/\" \"$chkdir/\"" "$fromdir" "$chkdir" |
106 | ||
337a1a86 | 107 | sleep 1 # Ensures that the rm commands will tweak the directory times. |
ff570659 | 108 | |
ff570659 | 109 | rm -r "$chkdir"/foo/down |
093acc5d | 110 | rm -r "$chkdir"/mid/for/foo/and |
ff570659 | 111 | rm "$chkdir"/foo/file[235-9] |
093acc5d | 112 | rm "$chkdir"/bar/down/to/foo/to "$chkdir"/bar/down/to/foo/file[235-9] |
ff570659 WD |
113 | rm "$chkdir"/mid/for/foo/extra |
114 | ||
337a1a86 WD |
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/" | |
ff570659 | 118 | |
337a1a86 | 119 | # Now, test if rsync excludes the same files. |
ff570659 | 120 | |
201a2fe5 | 121 | checkit "$RSYNC -avv --exclude-from=\"$excl\" \ |
408aa7b2 | 122 | --delete-during \"$fromdir/\" \"$todir/\"" "$chkdir" "$todir" |
ff570659 | 123 | |
43a9d0e7 WD |
124 | # Modify the chk dir by removing cvs-ignored files and then tweaking the dir times. |
125 | ||
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 | |
131 | ||
132 | $RSYNC -av --existing --include='*/' --exclude='*' "$fromdir/" "$chkdir/" | |
133 | ||
134 | # Now, test if rsync excludes the same files, this time with --cvs-exclude | |
135 | # and --delete-excluded. | |
136 | ||
408aa7b2 WD |
137 | checkit "$RSYNC -avvC --filter=\". $excl\" --delete-excluded \ |
138 | --delete-during \"$fromdir/\" \"$todir/\"" "$chkdir" "$todir" | |
201a2fe5 WD |
139 | |
140 | # Modify the chk dir for our merge-exclude test and then tweak the dir times. | |
141 | ||
201a2fe5 | 142 | rm "$chkdir"/foo/file1 |
408aa7b2 | 143 | rm "$chkdir"/bar/down/to/bar/baz/*.deep |
201a2fe5 WD |
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 | |
146 | ||
408aa7b2 WD |
147 | $RSYNC -av --existing --delete-excluded \ |
148 | --include='*/' --include='.excl*' --exclude='*' "$fromdir/" "$todir/" | |
149 | ||
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 | |
152 | ||
201a2fe5 WD |
153 | $RSYNC -av --existing --include='*/' --exclude='*' "$fromdir/" "$chkdir/" |
154 | ||
155 | # Now, test if rsync excludes the same files, this time with a merge-exclude | |
156 | # file. | |
157 | ||
408aa7b2 WD |
158 | checkit "sed '/!/d' \"$excl\" | |
159 | $RSYNC -avv -f :_.excl -f ._- \ | |
160 | --delete-during \"$fromdir/\" \"$todir/\"" "$chkdir" "$todir" | |
161 | ||
162 | # Remove the files that --delete-excluded will delete. | |
163 | ||
164 | rm "$chkdir"/.excl | |
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 | |
171 | ||
172 | $RSYNC -av --existing --include='*/' --exclude='*' "$fromdir/" "$chkdir/" | |
173 | ||
174 | # Finally, try the prior command with --delete-before and --delete-excluded. | |
175 | ||
176 | checkit "sed '/!/d' \"$excl\" | | |
177 | $RSYNC -avv -f :_.excl -f ._- --delete-excluded \ | |
178 | --delete-before \"$fromdir/\" \"$todir/\"" "$chkdir" "$todir" | |
43a9d0e7 | 179 | |
05118158 | 180 | # The script would have aborted on error, so getting here means we've won. |
ff570659 | 181 | exit 0 |