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