Commit | Line | Data |
---|---|---|
8a529471 WD |
1 | After applying this patch and running configure, you MUST run this |
2 | command before "make": | |
3 | ||
4 | make proto | |
5 | ||
524989ae | 6 | This patch adds the ability to merge rules into your excludes/includes |
2e064775 WD |
7 | using either "+m FILE" (for merged includes) or "-m FILE" (for merged |
8 | excludes). It also lets you specify either "+p FILE" or "-p FILE" in | |
9 | order to specify a per-directory merge file -- one that will be looked | |
10 | for in every sub-directory that rsync visits, and the rules found in | |
11 | that subdirectory's file will affect that dir and (if desired) its | |
12 | subdirs. | |
a55d21aa WD |
13 | |
14 | For example: | |
15 | ||
2e064775 | 16 | rsync -av --exclude='-p .excl' from/ to |
a55d21aa WD |
17 | |
18 | The above will look for a file named ".excl" in every directory of the | |
524989ae WD |
19 | hierarchy that rsync visits, and it will exclude (by default) names |
20 | based on the rules found therein. If one of the .excl files contains | |
21 | this: | |
a55d21aa WD |
22 | |
23 | + *.c | |
2e064775 WD |
24 | -p .excl2 |
25 | -m .excl3 | |
524989ae | 26 | *.o |
5f98a4b1 | 27 | /foobar |
a55d21aa | 28 | |
d34d9fad | 29 | Then the file ".excl2" will also be read in from the current dir and all |
2e064775 WD |
30 | its subdirs. The file ".excl3" would just be read in from the current |
31 | dir. The exclusion of "foobar" will only happen in that .excl file's | |
32 | directory because the rule is anchored, so that's how you can make rules | |
33 | local instead of inherited. | |
a55d21aa WD |
34 | |
35 | ..wayne.. | |
36 | ||
37da98ae | 37 | --- orig/clientserver.c 2005-01-01 21:11:00 |
3d3aaf9f | 38 | +++ clientserver.c 2004-08-10 15:44:15 |
37da98ae | 39 | @@ -49,12 +49,14 @@ extern int no_detach; |
40e20a69 WD |
40 | extern int default_af_hint; |
41 | extern char *bind_address; | |
42 | extern struct exclude_list_struct server_exclude_list; | |
43 | -extern char *exclude_path_prefix; | |
44 | extern char *config_file; | |
45 | extern char *files_from; | |
40e20a69 WD |
46 | |
47 | char *auth_user; | |
48 | ||
3d3aaf9f | 49 | +/* Length of lp_path() string when in daemon mode & not chrooted, else 0. */ |
45795ec6 WD |
50 | +unsigned int module_dirlen = 0; |
51 | + | |
52 | /** | |
53 | * Run a client connected to an rsyncd. The alternative to this | |
54 | * function for remote-shell connections is do_cmd(). | |
37da98ae | 55 | @@ -304,26 +306,28 @@ static int rsync_module(int f_in, int f_ |
40e20a69 WD |
56 | /* TODO: Perhaps take a list of gids, and make them into the |
57 | * supplementary groups. */ | |
58 | ||
59 | - exclude_path_prefix = use_chroot? "" : lp_path(i); | |
60 | - if (*exclude_path_prefix == '/' && !exclude_path_prefix[1]) | |
61 | - exclude_path_prefix = ""; | |
45795ec6 WD |
62 | + if (use_chroot) { |
63 | + module_dirlen = 0; | |
64 | + set_excludes_dir("/", 1); | |
65 | + } else { | |
66 | + module_dirlen = strlen(lp_path(i)); | |
67 | + set_excludes_dir(lp_path(i), module_dirlen); | |
68 | + } | |
40e20a69 WD |
69 | |
70 | p = lp_include_from(i); | |
71 | add_exclude_file(&server_exclude_list, p, | |
72 | - XFLG_FATAL_ERRORS | XFLG_DEF_INCLUDE); | |
73 | + XFLG_FATAL_ERRORS | XFLG_DEF_INCLUDE | XFLG_ABS_PATH); | |
74 | ||
75 | p = lp_include(i); | |
76 | add_exclude(&server_exclude_list, p, | |
77 | - XFLG_WORD_SPLIT | XFLG_DEF_INCLUDE); | |
78 | + XFLG_WORD_SPLIT | XFLG_DEF_INCLUDE | XFLG_ABS_PATH); | |
79 | ||
80 | p = lp_exclude_from(i); | |
81 | add_exclude_file(&server_exclude_list, p, | |
82 | - XFLG_FATAL_ERRORS); | |
83 | + XFLG_FATAL_ERRORS | XFLG_ABS_PATH); | |
84 | ||
85 | p = lp_exclude(i); | |
86 | - add_exclude(&server_exclude_list, p, XFLG_WORD_SPLIT); | |
45795ec6 | 87 | - |
40e20a69 | 88 | - exclude_path_prefix = NULL; |
45795ec6 | 89 | + add_exclude(&server_exclude_list, p, XFLG_WORD_SPLIT | XFLG_ABS_PATH); |
40e20a69 WD |
90 | |
91 | log_init(); | |
92 | ||
2e064775 | 93 | --- orig/exclude.c 2005-01-13 23:15:56 |
6e313719 | 94 | +++ exclude.c 2005-01-16 01:05:56 |
b338da5b | 95 | @@ -30,13 +30,69 @@ extern int verbose; |
a55d21aa WD |
96 | extern int eol_nulls; |
97 | extern int list_only; | |
98 | extern int recurse; | |
99 | +extern int io_error; | |
56babefa | 100 | +extern int sanitize_paths; |
a55d21aa WD |
101 | |
102 | extern char curr_dir[]; | |
56babefa | 103 | +extern unsigned int curr_dir_len; |
45795ec6 | 104 | +extern unsigned int module_dirlen; |
a55d21aa | 105 | |
d8af8661 | 106 | struct exclude_list_struct exclude_list = { 0, 0, "" }; |
524989ae | 107 | -struct exclude_list_struct local_exclude_list = { 0, 0, "per-dir .cvsignore " }; |
d8af8661 | 108 | struct exclude_list_struct server_exclude_list = { 0, 0, "server " }; |
40e20a69 WD |
109 | -char *exclude_path_prefix = NULL; |
110 | + | |
eabda998 | 111 | +struct mergelist_save_struct { |
d1e7c1c8 | 112 | + struct exclude_list_struct *array; |
d8af8661 WD |
113 | + int count; |
114 | +}; | |
524989ae | 115 | + |
db4f43dd WD |
116 | +/* The dirbuf is set by push_local_excludes() to the current subdirectory |
117 | + * relative to curr_dir that is being processed. The path always has a | |
45795ec6 WD |
118 | + * trailing slash appended, and the variable dirbuf_len contains the length |
119 | + * of this path prefix. The path is always absolute. */ | |
120 | +static char dirbuf[MAXPATHLEN+1]; | |
121 | +static unsigned int dirbuf_len = 0; | |
b338da5b | 122 | +static int dirbuf_depth; |
45795ec6 WD |
123 | + |
124 | +/* This is True when we're scanning parent dirs for per-dir merge-files. */ | |
125 | +static BOOL parent_dirscan = False; | |
db4f43dd WD |
126 | + |
127 | +/* This array contains a list of all the currently active per-dir merge | |
128 | + * files. This makes it easier to save the appropriate values when we | |
129 | + * "push" down into each subdirectory. */ | |
d34d9fad WD |
130 | +static struct exclude_struct **mergelist_parents; |
131 | +static int mergelist_cnt = 0; | |
132 | +static int mergelist_size = 0; | |
a55d21aa | 133 | + |
d1e7c1c8 WD |
134 | +/* Each exclude_list_struct describes a singly-linked list by keeping track |
135 | + * of both the head and tail pointers. The list is slightly unusual in that | |
136 | + * a parent-dir's content can be appended to the end of the local list in a | |
137 | + * special way: the last item in the local list has its "next" pointer set | |
0c7d1fd8 | 138 | + * to point to the inherited list, but the local list's tail pointer points |
d1e7c1c8 | 139 | + * at the end of the local list. Thus, if the local list is empty, the head |
0c7d1fd8 | 140 | + * will be pointing at the inherited content but the tail will be NULL. To |
d1e7c1c8 WD |
141 | + * help you visualize this, here are the possible list arrangements: |
142 | + * | |
143 | + * Completely Empty Local Content Only | |
144 | + * ================================== ==================================== | |
145 | + * head -> NULL head -> Local1 -> Local2 -> NULL | |
146 | + * tail -> NULL tail -------------^ | |
147 | + * | |
148 | + * Inherited Content Only Both Local and Inherited Content | |
149 | + * ================================== ==================================== | |
150 | + * head -> Parent1 -> Parent2 -> NULL head -> L1 -> L2 -> P1 -> P2 -> NULL | |
151 | + * tail -> NULL tail ---------^ | |
152 | + * | |
2e064775 | 153 | + * This means that anyone wanting to traverse the whole list to use it just |
d1e7c1c8 WD |
154 | + * needs to start at the head and use the "next" pointers until it goes |
155 | + * NULL. To add new local content, we insert the item after the tail item | |
156 | + * and update the tail (obviously, if "tail" was NULL, we insert it at the | |
157 | + * head). To clear the local list, WE MUST NOT FREE THE INHERITED CONTENT | |
bc95f62b WD |
158 | + * because it is shared between the current list and our parent list(s). |
159 | + * The easiest way to handle this is to simply truncate the list after the | |
160 | + * tail item and then free the local list from the head. When inheriting | |
161 | + * the list for a new local dir, we just save off the exclude_list_struct | |
0c7d1fd8 | 162 | + * values (so we can pop back to them later) and set the tail to NULL. |
d1e7c1c8 | 163 | + */ |
40e20a69 | 164 | |
0c7d1fd8 WD |
165 | /** Build an exclude structure given an exclude pattern. */ |
166 | static void make_exclude(struct exclude_list_struct *listp, const char *pat, | |
6e313719 | 167 | @@ -46,23 +102,44 @@ static void make_exclude(struct exclude_ |
a55d21aa | 168 | const char *cp; |
0c7d1fd8 WD |
169 | unsigned int ex_len; |
170 | ||
d34d9fad WD |
171 | + if (verbose > 2) { |
172 | + rprintf(FINFO, "[%s] add_exclude(%.*s, %s%s%sclude)\n", | |
173 | + who_am_i(), (int)pat_len, pat, listp->debug_type, | |
174 | + mflags & MATCHFLG_MERGE_FILE ? "FILE " : "", | |
175 | + mflags & MATCHFLG_INCLUDE ? "in" : "ex"); | |
176 | + } | |
177 | + | |
524989ae | 178 | + if (mflags & MATCHFLG_MERGE_FILE) { |
eabda998 | 179 | + int i; |
2e064775 | 180 | + /* If the local merge file was already mentioned, don't |
524989ae | 181 | + * add it again. */ |
eabda998 WD |
182 | + for (i = 0; i < mergelist_cnt; i++) { |
183 | + struct exclude_struct *ex = mergelist_parents[i]; | |
184 | + if (strlen(ex->pattern) == pat_len | |
d8af8661 | 185 | + && memcmp(ex->pattern, pat, pat_len) == 0) |
a55d21aa WD |
186 | + return; |
187 | + } | |
a55d21aa | 188 | + } |
0c7d1fd8 | 189 | + |
a55d21aa WD |
190 | ret = new(struct exclude_struct); |
191 | if (!ret) | |
192 | out_of_memory("make_exclude"); | |
40e20a69 WD |
193 | |
194 | memset(ret, 0, sizeof ret[0]); | |
195 | ||
196 | - if (exclude_path_prefix) | |
197 | - mflags |= MATCHFLG_ABS_PATH; | |
198 | - if (exclude_path_prefix && *pat == '/') | |
199 | - ex_len = strlen(exclude_path_prefix); | |
200 | - else | |
201 | + if (mflags & MATCHFLG_ABS_PATH) { | |
202 | + if (*pat != '/') { | |
203 | + mflags &= ~MATCHFLG_ABS_PATH; | |
204 | + ex_len = 0; | |
45795ec6 WD |
205 | + } else |
206 | + ex_len = dirbuf_len - module_dirlen - 1; | |
40e20a69 WD |
207 | + } else |
208 | ex_len = 0; | |
209 | ret->pattern = new_array(char, ex_len + pat_len + 1); | |
210 | if (!ret->pattern) | |
211 | out_of_memory("make_exclude"); | |
45795ec6 | 212 | if (ex_len) |
40e20a69 | 213 | - memcpy(ret->pattern, exclude_path_prefix, ex_len); |
5f98a4b1 | 214 | + memcpy(ret->pattern, dirbuf + module_dirlen, ex_len); |
40e20a69 WD |
215 | strlcpy(ret->pattern + ex_len, pat, pat_len + 1); |
216 | pat_len += ex_len; | |
217 | ||
6e313719 | 218 | @@ -81,14 +158,40 @@ static void make_exclude(struct exclude_ |
7b22909b | 219 | mflags |= MATCHFLG_DIRECTORY; |
a55d21aa WD |
220 | } |
221 | ||
7b22909b | 222 | - for (cp = ret->pattern; (cp = strchr(cp, '/')) != NULL; cp++) |
bc95f62b | 223 | - ret->slash_cnt++; |
524989ae | 224 | + if (mflags & MATCHFLG_MERGE_FILE) { |
d8af8661 WD |
225 | + struct exclude_list_struct *lp |
226 | + = new_array(struct exclude_list_struct, 1); | |
227 | + if (!lp) | |
a55d21aa | 228 | + out_of_memory("make_exclude"); |
7cb7ae4e | 229 | + lp->head = lp->tail = NULL; |
d34d9fad WD |
230 | + if ((cp = strrchr(ret->pattern, '/')) != NULL) |
231 | + cp++; | |
232 | + else | |
233 | + cp = ret->pattern; | |
234 | + if (asprintf(&lp->debug_type, "per-dir %s ", cp) < 0) | |
a55d21aa | 235 | + out_of_memory("make_exclude"); |
eabda998 WD |
236 | + ret->u.mergelist = lp; |
237 | + if (mergelist_cnt == mergelist_size) { | |
d34d9fad WD |
238 | + mergelist_size += 5; |
239 | + mergelist_parents = realloc_array(mergelist_parents, | |
240 | + struct exclude_struct *, | |
241 | + mergelist_size); | |
242 | + if (!mergelist_parents) | |
243 | + out_of_memory("make_exclude"); | |
eabda998 WD |
244 | + } |
245 | + mergelist_parents[mergelist_cnt++] = ret; | |
7b22909b WD |
246 | + } else { |
247 | + for (cp = ret->pattern; (cp = strchr(cp, '/')) != NULL; cp++) | |
248 | + ret->u.slash_cnt++; | |
abe86b1f | 249 | + } |
7b22909b | 250 | |
0c7d1fd8 | 251 | ret->match_flags = mflags; |
a55d21aa | 252 | |
7b22909b WD |
253 | - if (!listp->tail) |
254 | + if (!listp->tail) { | |
255 | + ret->next = listp->head; | |
256 | listp->head = listp->tail = ret; | |
257 | - else { | |
258 | + } else { | |
259 | + ret->next = listp->tail->next; | |
260 | listp->tail->next = ret; | |
261 | listp->tail = ret; | |
262 | } | |
6e313719 | 263 | @@ -96,22 +199,267 @@ static void make_exclude(struct exclude_ |
d8af8661 WD |
264 | |
265 | static void free_exclude(struct exclude_struct *ex) | |
266 | { | |
267 | + if (ex->match_flags & MATCHFLG_MERGE_FILE) { | |
eabda998 WD |
268 | + free(ex->u.mergelist->debug_type); |
269 | + free(ex->u.mergelist); | |
d8af8661 WD |
270 | + } |
271 | free(ex->pattern); | |
a55d21aa WD |
272 | free(ex); |
273 | } | |
274 | ||
d8af8661 WD |
275 | -void clear_exclude_list(struct exclude_list_struct *listp) |
276 | +static void clear_exclude_list(struct exclude_list_struct *listp) | |
a55d21aa | 277 | { |
7cb7ae4e WD |
278 | - struct exclude_struct *ent, *next; |
279 | - | |
280 | - for (ent = listp->head; ent; ent = next) { | |
281 | - next = ent->next; | |
282 | - free_exclude(ent); | |
283 | + if (listp->tail) { | |
284 | + struct exclude_struct *ent, *next; | |
bc95f62b | 285 | + /* Truncate any inherited items from the local list. */ |
7cb7ae4e | 286 | + listp->tail->next = NULL; |
dc5cce3c | 287 | + /* Now free everything that is left. */ |
7cb7ae4e WD |
288 | + for (ent = listp->head; ent; ent = next) { |
289 | + next = ent->next; | |
290 | + free_exclude(ent); | |
291 | + } | |
524989ae WD |
292 | } |
293 | ||
7cb7ae4e WD |
294 | listp->head = listp->tail = NULL; |
295 | } | |
a55d21aa | 296 | |
db4f43dd | 297 | +/* This returns an expanded (absolute) filename for the merge-file name if |
45795ec6 | 298 | + * the name has any slashes in it OR if the parent_dirscan var is True; |
db4f43dd | 299 | + * otherwise it returns the original merge_file name. If the len_ptr value |
45795ec6 WD |
300 | + * is non-NULL the merge_file name is limited by the referenced length |
301 | + * value and will be updated with the length of the resulting name. We | |
302 | + * always return a name that is null terminated, even if the merge_file | |
303 | + * name was not. */ | |
304 | +static char *parse_merge_name(const char *merge_file, unsigned int *len_ptr, | |
305 | + unsigned int prefix_skip) | |
41ebea83 WD |
306 | +{ |
307 | + static char buf[MAXPATHLEN]; | |
308 | + char *fn, tmpbuf[MAXPATHLEN]; | |
45795ec6 | 309 | + unsigned int fn_len; |
41ebea83 | 310 | + |
40e20a69 | 311 | + if (!parent_dirscan && *merge_file != '/') { |
db4f43dd | 312 | + /* Return the name unchanged it doesn't have any slashes. */ |
41ebea83 | 313 | + if (len_ptr) { |
db4f43dd WD |
314 | + const char *p = merge_file + *len_ptr; |
315 | + while (--p > merge_file && *p != '/') {} | |
316 | + if (p == merge_file) { | |
317 | + strlcpy(buf, merge_file, *len_ptr + 1); | |
318 | + return buf; | |
319 | + } | |
320 | + } else if (strchr(merge_file, '/') == NULL) | |
41ebea83 WD |
321 | + return (char *)merge_file; |
322 | + } | |
323 | + | |
324 | + fn = *merge_file == '/' ? buf : tmpbuf; | |
325 | + if (sanitize_paths) { | |
45795ec6 | 326 | + const char *r = prefix_skip ? "/" : NULL; |
41ebea83 WD |
327 | + /* null-terminate the name if it isn't already */ |
328 | + if (len_ptr && merge_file[*len_ptr]) { | |
329 | + char *to = fn == buf ? tmpbuf : buf; | |
330 | + strlcpy(to, merge_file, *len_ptr + 1); | |
331 | + merge_file = to; | |
332 | + } | |
b338da5b | 333 | + if (!sanitize_path(fn, merge_file, r, dirbuf_depth)) { |
45795ec6 | 334 | + rprintf(FERROR, "merge-file name overflows: %s\n", |
41ebea83 WD |
335 | + merge_file); |
336 | + return NULL; | |
337 | + } | |
338 | + } else { | |
339 | + strlcpy(fn, merge_file, len_ptr ? *len_ptr + 1 : MAXPATHLEN); | |
20f8d513 | 340 | + clean_fname(fn, 1); |
41ebea83 WD |
341 | + } |
342 | + | |
41ebea83 | 343 | + fn_len = strlen(fn); |
45795ec6 WD |
344 | + if (fn == buf) |
345 | + goto done; | |
346 | + | |
347 | + if (dirbuf_len + fn_len >= MAXPATHLEN) { | |
348 | + rprintf(FERROR, "merge-file name overflows: %s\n", fn); | |
41ebea83 WD |
349 | + return NULL; |
350 | + } | |
45795ec6 WD |
351 | + memcpy(buf, dirbuf + prefix_skip, dirbuf_len - prefix_skip); |
352 | + memcpy(buf + dirbuf_len - prefix_skip, fn, fn_len + 1); | |
20f8d513 | 353 | + fn_len = clean_fname(buf, 1); |
45795ec6 WD |
354 | + |
355 | + done: | |
41ebea83 WD |
356 | + if (len_ptr) |
357 | + *len_ptr = fn_len; | |
41ebea83 WD |
358 | + return buf; |
359 | +} | |
360 | + | |
45795ec6 WD |
361 | +/* Sets the dirbuf and dirbuf_len values. */ |
362 | +void set_excludes_dir(const char *dir, unsigned int dirlen) | |
40e20a69 | 363 | +{ |
45795ec6 WD |
364 | + unsigned int len; |
365 | + if (*dir != '/') { | |
366 | + memcpy(dirbuf, curr_dir, curr_dir_len); | |
367 | + dirbuf[curr_dir_len] = '/'; | |
368 | + len = curr_dir_len + 1; | |
470aa8d5 WD |
369 | + if (len + dirlen >= MAXPATHLEN) |
370 | + dirlen = 0; | |
45795ec6 WD |
371 | + } else |
372 | + len = 0; | |
373 | + memcpy(dirbuf + len, dir, dirlen); | |
374 | + dirbuf[dirlen + len] = '\0'; | |
20f8d513 | 375 | + dirbuf_len = clean_fname(dirbuf, 1); |
45795ec6 WD |
376 | + if (dirbuf_len > 1 && dirbuf[dirbuf_len-1] == '.' |
377 | + && dirbuf[dirbuf_len-2] == '/') | |
378 | + dirbuf_len -= 2; | |
379 | + dirbuf[dirbuf_len++] = '/'; | |
380 | + dirbuf[dirbuf_len] = '\0'; | |
b338da5b WD |
381 | + if (sanitize_paths) |
382 | + dirbuf_depth = count_dir_elements(dirbuf + module_dirlen); | |
40e20a69 WD |
383 | +} |
384 | + | |
45795ec6 | 385 | +/* This routine takes a per-dir merge-file entry and finishes its setup. |
db4f43dd WD |
386 | + * If the name has a path portion then we check to see if it refers to a |
387 | + * parent directory of the first transfer dir. If it does, we scan all the | |
388 | + * dirs from that point through the parent dir of the transfer dir looking | |
45795ec6 WD |
389 | + * for the per-dir merge-file in each one. */ |
390 | +static BOOL setup_merge_file(struct exclude_struct *ex, | |
391 | + struct exclude_list_struct *lp, int flags) | |
1e476835 | 392 | +{ |
d34d9fad | 393 | + char buf[MAXPATHLEN]; |
db4f43dd WD |
394 | + char *x, *y, *pat = ex->pattern; |
395 | + unsigned int len; | |
56babefa | 396 | + |
45795ec6 WD |
397 | + if (!(x = parse_merge_name(pat, NULL, 0)) || *x != '/') |
398 | + return 0; | |
1e476835 | 399 | + |
db4f43dd WD |
400 | + y = strrchr(x, '/'); |
401 | + *y = '\0'; | |
402 | + ex->pattern = strdup(y+1); | |
db4f43dd WD |
403 | + if (!*x) |
404 | + x = "/"; | |
405 | + if (*x == '/') | |
406 | + strlcpy(buf, x, MAXPATHLEN); | |
d34d9fad | 407 | + else |
db4f43dd | 408 | + pathjoin(buf, MAXPATHLEN, dirbuf, x); |
d34d9fad | 409 | + |
20f8d513 | 410 | + len = clean_fname(buf, 1); |
db4f43dd WD |
411 | + if (len != 1 && len < MAXPATHLEN-1) { |
412 | + buf[len++] = '/'; | |
413 | + buf[len] = '\0'; | |
414 | + } | |
db4f43dd | 415 | + /* This ensures that the specified dir is a parent of the transfer. */ |
45795ec6 | 416 | + for (x = buf, y = dirbuf; *x && *x == *y; x++, y++) {} |
d34d9fad | 417 | + if (*x) |
db4f43dd | 418 | + y += strlen(y); /* nope -- skip the scan */ |
d34d9fad | 419 | + |
45795ec6 | 420 | + parent_dirscan = True; |
d34d9fad WD |
421 | + while (*y) { |
422 | + char save[MAXPATHLEN]; | |
41ebea83 | 423 | + strlcpy(save, y, MAXPATHLEN); |
db4f43dd | 424 | + *y = '\0'; |
45795ec6 | 425 | + dirbuf_len = y - dirbuf; |
db4f43dd | 426 | + strlcpy(x, ex->pattern, MAXPATHLEN - (x - buf)); |
40e20a69 WD |
427 | + add_exclude_file(lp, buf, flags | XFLG_ABS_PATH); |
428 | + if (ex->match_flags & MATCHFLG_CVSIGNORE) | |
429 | + lp->head = NULL; /* CVS doesn't inherit rules. */ | |
d34d9fad | 430 | + lp->tail = NULL; |
41ebea83 | 431 | + strlcpy(y, save, MAXPATHLEN); |
d34d9fad | 432 | + while ((*x++ = *y++) != '/') {} |
1e476835 | 433 | + } |
45795ec6 | 434 | + parent_dirscan = False; |
db4f43dd | 435 | + free(pat); |
45795ec6 | 436 | + return 1; |
1e476835 WD |
437 | +} |
438 | + | |
db4f43dd | 439 | +/* Each time rsync changes to a new directory it call this function to |
45795ec6 WD |
440 | + * handle all the per-dir merge-files. The "dir" value is the current path |
441 | + * relative to curr_dir (which might not be null-terminated). We copy it | |
442 | + * into dirbuf so that we can easily append a file name on the end. */ | |
40e20a69 | 443 | +void *push_local_excludes(const char *dir, unsigned int dirlen) |
a55d21aa | 444 | +{ |
eabda998 WD |
445 | + struct mergelist_save_struct *push; |
446 | + struct exclude_list_struct *ap; | |
447 | + int i; | |
448 | + | |
45795ec6 | 449 | + set_excludes_dir(dir, dirlen); |
eabda998 WD |
450 | + |
451 | + if (!(push = new_array(struct mergelist_save_struct, 1))) | |
452 | + out_of_memory("push_local_excludes"); | |
453 | + | |
454 | + push->count = mergelist_cnt; | |
455 | + push->array = new_array(struct exclude_list_struct, mergelist_cnt); | |
456 | + if (!push->array) | |
457 | + out_of_memory("push_local_excludes"); | |
524989ae | 458 | + |
eabda998 WD |
459 | + for (i = 0, ap = push->array; i < mergelist_cnt; i++) { |
460 | + memcpy(ap++, mergelist_parents[i]->u.mergelist, | |
461 | + sizeof (struct exclude_list_struct)); | |
462 | + } | |
463 | + | |
464 | + /* Note: add_exclude_file() might increase mergelist_cnt, so keep | |
465 | + * this loop separate from the above loop. */ | |
466 | + for (i = 0; i < mergelist_cnt; i++) { | |
467 | + struct exclude_struct *ex = mergelist_parents[i]; | |
468 | + struct exclude_list_struct *lp = ex->u.mergelist; | |
a55d21aa | 469 | + int flags; |
524989ae WD |
470 | + |
471 | + if (verbose > 2) { | |
472 | + rprintf(FINFO, "[%s] pushing %sexclude list\n", | |
d8af8661 | 473 | + who_am_i(), lp->debug_type); |
524989ae | 474 | + } |
d8af8661 | 475 | + |
40e20a69 WD |
476 | + if (ex->match_flags & MATCHFLG_CVSIGNORE) { |
477 | + lp->head = NULL; /* CVS doesn't inherit rules. */ | |
ee1af13c | 478 | + flags = XFLG_WORD_SPLIT | XFLG_WORDS_ONLY; |
40e20a69 | 479 | + } else { |
eabda998 | 480 | + flags = ex->match_flags & MATCHFLG_INCLUDE |
524989ae | 481 | + ? XFLG_DEF_INCLUDE : 0; |
a55d21aa | 482 | + } |
40e20a69 | 483 | + lp->tail = NULL; /* Switch any local rules to inherited. */ |
d34d9fad | 484 | + |
40e20a69 WD |
485 | + if (ex->match_flags & MATCHFLG_FINISH_SETUP) { |
486 | + ex->match_flags &= ~MATCHFLG_FINISH_SETUP; | |
45795ec6 WD |
487 | + if (setup_merge_file(ex, lp, flags)) |
488 | + set_excludes_dir(dir, dirlen); | |
d34d9fad WD |
489 | + } |
490 | + | |
45795ec6 WD |
491 | + if (strlcpy(dirbuf + dirbuf_len, ex->pattern, |
492 | + MAXPATHLEN - dirbuf_len) < MAXPATHLEN - dirbuf_len) | |
40e20a69 | 493 | + add_exclude_file(lp, dirbuf, flags | XFLG_ABS_PATH); |
524989ae | 494 | + else { |
a55d21aa WD |
495 | + io_error |= IOERR_GENERAL; |
496 | + rprintf(FINFO, | |
497 | + "cannot add local excludes in long-named directory %s\n", | |
d8af8661 | 498 | + full_fname(dirbuf)); |
a55d21aa | 499 | + } |
45795ec6 | 500 | + dirbuf[dirbuf_len] = '\0'; |
a55d21aa WD |
501 | + } |
502 | + | |
524989ae | 503 | + return (void*)push; |
a55d21aa WD |
504 | +} |
505 | + | |
eabda998 | 506 | +void pop_local_excludes(void *mem) |
a55d21aa | 507 | +{ |
eabda998 WD |
508 | + struct mergelist_save_struct *pop = (struct mergelist_save_struct*)mem; |
509 | + struct exclude_list_struct *ap; | |
510 | + int i; | |
d8af8661 | 511 | + |
066e3b3e | 512 | + for (i = mergelist_cnt; i-- > 0; ) { |
eabda998 WD |
513 | + struct exclude_struct *ex = mergelist_parents[i]; |
514 | + struct exclude_list_struct *lp = ex->u.mergelist; | |
524989ae | 515 | + |
524989ae WD |
516 | + if (verbose > 2) { |
517 | + rprintf(FINFO, "[%s] popping %sexclude list\n", | |
d8af8661 | 518 | + who_am_i(), lp->debug_type); |
524989ae | 519 | + } |
d8af8661 WD |
520 | + |
521 | + clear_exclude_list(lp); | |
a55d21aa | 522 | + } |
d8af8661 | 523 | + |
40e20a69 | 524 | + mergelist_cnt = pop->count; |
eabda998 WD |
525 | + for (i = 0, ap = pop->array; i < mergelist_cnt; i++) { |
526 | + memcpy(mergelist_parents[i]->u.mergelist, ap++, | |
527 | + sizeof (struct exclude_list_struct)); | |
528 | + } | |
d8af8661 WD |
529 | + |
530 | + free(pop->array); | |
531 | + free(pop); | |
7cb7ae4e WD |
532 | +} |
533 | + | |
a55d21aa | 534 | static int check_one_exclude(char *name, struct exclude_struct *ex, |
7cb7ae4e WD |
535 | int name_is_dir) |
536 | { | |
6e313719 | 537 | @@ -125,13 +473,14 @@ static int check_one_exclude(char *name, |
bc95f62b WD |
538 | /* If the pattern does not have any slashes AND it does not have |
539 | * a "**" (which could match a slash), then we just match the | |
540 | * name portion of the path. */ | |
541 | - if (!ex->slash_cnt && !(ex->match_flags & MATCHFLG_WILD2)) { | |
542 | + if (!ex->u.slash_cnt && !(ex->match_flags & MATCHFLG_WILD2)) { | |
543 | if ((p = strrchr(name,'/')) != NULL) | |
544 | name = p+1; | |
545 | } | |
3d3aaf9f WD |
546 | else if (ex->match_flags & MATCHFLG_ABS_PATH && *name != '/' |
547 | - && curr_dir[1]) { | |
548 | - pathjoin(full_name, sizeof full_name, curr_dir + 1, name); | |
549 | + && curr_dir_len > module_dirlen + 1) { | |
550 | + pathjoin(full_name, sizeof full_name, | |
551 | + curr_dir + module_dirlen + 1, name); | |
045caa90 WD |
552 | name = full_name; |
553 | } | |
554 | ||
6e313719 | 555 | @@ -148,9 +497,9 @@ static int check_one_exclude(char *name, |
bc95f62b WD |
556 | if (ex->match_flags & MATCHFLG_WILD) { |
557 | /* A non-anchored match with an infix slash and no "**" | |
558 | * needs to match the last slash_cnt+1 name elements. */ | |
0c7d1fd8 WD |
559 | - if (!match_start && ex->slash_cnt |
560 | + if (!match_start && ex->u.slash_cnt | |
561 | && !(ex->match_flags & MATCHFLG_WILD2)) { | |
bc95f62b WD |
562 | - int cnt = ex->slash_cnt + 1; |
563 | + int cnt = ex->u.slash_cnt + 1; | |
564 | for (p = name + strlen(name) - 1; p >= name; p--) { | |
565 | if (*p == '/' && !--cnt) | |
566 | break; | |
6e313719 | 567 | @@ -221,6 +570,13 @@ int check_exclude(struct exclude_list_st |
a55d21aa WD |
568 | struct exclude_struct *ent; |
569 | ||
570 | for (ent = listp->head; ent; ent = ent->next) { | |
524989ae | 571 | + if (ent->match_flags & MATCHFLG_MERGE_FILE) { |
eabda998 | 572 | + int rc = check_exclude(ent->u.mergelist, name, |
d8af8661 | 573 | + name_is_dir); |
a55d21aa WD |
574 | + if (rc) |
575 | + return rc; | |
576 | + continue; | |
577 | + } | |
578 | if (check_one_exclude(name, ent, name_is_dir)) { | |
579 | report_exclude_result(name, ent, name_is_dir, | |
580 | listp->debug_type); | |
6e313719 | 581 | @@ -254,12 +610,45 @@ static const char *get_exclude_tok(const |
a55d21aa WD |
582 | p = (const char *)s; |
583 | } | |
584 | ||
585 | - /* Is this a '+' or '-' followed by a space (not whitespace)? */ | |
2e064775 | 586 | - if (!(xflags & XFLG_WORDS_ONLY) |
a55d21aa | 587 | - && (*s == '-' || *s == '+') && s[1] == ' ') { |
2e064775 WD |
588 | + /* Check for a leading '+' or '-'. */ |
589 | + if (!(xflags & XFLG_WORDS_ONLY) && (*s == '-' || *s == '+')) { | |
6e313719 WD |
590 | + if (!s[1]) { |
591 | + rprintf(FERROR, | |
592 | + "no pattern followed %c in %sclude file.\n", | |
593 | + *s, xflags & XFLG_DEF_INCLUDE ? "in" : "ex"); | |
594 | + exit_cleanup(RERR_SYNTAX); | |
595 | + } | |
0c7d1fd8 WD |
596 | if (*s == '+') |
597 | mflags |= MATCHFLG_INCLUDE; | |
2e064775 | 598 | - s += 2; |
6e313719 | 599 | + while (*++s && *s != ' ') { |
2e064775 | 600 | + switch (*s) { |
6e313719 WD |
601 | + case 'C': |
602 | + mflags |= MATCHFLG_MERGE_FILE | |
603 | + | MATCHFLG_PERDIR_MERGE | |
604 | + | MATCHFLG_FINISH_SETUP | |
605 | + | MATCHFLG_CVSIGNORE; | |
606 | + mflags &= ~MATCHFLG_INCLUDE; | |
607 | + break; | |
608 | + case 'E': | |
609 | + mflags |= MATCHFLG_EXCLUDE_SELF; | |
610 | + break; | |
2e064775 WD |
611 | + case 'p': |
612 | + mflags |= MATCHFLG_MERGE_FILE | |
613 | + | MATCHFLG_PERDIR_MERGE | |
614 | + | MATCHFLG_FINISH_SETUP; | |
615 | + break; | |
616 | + case 'm': | |
617 | + mflags |= MATCHFLG_MERGE_FILE; | |
618 | + break; | |
619 | + default: | |
620 | + rprintf(FERROR, | |
621 | + "invalid include/exclude option after %c: %c\n", | |
622 | + *p, *s); | |
623 | + exit_cleanup(RERR_SYNTAX); | |
d34d9fad | 624 | + } |
a55d21aa | 625 | + } |
6e313719 WD |
626 | + if (*s) |
627 | + s++; | |
0c7d1fd8 WD |
628 | } else if (xflags & XFLG_DEF_INCLUDE) |
629 | mflags |= MATCHFLG_INCLUDE; | |
2e064775 | 630 | if (xflags & XFLG_DIRECTORY) |
6e313719 WD |
631 | @@ -274,8 +663,27 @@ static const char *get_exclude_tok(const |
632 | } else | |
633 | len = strlen(s); | |
40e20a69 | 634 | |
6e313719 WD |
635 | + if (mflags & MATCHFLG_PERDIR_MERGE) { |
636 | + if (mflags & MATCHFLG_CVSIGNORE) { | |
637 | + if (len) { | |
638 | + rprintf(FERROR, | |
639 | + "unexpected trailing char%s after -C: `%s'\n", | |
640 | + len == 1 ? "" : "s", s); | |
641 | + exit_cleanup(RERR_SYNTAX); | |
642 | + } | |
643 | + s = ".cvsignore"; | |
644 | + len = 10; | |
645 | + } else if ((len == 10 || (len > 10 && s[len-11] == '/')) | |
646 | + && strncmp(s+len-10, ".cvsignore", 10) == 0) { | |
647 | + mflags |= MATCHFLG_CVSIGNORE; | |
648 | + mflags &= ~MATCHFLG_INCLUDE; | |
649 | + } | |
650 | + } | |
651 | + | |
5388f859 | 652 | if (*p == '!' && len == 1) |
40e20a69 WD |
653 | mflags |= MATCHFLG_CLEAR_LIST; |
654 | + if (xflags & XFLG_ABS_PATH) | |
655 | + mflags |= MATCHFLG_ABS_PATH; | |
656 | ||
657 | *len_ptr = len; | |
658 | *flag_ptr = mflags; | |
6e313719 | 659 | @@ -287,7 +695,7 @@ void add_exclude(struct exclude_list_str |
45795ec6 WD |
660 | int xflags) |
661 | { | |
662 | unsigned int pat_len, mflags; | |
663 | - const char *cp; | |
664 | + const char *cp, *p; | |
665 | ||
666 | if (!pattern) | |
667 | return; | |
6e313719 | 668 | @@ -295,9 +703,15 @@ void add_exclude(struct exclude_list_str |
045caa90 WD |
669 | cp = pattern; |
670 | pat_len = 0; | |
671 | while (1) { | |
672 | + /* Remember that the returned string is NOT '\0' terminated! */ | |
673 | cp = get_exclude_tok(cp + pat_len, &pat_len, &mflags, xflags); | |
674 | if (!pat_len) | |
675 | break; | |
41ebea83 WD |
676 | + if (pat_len >= MAXPATHLEN) { |
677 | + rprintf(FERROR, "discarding over-long exclude: %s\n", | |
678 | + cp); | |
679 | + continue; | |
680 | + } | |
681 | ||
682 | if (mflags & MATCHFLG_CLEAR_LIST) { | |
683 | if (verbose > 2) { | |
6e313719 | 684 | @@ -309,13 +723,37 @@ void add_exclude(struct exclude_list_str |
0c7d1fd8 WD |
685 | continue; |
686 | } | |
a55d21aa | 687 | |
d34d9fad WD |
688 | - make_exclude(listp, cp, pat_len, mflags); |
689 | - | |
690 | - if (verbose > 2) { | |
691 | - rprintf(FINFO, "[%s] add_exclude(%.*s, %s%sclude)\n", | |
692 | - who_am_i(), (int)pat_len, cp, listp->debug_type, | |
693 | - mflags & MATCHFLG_INCLUDE ? "in" : "ex"); | |
524989ae | 694 | + if (mflags & MATCHFLG_MERGE_FILE) { |
45795ec6 | 695 | + unsigned int len = pat_len; |
6e313719 WD |
696 | + if (mflags & MATCHFLG_EXCLUDE_SELF) { |
697 | + const char *name = strrchr(cp, '/'); | |
698 | + if (name) | |
699 | + len -= ++name - cp; | |
700 | + else | |
701 | + name = cp; | |
702 | + make_exclude(listp, name, len, 0); | |
703 | + mflags &= ~MATCHFLG_EXCLUDE_SELF; | |
704 | + len = pat_len; | |
705 | + } | |
41ebea83 | 706 | + if (mflags & MATCHFLG_PERDIR_MERGE) { |
40e20a69 | 707 | + if (parent_dirscan) { |
45795ec6 | 708 | + if (!(p = parse_merge_name(cp, &len, module_dirlen))) |
41ebea83 | 709 | + continue; |
45795ec6 | 710 | + make_exclude(listp, p, len, mflags); |
d34d9fad WD |
711 | + continue; |
712 | + } | |
41ebea83 | 713 | + } else { |
6e313719 | 714 | + int flgs = XFLG_FATAL_ERRORS; |
45795ec6 | 715 | + if (!(p = parse_merge_name(cp, &len, 0))) |
d34d9fad | 716 | + continue; |
6e313719 WD |
717 | + if (mflags & MATCHFLG_INCLUDE) |
718 | + flgs |= XFLG_DEF_INCLUDE; | |
719 | + add_exclude_file(listp, p, flgs); | |
41ebea83 | 720 | + continue; |
0c7d1fd8 | 721 | + } |
a55d21aa | 722 | } |
d34d9fad WD |
723 | + |
724 | + make_exclude(listp, cp, pat_len, mflags); | |
0c7d1fd8 | 725 | } |
d34d9fad WD |
726 | } |
727 | ||
6e313719 | 728 | @@ -324,7 +762,7 @@ void add_exclude_file(struct exclude_lis |
41ebea83 WD |
729 | int xflags) |
730 | { | |
731 | FILE *fp; | |
732 | - char line[MAXPATHLEN+3]; /* Room for "x " prefix and trailing slash. */ | |
2e064775 | 733 | + char line[MAXPATHLEN+4]; /* Room for prefix chars and trailing slash. */ |
41ebea83 WD |
734 | char *eob = line + sizeof line - 1; |
735 | int word_split = xflags & XFLG_WORD_SPLIT; | |
736 | ||
6e313719 WD |
737 | @@ -338,13 +776,19 @@ void add_exclude_file(struct exclude_lis |
738 | if (!fp) { | |
739 | if (xflags & XFLG_FATAL_ERRORS) { | |
740 | rsyserr(FERROR, errno, | |
741 | - "failed to open %s file %s", | |
742 | - xflags & XFLG_DEF_INCLUDE ? "include" : "exclude", | |
743 | + "failed to open %sclude file %s", | |
744 | + xflags & XFLG_DEF_INCLUDE ? "in" : "ex", | |
745 | fname); | |
746 | exit_cleanup(RERR_FILEIO); | |
45795ec6 | 747 | } |
c4e46f36 WD |
748 | return; |
749 | } | |
45795ec6 WD |
750 | + dirbuf[dirbuf_len] = '\0'; |
751 | + | |
c4e46f36 | 752 | + if (verbose > 2) { |
1e476835 WD |
753 | + rprintf(FINFO, "[%s] add_exclude_file(%s,%d)\n", |
754 | + who_am_i(), fname, xflags); | |
c4e46f36 | 755 | + } |
45795ec6 | 756 | |
c4e46f36 WD |
757 | while (1) { |
758 | char *s = line; | |
6e313719 | 759 | @@ -402,7 +846,20 @@ void send_exclude_list(int f) |
2e064775 WD |
760 | p[l] = '\0'; |
761 | } | |
762 | ||
763 | - if (ent->match_flags & MATCHFLG_INCLUDE) { | |
764 | + if (ent->match_flags & MATCHFLG_MERGE_FILE) { | |
41ebea83 | 765 | + char buf[32], *op = buf; |
2e064775 WD |
766 | + if (ent->match_flags & MATCHFLG_INCLUDE) |
767 | + *op++ = '+'; | |
768 | + else | |
41ebea83 | 769 | + *op++ = '-'; |
2e064775 | 770 | + if (ent->match_flags & MATCHFLG_PERDIR_MERGE) |
41ebea83 | 771 | + *op++ = 'p'; |
2e064775 WD |
772 | + else |
773 | + *op++ = 'm'; | |
774 | + *op++ = ' '; | |
41ebea83 WD |
775 | + write_int(f, l + (op - buf)); |
776 | + write_buf(f, buf, op - buf); | |
2e064775 | 777 | + } else if (ent->match_flags & MATCHFLG_INCLUDE) { |
a55d21aa | 778 | write_int(f, l + 2); |
2e064775 WD |
779 | write_buf(f, "+ ", 2); |
780 | } else if (*p == '-' || *p == '+') { | |
6e313719 | 781 | @@ -419,7 +876,7 @@ void send_exclude_list(int f) |
2e064775 WD |
782 | |
783 | void recv_exclude_list(int f) | |
784 | { | |
785 | - char line[MAXPATHLEN+3]; /* Room for "x " prefix and trailing slash. */ | |
786 | + char line[MAXPATHLEN+4]; /* Room for prefix and trailing slash. */ | |
787 | unsigned int l; | |
788 | ||
789 | while ((l = read_int(f)) != 0) { | |
6e313719 | 790 | @@ -446,6 +903,7 @@ void add_cvs_excludes(void) |
a55d21aa WD |
791 | char fname[MAXPATHLEN]; |
792 | char *p; | |
793 | ||
6e313719 | 794 | + add_exclude(&exclude_list, "-C", 0); |
a55d21aa | 795 | add_exclude(&exclude_list, default_cvsignore, |
ee1af13c | 796 | XFLG_WORD_SPLIT | XFLG_WORDS_ONLY); |
a55d21aa | 797 | |
37da98ae | 798 | --- orig/flist.c 2005-01-01 21:11:00 |
20f8d513 | 799 | +++ flist.c 2004-08-12 18:59:28 |
a6587818 | 800 | @@ -40,10 +40,9 @@ extern int module_id; |
a55d21aa WD |
801 | extern int ignore_errors; |
802 | extern int numeric_ids; | |
803 | ||
804 | -extern int cvs_exclude; | |
805 | - | |
806 | extern int recurse; | |
807 | extern char curr_dir[MAXPATHLEN]; | |
d34d9fad | 808 | +extern unsigned int curr_dir_len; |
a55d21aa | 809 | extern char *files_from; |
d34d9fad WD |
810 | extern int filesfrom_fd; |
811 | ||
a6587818 | 812 | @@ -67,7 +66,6 @@ extern int list_only; |
a55d21aa WD |
813 | |
814 | extern struct exclude_list_struct exclude_list; | |
815 | extern struct exclude_list_struct server_exclude_list; | |
816 | -extern struct exclude_list_struct local_exclude_list; | |
817 | ||
818 | int io_error; | |
819 | ||
a6587818 | 820 | @@ -223,8 +221,6 @@ int link_stat(const char *path, STRUCT_S |
a55d21aa WD |
821 | */ |
822 | static int check_exclude_file(char *fname, int is_dir, int exclude_level) | |
823 | { | |
824 | - int rc; | |
825 | - | |
826 | #if 0 /* This currently never happens, so avoid a useless compare. */ | |
827 | if (exclude_level == NO_EXCLUDES) | |
828 | return 0; | |
a6587818 | 829 | @@ -246,10 +242,7 @@ static int check_exclude_file(char *fnam |
a55d21aa WD |
830 | if (exclude_level != ALL_EXCLUDES) |
831 | return 0; | |
832 | if (exclude_list.head | |
833 | - && (rc = check_exclude(&exclude_list, fname, is_dir)) != 0) | |
834 | - return rc < 0; | |
835 | - if (local_exclude_list.head | |
836 | - && check_exclude(&local_exclude_list, fname, is_dir) < 0) | |
837 | + && check_exclude(&exclude_list, fname, is_dir) < 0) | |
838 | return 1; | |
839 | return 0; | |
840 | } | |
37da98ae | 841 | @@ -983,15 +976,7 @@ void send_file_name(int f, struct file_l |
a55d21aa WD |
842 | |
843 | if (recursive && S_ISDIR(file->mode) | |
844 | && !(file->flags & FLAG_MOUNT_POINT)) { | |
845 | - struct exclude_list_struct last_list = local_exclude_list; | |
846 | - local_exclude_list.head = local_exclude_list.tail = NULL; | |
847 | send_directory(f, flist, f_name_to(file, fbuf)); | |
7cb7ae4e WD |
848 | - if (verbose > 2) { |
849 | - rprintf(FINFO, "[%s] popping %sexclude list\n", | |
850 | - who_am_i(), local_exclude_list.debug_type); | |
851 | - } | |
d8af8661 | 852 | - clear_exclude_list(&local_exclude_list); |
a55d21aa WD |
853 | - local_exclude_list = last_list; |
854 | } | |
855 | } | |
856 | ||
37da98ae | 857 | @@ -1002,6 +987,7 @@ static void send_directory(int f, struct |
a55d21aa WD |
858 | struct dirent *di; |
859 | char fname[MAXPATHLEN]; | |
860 | unsigned int offset; | |
861 | + void *save_excludes; | |
862 | char *p; | |
863 | ||
864 | d = opendir(dir); | |
37da98ae | 865 | @@ -1025,18 +1011,7 @@ static void send_directory(int f, struct |
a55d21aa WD |
866 | offset++; |
867 | } | |
868 | ||
869 | - if (cvs_exclude) { | |
870 | - if (strlcpy(p, ".cvsignore", MAXPATHLEN - offset) | |
871 | - < MAXPATHLEN - offset) { | |
872 | - add_exclude_file(&local_exclude_list, fname, | |
ee1af13c | 873 | - XFLG_WORD_SPLIT | XFLG_WORDS_ONLY); |
a55d21aa WD |
874 | - } else { |
875 | - io_error |= IOERR_GENERAL; | |
876 | - rprintf(FINFO, | |
877 | - "cannot cvs-exclude in long-named directory %s\n", | |
878 | - full_fname(fname)); | |
879 | - } | |
045caa90 | 880 | - } |
045caa90 WD |
881 | + save_excludes = push_local_excludes(fname, offset); |
882 | ||
a55d21aa WD |
883 | for (errno = 0, di = readdir(d); di; errno = 0, di = readdir(d)) { |
884 | char *dname = d_name(di); | |
37da98ae | 885 | @@ -1057,6 +1032,8 @@ static void send_directory(int f, struct |
bc95f62b | 886 | rsyserr(FERROR, errno, "readdir(%s)", dir); |
a55d21aa | 887 | } |
a55d21aa | 888 | |
eabda998 WD |
889 | + pop_local_excludes(save_excludes); |
890 | + | |
a55d21aa WD |
891 | closedir(d); |
892 | } | |
eabda998 | 893 | |
37da98ae | 894 | @@ -1076,6 +1053,7 @@ struct file_list *send_file_list(int f, |
d34d9fad WD |
895 | char *p, *dir, olddir[sizeof curr_dir]; |
896 | char lastpath[MAXPATHLEN] = ""; | |
897 | struct file_list *flist; | |
45795ec6 | 898 | + BOOL need_first_push = True; |
d34d9fad WD |
899 | int64 start_write; |
900 | int use_ff_fd = 0; | |
901 | ||
37da98ae | 902 | @@ -1096,6 +1074,10 @@ struct file_list *send_file_list(int f, |
d34d9fad WD |
903 | exit_cleanup(RERR_FILESELECT); |
904 | } | |
905 | use_ff_fd = 1; | |
906 | + if (curr_dir_len < MAXPATHLEN - 1) { | |
40e20a69 | 907 | + push_local_excludes(curr_dir, curr_dir_len); |
45795ec6 | 908 | + need_first_push = False; |
1e476835 | 909 | + } |
d34d9fad WD |
910 | } |
911 | } | |
912 | ||
37da98ae | 913 | @@ -1126,6 +1108,15 @@ struct file_list *send_file_list(int f, |
d34d9fad WD |
914 | } |
915 | } | |
916 | ||
45795ec6 | 917 | + if (need_first_push) { |
d34d9fad | 918 | + if ((p = strrchr(fname, '/')) != NULL) { |
45795ec6 WD |
919 | + if (*++p && strcmp(p, ".") != 0) |
920 | + push_local_excludes(fname, p - fname); | |
921 | + } else if (strcmp(fname, ".") != 0) | |
922 | + push_local_excludes(fname, 0); | |
923 | + need_first_push = False; | |
d34d9fad | 924 | + } |
1e476835 | 925 | + |
d34d9fad WD |
926 | if (link_stat(fname, &st, keep_dirlinks) != 0) { |
927 | if (f != -1) { | |
928 | io_error |= IOERR_GENERAL; | |
6e313719 WD |
929 | --- orig/options.c 2005-01-15 21:23:15 |
930 | +++ options.c 2005-01-15 23:50:05 | |
931 | @@ -144,6 +144,7 @@ int list_only = 0; | |
932 | char *batch_name = NULL; | |
933 | ||
934 | static int daemon_opt; /* sets am_daemon after option error-reporting */ | |
935 | +static int E_option_cnt = 0; | |
936 | static int modify_window_set; | |
937 | static char *dest_option = NULL; | |
938 | static char *max_size_arg; | |
939 | @@ -295,6 +296,8 @@ void usage(enum logcode F) | |
940 | rprintf(F," --exclude-from=FILE exclude patterns listed in FILE\n"); | |
40e20a69 WD |
941 | rprintf(F," --include=PATTERN don't exclude files matching PATTERN\n"); |
942 | rprintf(F," --include-from=FILE don't exclude patterns listed in FILE\n"); | |
2e064775 | 943 | + rprintf(F," -E same as --exclude='-p /.rsync-excludes'\n"); |
6e313719 WD |
944 | + rprintf(F," repeated: --exclude=.rsync-excludes\n"); |
945 | rprintf(F," --files-from=FILE read FILE for list of source-file names\n"); | |
40e20a69 WD |
946 | rprintf(F," -0, --from0 all *-from file lists are delimited by nulls\n"); |
947 | rprintf(F," --version print version number\n"); | |
6e313719 | 948 | @@ -393,6 +396,7 @@ static struct poptOption long_options[] |
d34d9fad WD |
949 | {"ignore-errors", 0, POPT_ARG_NONE, &ignore_errors, 0, 0, 0 }, |
950 | {"blocking-io", 0, POPT_ARG_VAL, &blocking_io, 1, 0, 0 }, | |
951 | {"no-blocking-io", 0, POPT_ARG_VAL, &blocking_io, 0, 0, 0 }, | |
5388f859 WD |
952 | + {0, 'E', POPT_ARG_NONE, 0, 'E', 0, 0 }, |
953 | {0, 'P', POPT_ARG_NONE, 0, 'P', 0, 0 }, | |
37da98ae | 954 | {"port", 0, POPT_ARG_INT, &rsync_port, 0, 0, 0 }, |
5388f859 | 955 | {"log-format", 0, POPT_ARG_STRING, &log_format, 0, 0, 0 }, |
6e313719 | 956 | @@ -668,6 +672,19 @@ int parse_arguments(int *argc, const cha |
d34d9fad WD |
957 | am_sender = 1; |
958 | break; | |
959 | ||
960 | + case 'E': | |
6e313719 WD |
961 | + switch (++E_option_cnt) { |
962 | + case 1: | |
963 | + add_exclude(&exclude_list, | |
964 | + "-p /.rsync-excludes", 0); | |
965 | + break; | |
966 | + case 2: | |
967 | + add_exclude(&exclude_list, | |
968 | + ".rsync-excludes", 0); | |
969 | + break; | |
970 | + } | |
d34d9fad | 971 | + break; |
1e476835 | 972 | + |
d34d9fad WD |
973 | case 'P': |
974 | do_progress = 1; | |
975 | keep_partial = 1; | |
6e313719 WD |
976 | --- orig/rsync.h 2005-01-15 21:18:09 |
977 | +++ rsync.h 2005-01-16 00:37:39 | |
4c1f2ca5 | 978 | @@ -111,6 +111,7 @@ |
40e20a69 WD |
979 | #define XFLG_WORDS_ONLY (1<<2) |
980 | #define XFLG_WORD_SPLIT (1<<3) | |
a60267ab WD |
981 | #define XFLG_DIRECTORY (1<<4) |
982 | +#define XFLG_ABS_PATH (1<<5) | |
40e20a69 WD |
983 | |
984 | #define PERMS_REPORT (1<<0) | |
985 | #define PERMS_SKIP_MTIME (1<<1) | |
6e313719 | 986 | @@ -512,11 +513,19 @@ struct map_struct { |
0c7d1fd8 WD |
987 | #define MATCHFLG_INCLUDE (1<<4) /* this is an include, not an exclude */ |
988 | #define MATCHFLG_DIRECTORY (1<<5) /* this matches only directories */ | |
989 | #define MATCHFLG_CLEAR_LIST (1<<6) /* this item is the "!" token */ | |
524989ae | 990 | +#define MATCHFLG_MERGE_FILE (1<<7) /* specifies a file to merge */ |
a55d21aa | 991 | +#define MATCHFLG_CVSIGNORE (1<<8) /* parse this as a .cvsignore file */ |
40e20a69 WD |
992 | +#define MATCHFLG_PERDIR_MERGE (1<<9) /* merge-file is searched per-dir */ |
993 | +#define MATCHFLG_FINISH_SETUP (1<<10)/* per-dir merge file needs setup */ | |
6e313719 | 994 | +#define MATCHFLG_EXCLUDE_SELF (1<<11)/* merge-file name should be excluded */ |
a55d21aa WD |
995 | struct exclude_struct { |
996 | struct exclude_struct *next; | |
997 | char *pattern; | |
0c7d1fd8 | 998 | unsigned int match_flags; |
bc95f62b | 999 | - int slash_cnt; |
bc95f62b WD |
1000 | + union { |
1001 | + int slash_cnt; | |
eabda998 | 1002 | + struct exclude_list_struct *mergelist; |
bc95f62b | 1003 | + } u; |
a55d21aa WD |
1004 | }; |
1005 | ||
1006 | struct exclude_list_struct { | |
2e064775 | 1007 | --- orig/rsync.yo 2005-01-15 04:36:32 |
6e313719 WD |
1008 | +++ rsync.yo 2005-01-16 00:39:05 |
1009 | @@ -365,6 +365,8 @@ verb( | |
1010 | --exclude-from=FILE exclude patterns listed in FILE | |
1e476835 WD |
1011 | --include=PATTERN don't exclude files matching PATTERN |
1012 | --include-from=FILE don't exclude patterns listed in FILE | |
2e064775 | 1013 | + -E same as --exclude='-p /.rsync-excludes' |
6e313719 WD |
1014 | + repeated: --exclude=.rsync-excludes |
1015 | --files-from=FILE read FILE for list of source-file names | |
1e476835 WD |
1016 | -0 --from0 all file lists are delimited by nulls |
1017 | --version print version number | |
6e313719 WD |
1018 | @@ -779,6 +781,24 @@ dit(bf(--include-from=FILE)) This specif |
1019 | from a file. | |
1020 | If em(FILE) is "-" the list will be read from standard input. | |
1021 | ||
1022 | +dit(bf(-E)) The -E option is a shorthand for adding --exclude rules to | |
1023 | +your command. The first time it is used is a shorthand for this rule: | |
1024 | + | |
1025 | +verb( | |
1026 | + --exclude='-p /.rsync-excludes' | |
1027 | +) | |
1028 | + | |
1029 | +If it is repeated, it is a shorthand for this rule: | |
1030 | + | |
1031 | +verb( | |
1032 | + --exclude=.rsync-excludes | |
1033 | +) | |
1034 | + | |
1035 | +This allows you to copy files from a hierarchy that has been sprinkled | |
1036 | +with ".rsync-excludes" files and those rules will affect the transfer by | |
1037 | +using specifying -E. If you don't want the .rsync-excludes files to be | |
1038 | +sent along with the other files, specify -E a second time. | |
1039 | + | |
1040 | dit(bf(--files-from=FILE)) Using this option allows you to specify the | |
1041 | exact list of files to transfer (as read from the specified FILE or "-" | |
1042 | for standard input). It also tweaks the default behavior of rsync to make | |
1043 | @@ -1114,24 +1134,32 @@ The exclude and include patterns specifi | |
5f98a4b1 WD |
1044 | selection of which files to transfer and which files to skip. |
1045 | ||
1046 | Rsync builds an ordered list of include/exclude options as specified on | |
1047 | -the command line. Rsync checks each file and directory | |
1048 | -name against each exclude/include pattern in turn. The first matching | |
1049 | +the command line. | |
1050 | +It can also be told to check for include/exclude options in each | |
1051 | +directory that rsync visits during the transfer (see the section on | |
1052 | +MERGED EXCLUDE FILES for the details on these per-directory exclude | |
1053 | +files). | |
1054 | + | |
1055 | +As the list of files/directories to transfer is built, rsync checks each | |
1056 | +name against every exclude/include pattern in turn. The first matching | |
1057 | pattern is acted on. If it is an exclude pattern, then that file is | |
1058 | skipped. If it is an include pattern then that filename is not | |
1059 | skipped. If no matching include/exclude pattern is found then the | |
1060 | filename is not skipped. | |
1061 | ||
1062 | -The filenames matched against the exclude/include patterns are relative | |
1063 | -to the "root of the transfer". If you think of the transfer as a | |
85c7c40a WD |
1064 | -subtree of names that are being sent from sender to receiver, the root |
1065 | -is where the tree starts to be duplicated in the destination directory. | |
1066 | -This root governs where patterns that start with a / match (see below). | |
5f98a4b1 WD |
1067 | +The global include/exclude rules are anchored at the "root of the |
1068 | +transfer" (as opposed to per-directory rules, which are anchored at | |
85c7c40a WD |
1069 | +the merge-file's directory). If you think of the transfer as a |
1070 | +subtree of names that are being sent from sender to receiver, the | |
1071 | +transfer-root is where the tree starts to be duplicated in the | |
1072 | +destination directory. This root governs where patterns that start | |
1073 | +with a / match (as described in the list on pattern forms below). | |
1074 | ||
1075 | Because the matching is relative to the transfer-root, changing the | |
5f98a4b1 WD |
1076 | trailing slash on a source path or changing your use of the --relative |
1077 | option affects the path you need to use in your matching (in addition to | |
1078 | changing how much of the file tree is duplicated on the destination | |
1079 | -system). The following examples demonstrate this. | |
1080 | +host). The following examples demonstrate this. | |
1081 | ||
1082 | Let's say that we want to match two source files, one with an absolute | |
1083 | path of "/home/me/foo/bar", and one with a path of "/home/you/bar/baz". | |
6e313719 | 1084 | @@ -1178,23 +1206,27 @@ because rsync did not descend through th |
5f98a4b1 WD |
1085 | hierarchy. |
1086 | ||
1087 | Note also that the --include and --exclude options take one pattern | |
1088 | -each. To add multiple patterns use the --include-from and | |
1089 | ---exclude-from options or multiple --include and --exclude options. | |
1090 | +each. To add multiple patterns use the --include-from and --exclude-from | |
85c7c40a | 1091 | +options or multiple --include and --exclude options. |
5f98a4b1 WD |
1092 | |
1093 | -The patterns can take several forms. The rules are: | |
1094 | +The include/exclude patterns can take several forms. The rules are: | |
1095 | ||
1096 | itemize( | |
1097 | ||
1098 | - it() if the pattern starts with a / then it is matched against the | |
1099 | - start of the filename, otherwise it is matched against the end of | |
1100 | - the filename. | |
1101 | - This is the equivalent of a leading ^ in regular expressions. | |
1102 | - Thus "/foo" would match a file called "foo" at the transfer-root | |
1103 | - (see above for how this is different from the filesystem-root). | |
1104 | - On the other hand, "foo" would match any file called "foo" | |
1105 | + it() if the pattern starts with a / then it is anchored to a | |
1106 | + particular spot in the hierarchy of files, otherwise it is matched | |
1107 | + against the end of the pathname. This is similar to a leading ^ in | |
1108 | + regular expressions. | |
1109 | + Thus "/foo" would match a file called "foo" at either the "root of the | |
85c7c40a | 1110 | + transfer" (for a global rule) or in the merge-file's directory (for a |
5f98a4b1 WD |
1111 | + per-directory rule). |
1112 | + An unqualified "foo" would match any file or directory named "foo" | |
1113 | anywhere in the tree because the algorithm is applied recursively from | |
1114 | + the | |
1115 | top down; it behaves as if each path component gets a turn at being the | |
1116 | - end of the file name. | |
1117 | + end of the file name. Even the unanchored "sub/foo" would match at | |
1118 | + any point in the hierarchy where a "foo" was found within a directory | |
1119 | + named "sub". | |
1120 | ||
1121 | it() if the pattern ends with a / then it will only match a | |
1122 | directory, not a file, link, or device. | |
6e313719 | 1123 | @@ -1207,24 +1239,55 @@ itemize( |
5f98a4b1 WD |
1124 | single asterisk pattern "*" will stop at slashes. |
1125 | ||
1126 | it() if the pattern contains a / (not counting a trailing /) or a "**" | |
1127 | - then it is matched against the full filename, including any leading | |
1128 | - directory. If the pattern doesn't contain a / or a "**", then it is | |
1129 | + then it is matched against the full pathname, including any leading | |
1130 | + directories. If the pattern doesn't contain a / or a "**", then it is | |
1131 | matched only against the final component of the filename. Again, | |
1132 | remember that the algorithm is applied recursively so "full filename" can | |
1133 | actually be any portion of a path below the starting directory. | |
1134 | ||
2e064775 WD |
1135 | - it() if the pattern starts with "+ " (a plus followed by a space) |
1136 | - then it is always considered an include pattern, even if specified as | |
5f98a4b1 | 1137 | - part of an exclude option. The prefix is discarded before matching. |
2e064775 WD |
1138 | - |
1139 | - it() if the pattern starts with "- " (a minus followed by a space) | |
1140 | - then it is always considered an exclude pattern, even if specified as | |
5f98a4b1 | 1141 | - part of an include option. The prefix is discarded before matching. |
2e064775 WD |
1142 | + it() if the pattern starts with "+" (a plus), the actual pattern begins |
1143 | + after the first space, and is always considered to be an include pattern, | |
1144 | + even if specified as part of an exclude file/option. Option letters may | |
1145 | + follow the "+" prior to the separating space (see below). | |
1146 | + | |
1147 | + it() if the pattern starts with "-" (a minus), the actual pattern begins | |
1148 | + after the first space, and is always considered to be an exclude pattern, | |
1149 | + even if specified as part of an include file/option. Option letters may | |
1150 | + follow the "-" prior to the separating space (see below). | |
1151 | ||
1152 | - it() if the pattern is a single exclamation mark ! then the current | |
1153 | + it() if the pattern is a "!" (single exclamation mark) then the current | |
1e476835 | 1154 | include/exclude list is reset, removing all previously defined patterns. |
5f98a4b1 WD |
1155 | + The "current" list is either the global list of rules (which are |
1156 | + specified via options) or a set of per-directory rules (which are | |
1157 | + inherited in their own sub-list, so a subdirectory can use this to | |
1158 | + clear out the parent's rules). | |
2e064775 WD |
1159 | + |
1160 | +) | |
1161 | + | |
1162 | +For a line that starts with a "+" (plus) or a "-" (minus), the following | |
1163 | +option letters may be suffixed: | |
1164 | + | |
1165 | +itemize( | |
1166 | + | |
1167 | + it() An "m" means that the string following the space is to be taken to | |
6e313719 | 1168 | + be a merge-file that is read in to supplement the current rules. |
2e064775 WD |
1169 | + |
1170 | + it() A "p" means that the string following the space is to be taken to be | |
1171 | + a per-directory merge-file that is read in to supplement the current | |
6e313719 WD |
1172 | + rules. |
1173 | + | |
1174 | + it() A "C" (which must be followed by an empty pattern) will be | |
1175 | + interpreted as though "-p .cvsignore" had been specified. | |
1176 | + | |
1177 | + it() A "E" may be used in combination with any of the prior 3 letters in | |
1178 | + order to specify that the merge-file name should be also excluded from | |
1179 | + the transfer (e.g. "-pE .excl" is like "-p .excl" and "- .excl"). | |
2e064775 | 1180 | + |
524989ae WD |
1181 | ) |
1182 | ||
6e313719 WD |
1183 | +See the section on MERGED EXCLUDE FILES for more information on how the |
1184 | +above options work. | |
1185 | + | |
5f98a4b1 | 1186 | The +/- rules are most useful in a list that was read from a file, allowing |
6e313719 WD |
1187 | you to have a single exclude list that contains both include and exclude |
1188 | options in the proper order. | |
1189 | @@ -1269,8 +1332,166 @@ itemize( | |
5f98a4b1 WD |
1190 | it() --include "*/" --include "*.c" --exclude "*" would include all |
1191 | directories and C source files | |
1192 | it() --include "foo/" --include "foo/bar.c" --exclude "*" would include | |
1193 | - only foo/bar.c (the foo/ directory must be explicitly included or | |
1194 | - it would be excluded by the "*") | |
1195 | + only the foo directory and foo/bar.c (the foo directory must be | |
1196 | + explicitly included or it would be excluded by the "*") | |
1197 | +) | |
1198 | + | |
1199 | +manpagesection(MERGED EXCLUDE FILES) | |
524989ae | 1200 | + |
2e064775 WD |
1201 | +You can merge whole files into an exclude file by specifying either the |
1202 | +"m" or "p" option following the initial "+" or "-", and putting a filename | |
1203 | +in place of the pattern. There are two kinds of merged exclude files -- | |
1204 | +single-instance ("m") and per-directory ("p"). For example: | |
d34d9fad | 1205 | + |
2e064775 WD |
1206 | +verb( |
1207 | + -m /etc/rsync/default.excludes | |
1208 | + +p .per-dir-includes | |
1209 | +) | |
d34d9fad | 1210 | + |
2e064775 | 1211 | +For a per-directory merge file, rsync will scan |
d34d9fad | 1212 | +every directory that it traverses for the named file, merging its contents |
3d3aaf9f WD |
1213 | +when the file exists. These exclude files must exist on the sending side |
1214 | +because it is the sending side that is being scanned for available files | |
1215 | +to send. The files may also need to be transferred to the receiving side | |
1216 | +if you want them to affect what files don't get deleted (see PER-DIRECTORY | |
1217 | +EXCLUDES AND DELETE below). | |
5f98a4b1 | 1218 | + |
85c7c40a WD |
1219 | +Per-directory rules are inherited in all subdirectories of the directory |
1220 | +where the merge-file was found. Each subdirectory's rules are prefixed | |
1221 | +to the inherited rules from the parent directories, which gives the | |
1222 | +newest rules a higher priority than the inherited rules. The entire set | |
1223 | +of per-dir rules is grouped together in the spot where the merge-file was | |
1224 | +specified, so it is possible to override per-dir rules via a rule that | |
1225 | +got specified earlier in the list of global rules. | |
1226 | + | |
1227 | +If you don't want a per-dir rule to be inherited, anchor it with a leading | |
1228 | +slash. Anchored rules in a per-directory merge-file are relative to the | |
1229 | +merge-file's directory, so a rule "/foo" would only exclude the file "foo" | |
1230 | +in the directory where the per-dir exclude file was found. | |
1231 | + | |
1232 | +Here's an example exclude file which you'd specify via the normal | |
1233 | +--exclude-from=FILE option: | |
524989ae WD |
1234 | + |
1235 | +verb( | |
2e064775 | 1236 | + -m /home/user/.global_excludes |
41ebea83 | 1237 | + *.gz |
2e064775 | 1238 | + +p .incl |
524989ae | 1239 | + + *.[ch] |
41ebea83 | 1240 | + *.o |
3d3aaf9f WD |
1241 | +) |
1242 | + | |
524989ae | 1243 | +This will merge the contents of the /home/user/.global_excludes file at the |
2e064775 WD |
1244 | +start of the list and also turns the ".incl" filename into a per-directory |
1245 | +include file. All rules read in prior to the start of the directory scan | |
1246 | +follow the global anchoring rules (i.e. a leading slash matches at the root | |
1247 | +of the transfer). | |
524989ae | 1248 | + |
5f98a4b1 | 1249 | +If a per-directory merge-file is specified with a path that is a parent |
d34d9fad WD |
1250 | +directory of the first transfer directory, rsync will scan all the parent |
1251 | +dirs from that starting point to the transfer directory for the indicated | |
6e313719 | 1252 | +per-directory file. For instance, here is a common exclude (see -E): |
d34d9fad WD |
1253 | + |
1254 | +verb( | |
2e064775 | 1255 | + --exclude='-p /.rsync-excludes' |
d34d9fad WD |
1256 | +) |
1257 | + | |
1258 | +That exclude tells rsync to scan for the file .rsync-excludes in all | |
6e313719 WD |
1259 | +directories from the root down through the parent directory of the |
1260 | +transfer prior to the start of the normal directory scan of the file in | |
1261 | +the directories that are sent as a part of the transfer. (Note: for an | |
1262 | +rsync daemon, the root is always the same as the module's "path".) | |
41ebea83 WD |
1263 | + |
1264 | +Some examples of this pre-scanning for per-directory files: | |
d34d9fad WD |
1265 | + |
1266 | +verb( | |
1267 | + rsync -avE /src/path/ /dest/dir | |
2e064775 WD |
1268 | + rsync -av --exclude='-p ../../.rsync-excludes' /src/path/ /dest/dir |
1269 | + rsync -av --exclude='-p .rsync-excludes' /src/path/ /dest/dir | |
d34d9fad | 1270 | +) |
1e476835 | 1271 | + |
5f98a4b1 | 1272 | +The first two commands above will look for ".rsync-excludes" in "/" and |
41ebea83 | 1273 | +"/src" before the normal scan begins looking for the file in "/src/path" |
5f98a4b1 WD |
1274 | +and its subdirectories. The last command avoids the parent-dir scan |
1275 | +and only looks for the ".rsync-excludes" files in each directory that is | |
1276 | +a part of the transfer. | |
1277 | + | |
1278 | +Finally, note that the parsing of any merge-file named ".cvsignore" is | |
1279 | +always done in a CVS-compatible manner, even if -C wasn't specified. This | |
1280 | +means that its rules are always excludes (even if an include option | |
1281 | +specified the file), patterns are split on whitespace, the rules are never | |
2e064775 WD |
1282 | +inherited, and no special characters are honored except for "!" (e.g. no |
1283 | +comments, and no +/- prefixes). | |
5f98a4b1 WD |
1284 | + |
1285 | +Additionally, you can affect where the --cvs-exclude (-C) option's | |
1286 | +inclusion of the per-directory .cvsignore file gets placed into your rules | |
6e313719 WD |
1287 | +by putting a "-C" somewhere in your exclude rules. Without this, rsync |
1288 | +would add the per-dir rule for the .cvignore file at the end of all your | |
1289 | +other rules (giving it a lower priority than your command-line rules). | |
1290 | +For example: | |
5f98a4b1 WD |
1291 | + |
1292 | +verb( | |
6e313719 WD |
1293 | + cat <<EOT |
1294 | + + foo.o | |
1295 | + -C | |
1296 | + *.old | |
1297 | + EOT | rsync -avC --exclude-from=- a/ b | |
1298 | + | |
1299 | + rsync -avC --include=foo.o --exclude=-C --exclude='*.old' a/ b | |
5f98a4b1 WD |
1300 | +) |
1301 | + | |
6e313719 WD |
1302 | +Both of the above rsync commands are identical. Each one will merge all |
1303 | +the per-directory .cvsignore rules in the middle of the list rather than | |
1304 | +at the end. This allows their dir-specific rules to supersede the rules | |
1305 | +that follow the -C instead of being subservient to all your rules. (The | |
1306 | +global rules taken from the $HOME/.cvsignore file and from $CVSIGNORE are | |
1307 | +not repositioned from their spot at the end of your rules, however.) | |
524989ae | 1308 | + |
3d3aaf9f WD |
1309 | +manpagesection(PER-DIRECTORY EXCLUDES AND DELETE) |
1310 | + | |
1311 | +Without a delete option, per-directory excludes are only relevant on the | |
1312 | +sending side, so you can feel free to exclude the merge files themselves | |
1313 | +without affecting the transfer: | |
1314 | + | |
1315 | +verb( | |
2e064775 | 1316 | + rsync -av --exclude='-p .excl' --exclude=.excl host:src/dir /dest |
3d3aaf9f WD |
1317 | +) |
1318 | + | |
1319 | +However, if you want to do a delete on the receiving side AND you want some | |
1320 | +files to be excluded from being deleted, you'll need to be sure that the | |
1321 | +receiving side knows what files to exclude. The easiest way is to include | |
1322 | +the per-directory merge files in the transfer and use --delete-after | |
1323 | +because this ensures that the receiving side gets all the same exclude | |
1324 | +rules as the sending side before it tries to delete anything: | |
1325 | + | |
1326 | +verb( | |
1327 | + rsync -avE --delete-after host:src/dir /dest | |
1328 | +) | |
1329 | + | |
6e313719 WD |
1330 | +However, if the merge files are not a part of the transfer, you'll need to |
1331 | +either specify some global exclude rules (i.e. specified on the command | |
1332 | +line), or you'll need to maintain your own per-directory merge files on | |
1333 | +the receiving side. An example of the first is this (assume that the | |
1334 | +remote .ctrl files exclude themselves): | |
3d3aaf9f WD |
1335 | + |
1336 | +verb( | |
2e064775 | 1337 | + rsync -av --exclude='-p .ctrl' --exclude-from=/my/extra.rules |
3d3aaf9f WD |
1338 | + --delete host:src/dir /dest |
1339 | +) | |
1340 | + | |
1341 | +In the above example the extra.rules file can affect both sides of the | |
1342 | +transfer, but the rules are subservient to the rules merged from the .ctrl | |
1343 | +files because they were specified after the per-directory merge rule. | |
1344 | + | |
2e064775 | 1345 | +In one final example, the remote side is excluding the .rsync-excludes |
3d3aaf9f WD |
1346 | +files from the transfer, but we want to use our own .rsync-excludes files |
1347 | +to control what gets deleted on the receiving side. To do this we must | |
1348 | +specifically exclude the per-directory merge files (so that they don't get | |
1349 | +deleted) and then put rules into the local files to control what else | |
6e313719 | 1350 | +should not get deleted. Like one of these commands: |
3d3aaf9f WD |
1351 | + |
1352 | +verb( | |
6e313719 WD |
1353 | + rsync -av --exclude='-pE /.rsync-excludes' --delete host:src/dir /dest |
1354 | + rsync -avEE --delete host:src/dir /dest | |
3d3aaf9f | 1355 | ) |
524989ae | 1356 | |
3d3aaf9f | 1357 | manpagesection(BATCH MODE) |
13bed3dd | 1358 | --- orig/testsuite/exclude.test 2004-05-29 21:25:45 |
6e313719 | 1359 | +++ testsuite/exclude.test 2005-01-16 01:04:44 |
c4e46f36 | 1360 | @@ -23,19 +23,47 @@ export HOME CVSIGNORE |
7d31425d WD |
1361 | makepath "$fromdir/foo/down/to/you" |
1362 | makepath "$fromdir/bar/down/to/foo/too" | |
1363 | makepath "$fromdir/mid/for/foo/and/that/is/who" | |
c4e46f36 | 1364 | +cat >"$fromdir/.excl" <<EOF |
7d31425d WD |
1365 | +.excl |
1366 | +*.bak | |
1367 | +*.old | |
1368 | +*.junk | |
c4e46f36 | 1369 | +EOF |
7d31425d WD |
1370 | echo kept >"$fromdir/foo/file1" |
1371 | echo removed >"$fromdir/foo/file2" | |
1372 | echo cvsout >"$fromdir/foo/file2.old" | |
c4e46f36 | 1373 | +cat >"$fromdir/foo/.excl" <<EOF |
7d31425d WD |
1374 | ++ .excl |
1375 | +- file1 | |
c4e46f36 WD |
1376 | +EOF |
1377 | +cat >"$fromdir/bar/.excl" <<EOF | |
7d31425d | 1378 | +home-cvs-exclude |
2e064775 | 1379 | +-p .excl2 |
7d31425d | 1380 | ++ to |
c4e46f36 | 1381 | +EOF |
7d31425d | 1382 | echo cvsout >"$fromdir/bar/down/to/home-cvs-exclude" |
c4e46f36 | 1383 | +cat >"$fromdir/bar/down/to/.excl2" <<EOF |
7d31425d | 1384 | +.excl2 |
c4e46f36 | 1385 | +EOF |
7d31425d WD |
1386 | echo keeper >"$fromdir/bar/down/to/foo/file1" |
1387 | echo cvsout >"$fromdir/bar/down/to/foo/file1.bak" | |
1388 | echo gone >"$fromdir/bar/down/to/foo/file3" | |
1389 | echo lost >"$fromdir/bar/down/to/foo/file4" | |
1390 | echo cvsout >"$fromdir/bar/down/to/foo/file4.junk" | |
1391 | echo smashed >"$fromdir/bar/down/to/foo/to" | |
c4e46f36 | 1392 | +cat >"$fromdir/bar/down/to/foo/.excl2" <<EOF |
7d31425d | 1393 | ++ *.junk |
c4e46f36 | 1394 | +EOF |
7d31425d | 1395 | +# This one should be ineffectual |
c4e46f36 | 1396 | +cat >"$fromdir/mid/.excl2" <<EOF |
7d31425d | 1397 | +extra |
c4e46f36 | 1398 | +EOF |
7d31425d WD |
1399 | echo cvsout >"$fromdir/mid/one-in-one-out" |
1400 | echo one-in-one-out >"$fromdir/mid/.cvsignore" | |
1401 | echo cvsin >"$fromdir/mid/one-for-all" | |
c4e46f36 | 1402 | +cat >"$fromdir/mid/.excl" <<EOF |
6e313719 | 1403 | +-C |
c4e46f36 | 1404 | +EOF |
7d31425d WD |
1405 | echo cvsin >"$fromdir/mid/for/one-in-one-out" |
1406 | echo expunged >"$fromdir/mid/for/foo/extra" | |
1407 | echo retained >"$fromdir/mid/for/foo/keep" | |
6e313719 WD |
1408 | @@ -57,7 +85,7 @@ cat >"$excl" <<EOF |
1409 | - to | |
1410 | + file4 | |
1411 | - file[2-9] | |
1412 | -- /mid/for/foo/extra | |
1413 | +/mid/for/foo/extra | |
1414 | EOF | |
1415 | ||
1416 | cat >"$scratchdir/.cvsignore" <<EOF | |
1417 | @@ -97,7 +125,26 @@ $RSYNC -av --existing --include='*/' --e | |
1418 | # Now, test if rsync excludes the same files, this time with --cvs-exclude | |
1419 | # and --delete-excluded. | |
1420 | ||
1421 | -checkit "$RSYNC -avvC --exclude-from=\"$excl\" \ | |
1422 | +checkit "$RSYNC -avvC --include=\"-m $excl\" \ | |
1423 | + --delete-excluded \"$fromdir/\" \"$todir/\"" "$chkdir" "$todir" | |
1424 | + | |
7d31425d WD |
1425 | +# Modify the chk dir for our merge-exclude test and then tweak the dir times. |
1426 | + | |
1427 | +rm "$chkdir"/.excl | |
1428 | +rm "$chkdir"/foo/file1 | |
1429 | +rm "$chkdir"/bar/.excl | |
1430 | +rm "$chkdir"/bar/down/to/.excl2 | |
1431 | +rm "$chkdir"/bar/down/to/foo/.excl2 | |
1432 | +rm "$chkdir"/mid/.excl | |
1433 | +cp -p "$fromdir"/bar/down/to/foo/*.junk "$chkdir"/bar/down/to/foo | |
1434 | +cp -p "$fromdir"/bar/down/to/foo/to "$chkdir"/bar/down/to/foo | |
1435 | + | |
1436 | +$RSYNC -av --existing --include='*/' --exclude='*' "$fromdir/" "$chkdir/" | |
1437 | + | |
1438 | +# Now, test if rsync excludes the same files, this time with a merge-exclude | |
1439 | +# file. | |
1440 | + | |
6e313719 WD |
1441 | +checkit "$RSYNC -avv --exclude='-p .excl' --exclude=\"-m $excl\" \ |
1442 | --delete-excluded \"$fromdir/\" \"$todir/\"" "$chkdir" "$todir" | |
1443 | ||
7d31425d | 1444 | # The script would have aborted on error, so getting here means we've won. |