1 After applying this patch and running configure, you MUST run this
6 This patch adds the ability to merge rules into your excludes/includes
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
16 rsync -av --exclude='-p .excl' from/ to
18 The above will look for a file named ".excl" in every directory of the
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
29 Then the file ".excl2" will also be read in from the current dir and all
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.
37 --- orig/clientserver.c 2005-01-01 21:11:00
38 +++ clientserver.c 2004-08-10 15:44:15
39 @@ -49,12 +49,14 @@ extern int no_detach;
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;
49 +/* Length of lp_path() string when in daemon mode & not chrooted, else 0. */
50 +unsigned int module_dirlen = 0;
53 * Run a client connected to an rsyncd. The alternative to this
54 * function for remote-shell connections is do_cmd().
55 @@ -304,26 +306,28 @@ static int rsync_module(int f_in, int f_
56 /* TODO: Perhaps take a list of gids, and make them into the
57 * supplementary groups. */
59 - exclude_path_prefix = use_chroot? "" : lp_path(i);
60 - if (*exclude_path_prefix == '/' && !exclude_path_prefix[1])
61 - exclude_path_prefix = "";
64 + set_excludes_dir("/", 1);
66 + module_dirlen = strlen(lp_path(i));
67 + set_excludes_dir(lp_path(i), module_dirlen);
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);
76 add_exclude(&server_exclude_list, p,
77 - XFLG_WORD_SPLIT | XFLG_DEF_INCLUDE);
78 + XFLG_WORD_SPLIT | XFLG_DEF_INCLUDE | XFLG_ABS_PATH);
80 p = lp_exclude_from(i);
81 add_exclude_file(&server_exclude_list, p,
83 + XFLG_FATAL_ERRORS | XFLG_ABS_PATH);
86 - add_exclude(&server_exclude_list, p, XFLG_WORD_SPLIT);
88 - exclude_path_prefix = NULL;
89 + add_exclude(&server_exclude_list, p, XFLG_WORD_SPLIT | XFLG_ABS_PATH);
93 --- orig/exclude.c 2005-01-13 23:15:56
94 +++ exclude.c 2005-01-16 01:05:56
95 @@ -30,13 +30,69 @@ extern int verbose;
100 +extern int sanitize_paths;
102 extern char curr_dir[];
103 +extern unsigned int curr_dir_len;
104 +extern unsigned int module_dirlen;
106 struct exclude_list_struct exclude_list = { 0, 0, "" };
107 -struct exclude_list_struct local_exclude_list = { 0, 0, "per-dir .cvsignore " };
108 struct exclude_list_struct server_exclude_list = { 0, 0, "server " };
109 -char *exclude_path_prefix = NULL;
111 +struct mergelist_save_struct {
112 + struct exclude_list_struct *array;
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
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;
122 +static int dirbuf_depth;
124 +/* This is True when we're scanning parent dirs for per-dir merge-files. */
125 +static BOOL parent_dirscan = False;
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. */
130 +static struct exclude_struct **mergelist_parents;
131 +static int mergelist_cnt = 0;
132 +static int mergelist_size = 0;
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
138 + * to point to the inherited list, but the local list's tail pointer points
139 + * at the end of the local list. Thus, if the local list is empty, the head
140 + * will be pointing at the inherited content but the tail will be NULL. To
141 + * help you visualize this, here are the possible list arrangements:
143 + * Completely Empty Local Content Only
144 + * ================================== ====================================
145 + * head -> NULL head -> Local1 -> Local2 -> NULL
146 + * tail -> NULL tail -------------^
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 ---------^
153 + * This means that anyone wanting to traverse the whole list to use it just
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
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
162 + * values (so we can pop back to them later) and set the tail to NULL.
165 /** Build an exclude structure given an exclude pattern. */
166 static void make_exclude(struct exclude_list_struct *listp, const char *pat,
167 @@ -46,23 +102,44 @@ static void make_exclude(struct exclude_
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");
178 + if (mflags & MATCHFLG_MERGE_FILE) {
180 + /* If the local merge file was already mentioned, don't
182 + for (i = 0; i < mergelist_cnt; i++) {
183 + struct exclude_struct *ex = mergelist_parents[i];
184 + if (strlen(ex->pattern) == pat_len
185 + && memcmp(ex->pattern, pat, pat_len) == 0)
190 ret = new(struct exclude_struct);
192 out_of_memory("make_exclude");
194 memset(ret, 0, sizeof ret[0]);
196 - if (exclude_path_prefix)
197 - mflags |= MATCHFLG_ABS_PATH;
198 - if (exclude_path_prefix && *pat == '/')
199 - ex_len = strlen(exclude_path_prefix);
201 + if (mflags & MATCHFLG_ABS_PATH) {
203 + mflags &= ~MATCHFLG_ABS_PATH;
206 + ex_len = dirbuf_len - module_dirlen - 1;
209 ret->pattern = new_array(char, ex_len + pat_len + 1);
211 out_of_memory("make_exclude");
213 - memcpy(ret->pattern, exclude_path_prefix, ex_len);
214 + memcpy(ret->pattern, dirbuf + module_dirlen, ex_len);
215 strlcpy(ret->pattern + ex_len, pat, pat_len + 1);
218 @@ -81,14 +158,40 @@ static void make_exclude(struct exclude_
219 mflags |= MATCHFLG_DIRECTORY;
222 - for (cp = ret->pattern; (cp = strchr(cp, '/')) != NULL; cp++)
224 + if (mflags & MATCHFLG_MERGE_FILE) {
225 + struct exclude_list_struct *lp
226 + = new_array(struct exclude_list_struct, 1);
228 + out_of_memory("make_exclude");
229 + lp->head = lp->tail = NULL;
230 + if ((cp = strrchr(ret->pattern, '/')) != NULL)
234 + if (asprintf(&lp->debug_type, "per-dir %s ", cp) < 0)
235 + out_of_memory("make_exclude");
236 + ret->u.mergelist = lp;
237 + if (mergelist_cnt == mergelist_size) {
238 + mergelist_size += 5;
239 + mergelist_parents = realloc_array(mergelist_parents,
240 + struct exclude_struct *,
242 + if (!mergelist_parents)
243 + out_of_memory("make_exclude");
245 + mergelist_parents[mergelist_cnt++] = ret;
247 + for (cp = ret->pattern; (cp = strchr(cp, '/')) != NULL; cp++)
248 + ret->u.slash_cnt++;
251 ret->match_flags = mflags;
254 + if (!listp->tail) {
255 + ret->next = listp->head;
256 listp->head = listp->tail = ret;
259 + ret->next = listp->tail->next;
260 listp->tail->next = ret;
263 @@ -96,22 +199,267 @@ static void make_exclude(struct exclude_
265 static void free_exclude(struct exclude_struct *ex)
267 + if (ex->match_flags & MATCHFLG_MERGE_FILE) {
268 + free(ex->u.mergelist->debug_type);
269 + free(ex->u.mergelist);
275 -void clear_exclude_list(struct exclude_list_struct *listp)
276 +static void clear_exclude_list(struct exclude_list_struct *listp)
278 - struct exclude_struct *ent, *next;
280 - for (ent = listp->head; ent; ent = next) {
284 + struct exclude_struct *ent, *next;
285 + /* Truncate any inherited items from the local list. */
286 + listp->tail->next = NULL;
287 + /* Now free everything that is left. */
288 + for (ent = listp->head; ent; ent = next) {
294 listp->head = listp->tail = NULL;
297 +/* This returns an expanded (absolute) filename for the merge-file name if
298 + * the name has any slashes in it OR if the parent_dirscan var is True;
299 + * otherwise it returns the original merge_file name. If the len_ptr value
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
304 +static char *parse_merge_name(const char *merge_file, unsigned int *len_ptr,
305 + unsigned int prefix_skip)
307 + static char buf[MAXPATHLEN];
308 + char *fn, tmpbuf[MAXPATHLEN];
309 + unsigned int fn_len;
311 + if (!parent_dirscan && *merge_file != '/') {
312 + /* Return the name unchanged it doesn't have any slashes. */
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);
320 + } else if (strchr(merge_file, '/') == NULL)
321 + return (char *)merge_file;
324 + fn = *merge_file == '/' ? buf : tmpbuf;
325 + if (sanitize_paths) {
326 + const char *r = prefix_skip ? "/" : NULL;
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);
333 + if (!sanitize_path(fn, merge_file, r, dirbuf_depth)) {
334 + rprintf(FERROR, "merge-file name overflows: %s\n",
339 + strlcpy(fn, merge_file, len_ptr ? *len_ptr + 1 : MAXPATHLEN);
340 + clean_fname(fn, 1);
343 + fn_len = strlen(fn);
347 + if (dirbuf_len + fn_len >= MAXPATHLEN) {
348 + rprintf(FERROR, "merge-file name overflows: %s\n", fn);
351 + memcpy(buf, dirbuf + prefix_skip, dirbuf_len - prefix_skip);
352 + memcpy(buf + dirbuf_len - prefix_skip, fn, fn_len + 1);
353 + fn_len = clean_fname(buf, 1);
361 +/* Sets the dirbuf and dirbuf_len values. */
362 +void set_excludes_dir(const char *dir, unsigned int dirlen)
366 + memcpy(dirbuf, curr_dir, curr_dir_len);
367 + dirbuf[curr_dir_len] = '/';
368 + len = curr_dir_len + 1;
369 + if (len + dirlen >= MAXPATHLEN)
373 + memcpy(dirbuf + len, dir, dirlen);
374 + dirbuf[dirlen + len] = '\0';
375 + dirbuf_len = clean_fname(dirbuf, 1);
376 + if (dirbuf_len > 1 && dirbuf[dirbuf_len-1] == '.'
377 + && dirbuf[dirbuf_len-2] == '/')
379 + dirbuf[dirbuf_len++] = '/';
380 + dirbuf[dirbuf_len] = '\0';
381 + if (sanitize_paths)
382 + dirbuf_depth = count_dir_elements(dirbuf + module_dirlen);
385 +/* This routine takes a per-dir merge-file entry and finishes its setup.
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
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)
393 + char buf[MAXPATHLEN];
394 + char *x, *y, *pat = ex->pattern;
397 + if (!(x = parse_merge_name(pat, NULL, 0)) || *x != '/')
400 + y = strrchr(x, '/');
402 + ex->pattern = strdup(y+1);
406 + strlcpy(buf, x, MAXPATHLEN);
408 + pathjoin(buf, MAXPATHLEN, dirbuf, x);
410 + len = clean_fname(buf, 1);
411 + if (len != 1 && len < MAXPATHLEN-1) {
415 + /* This ensures that the specified dir is a parent of the transfer. */
416 + for (x = buf, y = dirbuf; *x && *x == *y; x++, y++) {}
418 + y += strlen(y); /* nope -- skip the scan */
420 + parent_dirscan = True;
422 + char save[MAXPATHLEN];
423 + strlcpy(save, y, MAXPATHLEN);
425 + dirbuf_len = y - dirbuf;
426 + strlcpy(x, ex->pattern, MAXPATHLEN - (x - buf));
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. */
431 + strlcpy(y, save, MAXPATHLEN);
432 + while ((*x++ = *y++) != '/') {}
434 + parent_dirscan = False;
439 +/* Each time rsync changes to a new directory it call this function to
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. */
443 +void *push_local_excludes(const char *dir, unsigned int dirlen)
445 + struct mergelist_save_struct *push;
446 + struct exclude_list_struct *ap;
449 + set_excludes_dir(dir, dirlen);
451 + if (!(push = new_array(struct mergelist_save_struct, 1)))
452 + out_of_memory("push_local_excludes");
454 + push->count = mergelist_cnt;
455 + push->array = new_array(struct exclude_list_struct, mergelist_cnt);
457 + out_of_memory("push_local_excludes");
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));
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;
472 + rprintf(FINFO, "[%s] pushing %sexclude list\n",
473 + who_am_i(), lp->debug_type);
476 + if (ex->match_flags & MATCHFLG_CVSIGNORE) {
477 + lp->head = NULL; /* CVS doesn't inherit rules. */
478 + flags = XFLG_WORD_SPLIT | XFLG_WORDS_ONLY;
480 + flags = ex->match_flags & MATCHFLG_INCLUDE
481 + ? XFLG_DEF_INCLUDE : 0;
483 + lp->tail = NULL; /* Switch any local rules to inherited. */
485 + if (ex->match_flags & MATCHFLG_FINISH_SETUP) {
486 + ex->match_flags &= ~MATCHFLG_FINISH_SETUP;
487 + if (setup_merge_file(ex, lp, flags))
488 + set_excludes_dir(dir, dirlen);
491 + if (strlcpy(dirbuf + dirbuf_len, ex->pattern,
492 + MAXPATHLEN - dirbuf_len) < MAXPATHLEN - dirbuf_len)
493 + add_exclude_file(lp, dirbuf, flags | XFLG_ABS_PATH);
495 + io_error |= IOERR_GENERAL;
497 + "cannot add local excludes in long-named directory %s\n",
498 + full_fname(dirbuf));
500 + dirbuf[dirbuf_len] = '\0';
503 + return (void*)push;
506 +void pop_local_excludes(void *mem)
508 + struct mergelist_save_struct *pop = (struct mergelist_save_struct*)mem;
509 + struct exclude_list_struct *ap;
512 + for (i = mergelist_cnt; i-- > 0; ) {
513 + struct exclude_struct *ex = mergelist_parents[i];
514 + struct exclude_list_struct *lp = ex->u.mergelist;
517 + rprintf(FINFO, "[%s] popping %sexclude list\n",
518 + who_am_i(), lp->debug_type);
521 + clear_exclude_list(lp);
524 + mergelist_cnt = pop->count;
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));
534 static int check_one_exclude(char *name, struct exclude_struct *ex,
537 @@ -125,13 +473,14 @@ static int check_one_exclude(char *name,
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)
546 else if (ex->match_flags & MATCHFLG_ABS_PATH && *name != '/'
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);
555 @@ -148,9 +497,9 @@ static int check_one_exclude(char *name,
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. */
559 - if (!match_start && ex->slash_cnt
560 + if (!match_start && ex->u.slash_cnt
561 && !(ex->match_flags & MATCHFLG_WILD2)) {
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)
567 @@ -221,6 +570,13 @@ int check_exclude(struct exclude_list_st
568 struct exclude_struct *ent;
570 for (ent = listp->head; ent; ent = ent->next) {
571 + if (ent->match_flags & MATCHFLG_MERGE_FILE) {
572 + int rc = check_exclude(ent->u.mergelist, name,
578 if (check_one_exclude(name, ent, name_is_dir)) {
579 report_exclude_result(name, ent, name_is_dir,
581 @@ -254,12 +610,45 @@ static const char *get_exclude_tok(const
585 - /* Is this a '+' or '-' followed by a space (not whitespace)? */
586 - if (!(xflags & XFLG_WORDS_ONLY)
587 - && (*s == '-' || *s == '+') && s[1] == ' ') {
588 + /* Check for a leading '+' or '-'. */
589 + if (!(xflags & XFLG_WORDS_ONLY) && (*s == '-' || *s == '+')) {
592 + "no pattern followed %c in %sclude file.\n",
593 + *s, xflags & XFLG_DEF_INCLUDE ? "in" : "ex");
594 + exit_cleanup(RERR_SYNTAX);
597 mflags |= MATCHFLG_INCLUDE;
599 + while (*++s && *s != ' ') {
602 + mflags |= MATCHFLG_MERGE_FILE
603 + | MATCHFLG_PERDIR_MERGE
604 + | MATCHFLG_FINISH_SETUP
605 + | MATCHFLG_CVSIGNORE;
606 + mflags &= ~MATCHFLG_INCLUDE;
609 + mflags |= MATCHFLG_EXCLUDE_SELF;
612 + mflags |= MATCHFLG_MERGE_FILE
613 + | MATCHFLG_PERDIR_MERGE
614 + | MATCHFLG_FINISH_SETUP;
617 + mflags |= MATCHFLG_MERGE_FILE;
621 + "invalid include/exclude option after %c: %c\n",
623 + exit_cleanup(RERR_SYNTAX);
628 } else if (xflags & XFLG_DEF_INCLUDE)
629 mflags |= MATCHFLG_INCLUDE;
630 if (xflags & XFLG_DIRECTORY)
631 @@ -274,8 +663,27 @@ static const char *get_exclude_tok(const
635 + if (mflags & MATCHFLG_PERDIR_MERGE) {
636 + if (mflags & MATCHFLG_CVSIGNORE) {
639 + "unexpected trailing char%s after -C: `%s'\n",
640 + len == 1 ? "" : "s", s);
641 + exit_cleanup(RERR_SYNTAX);
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;
652 if (*p == '!' && len == 1)
653 mflags |= MATCHFLG_CLEAR_LIST;
654 + if (xflags & XFLG_ABS_PATH)
655 + mflags |= MATCHFLG_ABS_PATH;
659 @@ -287,7 +695,7 @@ void add_exclude(struct exclude_list_str
662 unsigned int pat_len, mflags;
664 + const char *cp, *p;
668 @@ -295,9 +703,15 @@ void add_exclude(struct exclude_list_str
672 + /* Remember that the returned string is NOT '\0' terminated! */
673 cp = get_exclude_tok(cp + pat_len, &pat_len, &mflags, xflags);
676 + if (pat_len >= MAXPATHLEN) {
677 + rprintf(FERROR, "discarding over-long exclude: %s\n",
682 if (mflags & MATCHFLG_CLEAR_LIST) {
684 @@ -309,13 +723,37 @@ void add_exclude(struct exclude_list_str
688 - make_exclude(listp, cp, pat_len, mflags);
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");
694 + if (mflags & MATCHFLG_MERGE_FILE) {
695 + unsigned int len = pat_len;
696 + if (mflags & MATCHFLG_EXCLUDE_SELF) {
697 + const char *name = strrchr(cp, '/');
699 + len -= ++name - cp;
702 + make_exclude(listp, name, len, 0);
703 + mflags &= ~MATCHFLG_EXCLUDE_SELF;
706 + if (mflags & MATCHFLG_PERDIR_MERGE) {
707 + if (parent_dirscan) {
708 + if (!(p = parse_merge_name(cp, &len, module_dirlen)))
710 + make_exclude(listp, p, len, mflags);
714 + int flgs = XFLG_FATAL_ERRORS;
715 + if (!(p = parse_merge_name(cp, &len, 0)))
717 + if (mflags & MATCHFLG_INCLUDE)
718 + flgs |= XFLG_DEF_INCLUDE;
719 + add_exclude_file(listp, p, flgs);
724 + make_exclude(listp, cp, pat_len, mflags);
728 @@ -324,7 +762,7 @@ void add_exclude_file(struct exclude_lis
732 - char line[MAXPATHLEN+3]; /* Room for "x " prefix and trailing slash. */
733 + char line[MAXPATHLEN+4]; /* Room for prefix chars and trailing slash. */
734 char *eob = line + sizeof line - 1;
735 int word_split = xflags & XFLG_WORD_SPLIT;
737 @@ -338,13 +776,19 @@ void add_exclude_file(struct exclude_lis
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",
746 exit_cleanup(RERR_FILEIO);
750 + dirbuf[dirbuf_len] = '\0';
753 + rprintf(FINFO, "[%s] add_exclude_file(%s,%d)\n",
754 + who_am_i(), fname, xflags);
759 @@ -402,7 +846,20 @@ void send_exclude_list(int f)
763 - if (ent->match_flags & MATCHFLG_INCLUDE) {
764 + if (ent->match_flags & MATCHFLG_MERGE_FILE) {
765 + char buf[32], *op = buf;
766 + if (ent->match_flags & MATCHFLG_INCLUDE)
770 + if (ent->match_flags & MATCHFLG_PERDIR_MERGE)
775 + write_int(f, l + (op - buf));
776 + write_buf(f, buf, op - buf);
777 + } else if (ent->match_flags & MATCHFLG_INCLUDE) {
779 write_buf(f, "+ ", 2);
780 } else if (*p == '-' || *p == '+') {
781 @@ -419,7 +876,7 @@ void send_exclude_list(int f)
783 void recv_exclude_list(int f)
785 - char line[MAXPATHLEN+3]; /* Room for "x " prefix and trailing slash. */
786 + char line[MAXPATHLEN+4]; /* Room for prefix and trailing slash. */
789 while ((l = read_int(f)) != 0) {
790 @@ -446,6 +903,7 @@ void add_cvs_excludes(void)
791 char fname[MAXPATHLEN];
794 + add_exclude(&exclude_list, "-C", 0);
795 add_exclude(&exclude_list, default_cvsignore,
796 XFLG_WORD_SPLIT | XFLG_WORDS_ONLY);
798 --- orig/flist.c 2005-01-01 21:11:00
799 +++ flist.c 2004-08-12 18:59:28
800 @@ -40,10 +40,9 @@ extern int module_id;
801 extern int ignore_errors;
802 extern int numeric_ids;
804 -extern int cvs_exclude;
807 extern char curr_dir[MAXPATHLEN];
808 +extern unsigned int curr_dir_len;
809 extern char *files_from;
810 extern int filesfrom_fd;
812 @@ -67,7 +66,6 @@ extern int list_only;
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;
820 @@ -223,8 +221,6 @@ int link_stat(const char *path, STRUCT_S
822 static int check_exclude_file(char *fname, int is_dir, int exclude_level)
826 #if 0 /* This currently never happens, so avoid a useless compare. */
827 if (exclude_level == NO_EXCLUDES)
829 @@ -246,10 +242,7 @@ static int check_exclude_file(char *fnam
830 if (exclude_level != ALL_EXCLUDES)
832 if (exclude_list.head
833 - && (rc = check_exclude(&exclude_list, fname, is_dir)) != 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)
841 @@ -983,15 +976,7 @@ void send_file_name(int f, struct file_l
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));
849 - rprintf(FINFO, "[%s] popping %sexclude list\n",
850 - who_am_i(), local_exclude_list.debug_type);
852 - clear_exclude_list(&local_exclude_list);
853 - local_exclude_list = last_list;
857 @@ -1002,6 +987,7 @@ static void send_directory(int f, struct
859 char fname[MAXPATHLEN];
861 + void *save_excludes;
865 @@ -1025,18 +1011,7 @@ static void send_directory(int f, struct
870 - if (strlcpy(p, ".cvsignore", MAXPATHLEN - offset)
871 - < MAXPATHLEN - offset) {
872 - add_exclude_file(&local_exclude_list, fname,
873 - XFLG_WORD_SPLIT | XFLG_WORDS_ONLY);
875 - io_error |= IOERR_GENERAL;
877 - "cannot cvs-exclude in long-named directory %s\n",
878 - full_fname(fname));
881 + save_excludes = push_local_excludes(fname, offset);
883 for (errno = 0, di = readdir(d); di; errno = 0, di = readdir(d)) {
884 char *dname = d_name(di);
885 @@ -1057,6 +1032,8 @@ static void send_directory(int f, struct
886 rsyserr(FERROR, errno, "readdir(%s)", dir);
889 + pop_local_excludes(save_excludes);
894 @@ -1076,6 +1053,7 @@ struct file_list *send_file_list(int f,
895 char *p, *dir, olddir[sizeof curr_dir];
896 char lastpath[MAXPATHLEN] = "";
897 struct file_list *flist;
898 + BOOL need_first_push = True;
902 @@ -1096,6 +1074,10 @@ struct file_list *send_file_list(int f,
903 exit_cleanup(RERR_FILESELECT);
906 + if (curr_dir_len < MAXPATHLEN - 1) {
907 + push_local_excludes(curr_dir, curr_dir_len);
908 + need_first_push = False;
913 @@ -1126,6 +1108,15 @@ struct file_list *send_file_list(int f,
917 + if (need_first_push) {
918 + if ((p = strrchr(fname, '/')) != NULL) {
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;
926 if (link_stat(fname, &st, keep_dirlinks) != 0) {
928 io_error |= IOERR_GENERAL;
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;
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");
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");
943 + rprintf(F," -E same as --exclude='-p /.rsync-excludes'\n");
944 + rprintf(F," repeated: --exclude=.rsync-excludes\n");
945 rprintf(F," --files-from=FILE read FILE for list of source-file names\n");
946 rprintf(F," -0, --from0 all *-from file lists are delimited by nulls\n");
947 rprintf(F," --version print version number\n");
948 @@ -393,6 +396,7 @@ static struct poptOption long_options[]
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 },
952 + {0, 'E', POPT_ARG_NONE, 0, 'E', 0, 0 },
953 {0, 'P', POPT_ARG_NONE, 0, 'P', 0, 0 },
954 {"port", 0, POPT_ARG_INT, &rsync_port, 0, 0, 0 },
955 {"log-format", 0, POPT_ARG_STRING, &log_format, 0, 0, 0 },
956 @@ -668,6 +672,19 @@ int parse_arguments(int *argc, const cha
961 + switch (++E_option_cnt) {
963 + add_exclude(&exclude_list,
964 + "-p /.rsync-excludes", 0);
967 + add_exclude(&exclude_list,
968 + ".rsync-excludes", 0);
976 --- orig/rsync.h 2005-01-15 21:18:09
977 +++ rsync.h 2005-01-16 00:37:39
979 #define XFLG_WORDS_ONLY (1<<2)
980 #define XFLG_WORD_SPLIT (1<<3)
981 #define XFLG_DIRECTORY (1<<4)
982 +#define XFLG_ABS_PATH (1<<5)
984 #define PERMS_REPORT (1<<0)
985 #define PERMS_SKIP_MTIME (1<<1)
986 @@ -512,11 +513,19 @@ struct map_struct {
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 */
990 +#define MATCHFLG_MERGE_FILE (1<<7) /* specifies a file to merge */
991 +#define MATCHFLG_CVSIGNORE (1<<8) /* parse this as a .cvsignore file */
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 */
994 +#define MATCHFLG_EXCLUDE_SELF (1<<11)/* merge-file name should be excluded */
995 struct exclude_struct {
996 struct exclude_struct *next;
998 unsigned int match_flags;
1002 + struct exclude_list_struct *mergelist;
1006 struct exclude_list_struct {
1007 --- orig/rsync.yo 2005-01-15 04:36:32
1008 +++ rsync.yo 2005-01-16 00:39:05
1009 @@ -365,6 +365,8 @@ verb(
1010 --exclude-from=FILE exclude patterns listed in FILE
1011 --include=PATTERN don't exclude files matching PATTERN
1012 --include-from=FILE don't exclude patterns listed in FILE
1013 + -E same as --exclude='-p /.rsync-excludes'
1014 + repeated: --exclude=.rsync-excludes
1015 --files-from=FILE read FILE for list of source-file names
1016 -0 --from0 all file lists are delimited by nulls
1017 --version print version number
1018 @@ -779,6 +781,24 @@ dit(bf(--include-from=FILE)) This specif
1020 If em(FILE) is "-" the list will be read from standard input.
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:
1026 + --exclude='-p /.rsync-excludes'
1029 +If it is repeated, it is a shorthand for this rule:
1032 + --exclude=.rsync-excludes
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.
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
1044 selection of which files to transfer and which files to skip.
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
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
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.
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
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).
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
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).
1075 Because the matching is relative to the transfer-root, changing the
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.
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".
1084 @@ -1178,23 +1206,27 @@ because rsync did not descend through th
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
1091 +options or multiple --include and --exclude options.
1093 -The patterns can take several forms. The rules are:
1094 +The include/exclude patterns can take several forms. The rules are:
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
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
1110 + transfer" (for a global rule) or in the merge-file's directory (for a
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
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
1121 it() if the pattern ends with a / then it will only match a
1122 directory, not a file, link, or device.
1123 @@ -1207,24 +1239,55 @@ itemize(
1124 single asterisk pattern "*" will stop at slashes.
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.
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
1137 - part of an exclude option. The prefix is discarded before matching.
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
1141 - part of an include option. The prefix is discarded before matching.
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).
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).
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
1154 include/exclude list is reset, removing all previously defined patterns.
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).
1162 +For a line that starts with a "+" (plus) or a "-" (minus), the following
1163 +option letters may be suffixed:
1167 + it() An "m" means that the string following the space is to be taken to
1168 + be a merge-file that is read in to supplement the current rules.
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
1174 + it() A "C" (which must be followed by an empty pattern) will be
1175 + interpreted as though "-p .cvsignore" had been specified.
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").
1183 +See the section on MERGED EXCLUDE FILES for more information on how the
1184 +above options work.
1186 The +/- rules are most useful in a list that was read from a file, allowing
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(
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 "*")
1199 +manpagesection(MERGED EXCLUDE FILES)
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:
1207 + -m /etc/rsync/default.excludes
1208 + +p .per-dir-includes
1211 +For a per-directory merge file, rsync will scan
1212 +every directory that it traverses for the named file, merging its contents
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).
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.
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.
1232 +Here's an example exclude file which you'd specify via the normal
1233 +--exclude-from=FILE option:
1236 + -m /home/user/.global_excludes
1243 +This will merge the contents of the /home/user/.global_excludes file at the
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
1249 +If a per-directory merge-file is specified with a path that is a parent
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
1252 +per-directory file. For instance, here is a common exclude (see -E):
1255 + --exclude='-p /.rsync-excludes'
1258 +That exclude tells rsync to scan for the file .rsync-excludes in all
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".)
1264 +Some examples of this pre-scanning for per-directory files:
1267 + rsync -avE /src/path/ /dest/dir
1268 + rsync -av --exclude='-p ../../.rsync-excludes' /src/path/ /dest/dir
1269 + rsync -av --exclude='-p .rsync-excludes' /src/path/ /dest/dir
1272 +The first two commands above will look for ".rsync-excludes" in "/" and
1273 +"/src" before the normal scan begins looking for the file in "/src/path"
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.
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
1282 +inherited, and no special characters are honored except for "!" (e.g. no
1283 +comments, and no +/- prefixes).
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
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).
1297 + EOT | rsync -avC --exclude-from=- a/ b
1299 + rsync -avC --include=foo.o --exclude=-C --exclude='*.old' a/ b
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.)
1309 +manpagesection(PER-DIRECTORY EXCLUDES AND DELETE)
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:
1316 + rsync -av --exclude='-p .excl' --exclude=.excl host:src/dir /dest
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:
1327 + rsync -avE --delete-after host:src/dir /dest
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):
1337 + rsync -av --exclude='-p .ctrl' --exclude-from=/my/extra.rules
1338 + --delete host:src/dir /dest
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.
1345 +In one final example, the remote side is excluding the .rsync-excludes
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
1350 +should not get deleted. Like one of these commands:
1353 + rsync -av --exclude='-pE /.rsync-excludes' --delete host:src/dir /dest
1354 + rsync -avEE --delete host:src/dir /dest
1357 manpagesection(BATCH MODE)
1358 --- orig/testsuite/exclude.test 2004-05-29 21:25:45
1359 +++ testsuite/exclude.test 2005-01-16 01:04:44
1360 @@ -23,19 +23,47 @@ export HOME CVSIGNORE
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"
1364 +cat >"$fromdir/.excl" <<EOF
1370 echo kept >"$fromdir/foo/file1"
1371 echo removed >"$fromdir/foo/file2"
1372 echo cvsout >"$fromdir/foo/file2.old"
1373 +cat >"$fromdir/foo/.excl" <<EOF
1377 +cat >"$fromdir/bar/.excl" <<EOF
1382 echo cvsout >"$fromdir/bar/down/to/home-cvs-exclude"
1383 +cat >"$fromdir/bar/down/to/.excl2" <<EOF
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"
1392 +cat >"$fromdir/bar/down/to/foo/.excl2" <<EOF
1395 +# This one should be ineffectual
1396 +cat >"$fromdir/mid/.excl2" <<EOF
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"
1402 +cat >"$fromdir/mid/.excl" <<EOF
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"
1408 @@ -57,7 +85,7 @@ cat >"$excl" <<EOF
1412 -- /mid/for/foo/extra
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.
1421 -checkit "$RSYNC -avvC --exclude-from=\"$excl\" \
1422 +checkit "$RSYNC -avvC --include=\"-m $excl\" \
1423 + --delete-excluded \"$fromdir/\" \"$todir/\"" "$chkdir" "$todir"
1425 +# Modify the chk dir for our merge-exclude test and then tweak the dir times.
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
1436 +$RSYNC -av --existing --include='*/' --exclude='*' "$fromdir/" "$chkdir/"
1438 +# Now, test if rsync excludes the same files, this time with a merge-exclude
1441 +checkit "$RSYNC -avv --exclude='-p .excl' --exclude=\"-m $excl\" \
1442 --delete-excluded \"$fromdir/\" \"$todir/\"" "$chkdir" "$todir"
1444 # The script would have aborted on error, so getting here means we've won.