From: Matt McCutchen Date: Tue, 5 May 2009 02:33:55 +0000 (-0400) Subject: Refactorings to the filter code, most notably: X-Git-Url: https://mattmccutchen.net/rsync/rsync.git/commitdiff_plain/ebaa4296bf813e36fcc7fd63ec813b2de59600a9 Refactorings to the filter code, most notably: - Improve function names: parse_filter_file -> load_filter_file and parse_rule -> load_filter_str (to make the similarity clearer, since it /can/ load multiple rules when MATCHFLG_WORD_SPLIT is specified). - In preparation for rule prefixes containing information beyond the mflags, change the code to pass around a full "template" filter_struct instead of just mflags. Callers of load_filter_{str,file} that want to specify only mflags can use filter_template(mflags) . - Remove the MODIFIERS_* strings and instead hand-code the condition under which each modifier is valid. This should make it easier to see that the conditions are correct. - Tighten up default modifiers on merge rules: - Disallow "!" because it isn't useful. - If the merge rule specifies a side via "s" or "r", the rules in the file cannot also specify a side via "s", "r", "hide", etc. --- diff --git a/batch.c b/batch.c index 37529f0d..971a2894 100644 --- a/batch.c +++ b/batch.c @@ -196,10 +196,10 @@ static void write_filter_rules(int fd) write_sbuf(fd, " <<'#E#'\n"); for (ent = filter_list.head; ent; ent = ent->next) { unsigned int plen; - char *p = get_rule_prefix(ent->match_flags, "- ", 0, &plen); + char *p = get_rule_prefix(ent, "- ", 0, &plen); write_buf(fd, p, plen); write_sbuf(fd, ent->pattern); - if (ent->match_flags & MATCHFLG_DIRECTORY) + if (ent->flags & MATCHFLG_DIRECTORY) write_byte(fd, '/'); write_byte(fd, eol_nulls ? 0 : '\n'); } diff --git a/clientserver.c b/clientserver.c index 8d062867..ca48ecb2 100644 --- a/clientserver.c +++ b/clientserver.c @@ -620,24 +620,24 @@ static int rsync_module(int f_in, int f_out, int i, const char *addr, const char set_filter_dir(module_dir, module_dirlen); p = lp_filter(i); - parse_rule(&daemon_filter_list, p, MATCHFLG_WORD_SPLIT, + load_filter_str(&daemon_filter_list, p, filter_template(MATCHFLG_WORD_SPLIT), XFLG_ABS_IF_SLASH | XFLG_DIR2WILD3); p = lp_include_from(i); - parse_filter_file(&daemon_filter_list, p, MATCHFLG_INCLUDE, + load_filter_file(&daemon_filter_list, p, filter_template(MATCHFLG_INCLUDE), XFLG_ABS_IF_SLASH | XFLG_DIR2WILD3 | XFLG_OLD_PREFIXES | XFLG_FATAL_ERRORS); p = lp_include(i); - parse_rule(&daemon_filter_list, p, - MATCHFLG_INCLUDE | MATCHFLG_WORD_SPLIT, + load_filter_str(&daemon_filter_list, p, + filter_template(MATCHFLG_INCLUDE | MATCHFLG_WORD_SPLIT), XFLG_ABS_IF_SLASH | XFLG_DIR2WILD3 | XFLG_OLD_PREFIXES); p = lp_exclude_from(i); - parse_filter_file(&daemon_filter_list, p, 0, + load_filter_file(&daemon_filter_list, p, filter_template(0), XFLG_ABS_IF_SLASH | XFLG_DIR2WILD3 | XFLG_OLD_PREFIXES | XFLG_FATAL_ERRORS); p = lp_exclude(i); - parse_rule(&daemon_filter_list, p, MATCHFLG_WORD_SPLIT, + load_filter_str(&daemon_filter_list, p, filter_template(MATCHFLG_WORD_SPLIT), XFLG_ABS_IF_SLASH | XFLG_DIR2WILD3 | XFLG_OLD_PREFIXES); log_init(1); diff --git a/compat.c b/compat.c index 5ba9a4ce..94eef434 100644 --- a/compat.c +++ b/compat.c @@ -294,7 +294,7 @@ void setup_protocol(int f_out,int f_in) int flags = MATCHFLG_NO_PREFIXES | MATCHFLG_DIRECTORY; if (!am_sender || protocol_version >= 30) flags |= MATCHFLG_PERISHABLE; - parse_rule(&filter_list, partial_dir, flags, 0); + load_filter_str(&filter_list, partial_dir, filter_template(flags), 0); } diff --git a/exclude.c b/exclude.c index 5fa6e00d..9a7e0daa 100644 --- a/exclude.c +++ b/exclude.c @@ -124,8 +124,6 @@ static void teardown_mergelist(struct filter_struct *ex) static void free_filter(struct filter_struct *ex) { - if (ex->match_flags & MATCHFLG_PERDIR_MERGE) - teardown_mergelist(ex); free(ex->pattern); free(ex); } @@ -145,47 +143,47 @@ static void free_filters(struct filter_struct *head) while (rev_head) { struct filter_struct *prev = rev_head->next; + /* Tear down mergelists here, not in free_filter, so that we + * affect only real filter lists and not temporarily allocated + * filters. */ + if (rev_head->flags & MATCHFLG_PERDIR_MERGE) + teardown_mergelist(rev_head); free_filter(rev_head); rev_head = prev; } } /* Build a filter structure given a filter pattern. The value in "pat" - * is not null-terminated. */ -static void add_rule(struct filter_list_struct *listp, const char *pat, - unsigned int pat_len, uint32 mflags, int xflags) + * is not null-terminated. "filter" is either held or freed, so the + * caller should not free it. */ +static void add_rule(struct filter_list_struct *listp, + const char *pat, unsigned int pat_len, + struct filter_struct *filter, int xflags) { - struct filter_struct *ret; const char *cp; unsigned int pre_len, suf_len, slash_cnt = 0; if (DEBUG_GTE(FILTER, 2)) { rprintf(FINFO, "[%s] add_rule(%s%.*s%s)%s\n", - who_am_i(), get_rule_prefix(mflags, pat, 0, NULL), + who_am_i(), get_rule_prefix(filter, pat, 0, NULL), (int)pat_len, pat, - (mflags & MATCHFLG_DIRECTORY) ? "/" : "", + (filter->flags & MATCHFLG_DIRECTORY) ? "/" : "", listp->debug_type); } /* These flags also indicate that we're reading a list that * needs to be filtered now, not post-filtered later. */ - if (xflags & (XFLG_ANCHORED2ABS|XFLG_ABS_IF_SLASH)) { - uint32 mf = mflags & (MATCHFLG_RECEIVER_SIDE|MATCHFLG_SENDER_SIDE); - if (am_sender) { - if (mf == MATCHFLG_RECEIVER_SIDE) - return; - } else { - if (mf == MATCHFLG_SENDER_SIDE) - return; - } + if (xflags & (XFLG_ANCHORED2ABS|XFLG_ABS_IF_SLASH) + && (filter->flags & MATCHFLGS_SIDES) + == (am_sender ? MATCHFLG_RECEIVER_SIDE : MATCHFLG_SENDER_SIDE)) { + /* This filter applies only to the other side. Drop it. */ + free_filter(filter); + return; } - if (!(ret = new0(struct filter_struct))) - out_of_memory("add_rule"); - if (pat_len > 1 && pat[pat_len-1] == '/') { pat_len--; - mflags |= MATCHFLG_DIRECTORY; + filter->flags |= MATCHFLG_DIRECTORY; } for (cp = pat; cp < pat + pat_len; cp++) { @@ -193,10 +191,10 @@ static void add_rule(struct filter_list_struct *listp, const char *pat, slash_cnt++; } - if (!(mflags & (MATCHFLG_ABS_PATH | MATCHFLG_MERGE_FILE)) + if (!(filter->flags & (MATCHFLG_ABS_PATH | MATCHFLG_MERGE_FILE)) && ((xflags & (XFLG_ANCHORED2ABS|XFLG_ABS_IF_SLASH) && *pat == '/') || (xflags & XFLG_ABS_IF_SLASH && slash_cnt))) { - mflags |= MATCHFLG_ABS_PATH; + filter->flags |= MATCHFLG_ABS_PATH; if (*pat == '/') pre_len = dirbuf_len - module_dirlen - 1; else @@ -206,54 +204,54 @@ static void add_rule(struct filter_list_struct *listp, const char *pat, /* The daemon wants dir-exclude rules to get an appended "/" + "***". */ if (xflags & XFLG_DIR2WILD3 - && BITS_SETnUNSET(mflags, MATCHFLG_DIRECTORY, MATCHFLG_INCLUDE)) { - mflags &= ~MATCHFLG_DIRECTORY; + && BITS_SETnUNSET(filter->flags, MATCHFLG_DIRECTORY, MATCHFLG_INCLUDE)) { + filter->flags &= ~MATCHFLG_DIRECTORY; suf_len = sizeof SLASH_WILD3_SUFFIX - 1; } else suf_len = 0; - if (!(ret->pattern = new_array(char, pre_len + pat_len + suf_len + 1))) + if (!(filter->pattern = new_array(char, pre_len + pat_len + suf_len + 1))) out_of_memory("add_rule"); if (pre_len) { - memcpy(ret->pattern, dirbuf + module_dirlen, pre_len); - for (cp = ret->pattern; cp < ret->pattern + pre_len; cp++) { + memcpy(filter->pattern, dirbuf + module_dirlen, pre_len); + for (cp = filter->pattern; cp < filter->pattern + pre_len; cp++) { if (*cp == '/') slash_cnt++; } } - strlcpy(ret->pattern + pre_len, pat, pat_len + 1); + strlcpy(filter->pattern + pre_len, pat, pat_len + 1); pat_len += pre_len; if (suf_len) { - memcpy(ret->pattern + pat_len, SLASH_WILD3_SUFFIX, suf_len+1); + memcpy(filter->pattern + pat_len, SLASH_WILD3_SUFFIX, suf_len+1); pat_len += suf_len; slash_cnt++; } - if (strpbrk(ret->pattern, "*[?")) { - mflags |= MATCHFLG_WILD; - if ((cp = strstr(ret->pattern, "**")) != NULL) { - mflags |= MATCHFLG_WILD2; + if (strpbrk(filter->pattern, "*[?")) { + filter->flags |= MATCHFLG_WILD; + if ((cp = strstr(filter->pattern, "**")) != NULL) { + filter->flags |= MATCHFLG_WILD2; /* If the pattern starts with **, note that. */ - if (cp == ret->pattern) - mflags |= MATCHFLG_WILD2_PREFIX; + if (cp == filter->pattern) + filter->flags |= MATCHFLG_WILD2_PREFIX; /* If the pattern ends with ***, note that. */ if (pat_len >= 3 - && ret->pattern[pat_len-3] == '*' - && ret->pattern[pat_len-2] == '*' - && ret->pattern[pat_len-1] == '*') - mflags |= MATCHFLG_WILD3_SUFFIX; + && filter->pattern[pat_len-3] == '*' + && filter->pattern[pat_len-2] == '*' + && filter->pattern[pat_len-1] == '*') + filter->flags |= MATCHFLG_WILD3_SUFFIX; } } - if (mflags & MATCHFLG_PERDIR_MERGE) { + if (filter->flags & MATCHFLG_PERDIR_MERGE) { struct filter_list_struct *lp; unsigned int len; int i; - if ((cp = strrchr(ret->pattern, '/')) != NULL) + if ((cp = strrchr(filter->pattern, '/')) != NULL) cp++; else - cp = ret->pattern; + cp = filter->pattern; /* If the local merge file was already mentioned, don't * add it again. */ @@ -265,9 +263,9 @@ static void add_rule(struct filter_list_struct *listp, const char *pat, else s = ex->pattern; len = strlen(s); - if (len == pat_len - (cp - ret->pattern) + if (len == pat_len - (cp - filter->pattern) && memcmp(s, cp, len) == 0) { - free_filter(ret); + free_filter(filter); return; } } @@ -277,7 +275,7 @@ static void add_rule(struct filter_list_struct *listp, const char *pat, lp->head = lp->tail = lp->parent_dirscan_head = NULL; if (asprintf(&lp->debug_type, " [per-dir %s]", cp) < 0) out_of_memory("add_rule"); - ret->u.mergelist = lp; + filter->u.mergelist = lp; if (mergelist_cnt == mergelist_size) { mergelist_size += 5; @@ -291,19 +289,17 @@ static void add_rule(struct filter_list_struct *listp, const char *pat, rprintf(FINFO, "[%s] activating mergelist #%d%s\n", who_am_i(), mergelist_cnt, lp->debug_type); } - mergelist_parents[mergelist_cnt++] = ret; + mergelist_parents[mergelist_cnt++] = filter; } else - ret->u.slash_cnt = slash_cnt; - - ret->match_flags = mflags; + filter->u.slash_cnt = slash_cnt; if (!listp->tail) { - ret->next = listp->head; - listp->head = listp->tail = ret; + filter->next = listp->head; + listp->head = listp->tail = filter; } else { - ret->next = listp->tail->next; - listp->tail->next = ret; - listp->tail = ret; + filter->next = listp->tail->next; + listp->tail->next = filter; + listp->tail = filter; } } @@ -454,8 +450,8 @@ static BOOL setup_merge_file(int mergelist_num, struct filter_struct *ex, *y = '\0'; dirbuf_len = y - dirbuf; strlcpy(x, ex->pattern, MAXPATHLEN - (x - buf)); - parse_filter_file(lp, buf, ex->match_flags, XFLG_ANCHORED2ABS); - if (ex->match_flags & MATCHFLG_NO_INHERIT) { + load_filter_file(lp, buf, ex, XFLG_ANCHORED2ABS); + if (ex->flags & MATCHFLG_NO_INHERIT) { /* Free the undesired rules to clean up any per-dir * mergelists they defined. Otherwise pop_local_filters * may crash trying to restore nonexistent state for @@ -515,7 +511,7 @@ void *push_local_filters(const char *dir, unsigned int dirlen) sizeof (struct filter_list_struct)); } - /* Note: parse_filter_file() might increase mergelist_cnt, so keep + /* Note: load_filter_file() might increase mergelist_cnt, so keep * this loop separate from the above loop. */ for (i = 0; i < mergelist_cnt; i++) { struct filter_struct *ex = mergelist_parents[i]; @@ -527,18 +523,18 @@ void *push_local_filters(const char *dir, unsigned int dirlen) } lp->tail = NULL; /* Switch any local rules to inherited. */ - if (ex->match_flags & MATCHFLG_NO_INHERIT) + if (ex->flags & MATCHFLG_NO_INHERIT) lp->head = NULL; - if (ex->match_flags & MATCHFLG_FINISH_SETUP) { - ex->match_flags &= ~MATCHFLG_FINISH_SETUP; + if (ex->flags & MATCHFLG_FINISH_SETUP) { + ex->flags &= ~MATCHFLG_FINISH_SETUP; if (setup_merge_file(i, ex, lp)) set_filter_dir(dir, dirlen); } if (strlcpy(dirbuf + dirbuf_len, ex->pattern, MAXPATHLEN - dirbuf_len) < MAXPATHLEN - dirbuf_len) { - parse_filter_file(lp, dirbuf, ex->match_flags, + load_filter_file(lp, dirbuf, ex, XFLG_ANCHORED2ABS); } else { io_error |= IOERR_GENERAL; @@ -637,7 +633,7 @@ void change_local_filter_dir(const char *dname, int dlen, int dir_depth) static int rule_matches(const char *fname, struct filter_struct *ex, int name_is_dir) { int slash_handling, str_cnt = 0, anchored_match = 0; - int ret_match = ex->match_flags & MATCHFLG_NEGATE ? 0 : 1; + int ret_match = ex->flags & MATCHFLG_NEGATE ? 0 : 1; char *p, *pattern = ex->pattern; const char *strings[16]; /* more than enough */ const char *name = fname + (*fname == '/'); @@ -645,28 +641,28 @@ static int rule_matches(const char *fname, struct filter_struct *ex, int name_is if (!*name) return 0; - if (!ex->u.slash_cnt && !(ex->match_flags & MATCHFLG_WILD2)) { + if (!ex->u.slash_cnt && !(ex->flags & MATCHFLG_WILD2)) { /* If the pattern does not have any slashes AND it does * not have a "**" (which could match a slash), then we * just match the name portion of the path. */ if ((p = strrchr(name,'/')) != NULL) name = p+1; - } else if (ex->match_flags & MATCHFLG_ABS_PATH && *fname != '/' + } else if (ex->flags & MATCHFLG_ABS_PATH && *fname != '/' && curr_dir_len > module_dirlen + 1) { /* If we're matching against an absolute-path pattern, * we need to prepend our full path info. */ strings[str_cnt++] = curr_dir + module_dirlen + 1; strings[str_cnt++] = "/"; - } else if (ex->match_flags & MATCHFLG_WILD2_PREFIX && *fname != '/') { + } else if (ex->flags & MATCHFLG_WILD2_PREFIX && *fname != '/') { /* Allow "**"+"/" to match at the start of the string. */ strings[str_cnt++] = "/"; } strings[str_cnt++] = name; if (name_is_dir) { /* Allow a trailing "/"+"***" to match the directory. */ - if (ex->match_flags & MATCHFLG_WILD3_SUFFIX) + if (ex->flags & MATCHFLG_WILD3_SUFFIX) strings[str_cnt++] = "/"; - } else if (ex->match_flags & MATCHFLG_DIRECTORY) + } else if (ex->flags & MATCHFLG_DIRECTORY) return !ret_match; strings[str_cnt] = NULL; @@ -676,12 +672,12 @@ static int rule_matches(const char *fname, struct filter_struct *ex, int name_is } if (!anchored_match && ex->u.slash_cnt - && !(ex->match_flags & MATCHFLG_WILD2)) { + && !(ex->flags & MATCHFLG_WILD2)) { /* A non-anchored match with an infix slash and no "**" * needs to match the last slash_cnt+1 name elements. */ slash_handling = ex->u.slash_cnt + 1; - } else if (!anchored_match && !(ex->match_flags & MATCHFLG_WILD2_PREFIX) - && ex->match_flags & MATCHFLG_WILD2) { + } else if (!anchored_match && !(ex->flags & MATCHFLG_WILD2_PREFIX) + && ex->flags & MATCHFLG_WILD2) { /* A non-anchored match with an infix or trailing "**" (but not * a prefixed "**") needs to try matching after every slash. */ slash_handling = -1; @@ -690,7 +686,7 @@ static int rule_matches(const char *fname, struct filter_struct *ex, int name_is slash_handling = 0; } - if (ex->match_flags & MATCHFLG_WILD) { + if (ex->flags & MATCHFLG_WILD) { if (wildmatch_array(pattern, strings, slash_handling)) return ret_match; } else if (str_cnt > 1) { @@ -726,9 +722,9 @@ static void report_filter_result(enum logcode code, char const *name, = { {"show", "hid"}, {"risk", "protect"} }; const char *w = who_am_i(); rprintf(code, "[%s] %sing %s %s because of pattern %s%s%s\n", - w, actions[*w!='s'][!(ent->match_flags&MATCHFLG_INCLUDE)], + w, actions[*w!='s'][!(ent->flags&MATCHFLG_INCLUDE)], name_is_dir ? "directory" : "file", name, ent->pattern, - ent->match_flags & MATCHFLG_DIRECTORY ? "/" : "", type); + ent->flags & MATCHFLG_DIRECTORY ? "/" : "", type); } } @@ -743,16 +739,16 @@ int check_filter(struct filter_list_struct *listp, enum logcode code, struct filter_struct *ent; for (ent = listp->head; ent; ent = ent->next) { - if (ignore_perishable && ent->match_flags & MATCHFLG_PERISHABLE) + if (ignore_perishable && ent->flags & MATCHFLG_PERISHABLE) continue; - if (ent->match_flags & MATCHFLG_PERDIR_MERGE) { + if (ent->flags & MATCHFLG_PERDIR_MERGE) { int rc = check_filter(ent->u.mergelist, code, name, name_is_dir); if (rc) return rc; continue; } - if (ent->match_flags & MATCHFLG_CVS_IGNORE) { + if (ent->flags & MATCHFLG_CVS_IGNORE) { int rc = check_filter(&cvs_filter_list, code, name, name_is_dir); if (rc) @@ -762,7 +758,7 @@ int check_filter(struct filter_list_struct *listp, enum logcode code, if (rule_matches(name, ent, name_is_dir)) { report_filter_result(code, name, ent, name_is_dir, listp->debug_type); - return ent->match_flags & MATCHFLG_INCLUDE ? 1 : -1; + return ent->flags & MATCHFLG_INCLUDE ? 1 : -1; } } @@ -782,31 +778,42 @@ static const uchar *rule_strcmp(const uchar *str, const char *rule, int rule_len return NULL; } -/* Get the next include/exclude arg from the string. The token will not - * be '\0' terminated, so use the returned length to limit the string. - * Also, be sure to add this length to the returned pointer before passing - * it back to ask for the next token. This routine parses the "!" (list- - * clearing) token and (depending on the mflags) the various prefixes. - * The *mflags_ptr value will be set on exit to the new MATCHFLG_* bits - * for the current token. */ -static const char *parse_rule_tok(const char *p, uint32 mflags, int xflags, - unsigned int *len_ptr, uint32 *mflags_ptr) +#define MATCHFLGS_FROM_CONTAINER (MATCHFLG_ABS_PATH | MATCHFLG_INCLUDE \ + | MATCHFLG_DIRECTORY | MATCHFLG_NEGATE \ + | MATCHFLG_PERISHABLE) + +/* Gets the next include/exclude rule from *rulestr_ptr and advances + * *rulestr_ptr to point beyond it. Stores the pattern's start (within + * *rulestr_ptr) and length in *pat_ptr and *pat_len_ptr, and returns a newly + * allocated filter_struct containing the rest of the information. Returns + * NULL if there are no more rules in the input. + * + * The template provides defaults for the new rule to inherit, and the + * template mflags and the xflags additionally affect parsing. */ +static struct filter_struct *parse_rule_tok(const char **rulestr_ptr, + struct filter_struct *template, int xflags, + const char **pat_ptr, unsigned int *pat_len_ptr) { - const uchar *s = (const uchar *)p; - uint32 new_mflags; + const uchar *s = (const uchar *)*rulestr_ptr; + struct filter_struct *filter; unsigned int len; - if (mflags & MATCHFLG_WORD_SPLIT) { + if (template->flags & MATCHFLG_WORD_SPLIT) { /* Skip over any initial whitespace. */ while (isspace(*s)) s++; /* Update to point to real start of rule. */ - p = (const char *)s; + *rulestr_ptr = (const char *)s; } if (!*s) return NULL; - new_mflags = mflags & MATCHFLGS_FROM_CONTAINER; + if (!(filter = new0(struct filter_struct))) + out_of_memory("parse_rule_tok"); + + /* Inherit from the template. Don't inherit MATCHFLGS_SIDES; we check + * that later. */ + filter->flags = template->flags & MATCHFLGS_FROM_CONTAINER; /* Figure out what kind of a filter rule "s" is pointing at. Note * that if MATCHFLG_NO_PREFIXES is set, the rule is either an include @@ -814,20 +821,21 @@ static const char *parse_rule_tok(const char *p, uint32 mflags, int xflags, * flag (above). XFLG_OLD_PREFIXES indicates a compatibility mode * for old include/exclude patterns where just "+ " and "- " are * allowed as optional prefixes. */ - if (mflags & MATCHFLG_NO_PREFIXES) { - if (*s == '!' && mflags & MATCHFLG_CVS_IGNORE) - new_mflags |= MATCHFLG_CLEAR_LIST; /* Tentative! */ + if (template->flags & MATCHFLG_NO_PREFIXES) { + if (*s == '!' && template->flags & MATCHFLG_CVS_IGNORE) + filter->flags |= MATCHFLG_CLEAR_LIST; /* Tentative! */ } else if (xflags & XFLG_OLD_PREFIXES) { if (*s == '-' && s[1] == ' ') { - new_mflags &= ~MATCHFLG_INCLUDE; + filter->flags &= ~MATCHFLG_INCLUDE; s += 2; } else if (*s == '+' && s[1] == ' ') { - new_mflags |= MATCHFLG_INCLUDE; + filter->flags |= MATCHFLG_INCLUDE; s += 2; } else if (*s == '!') - new_mflags |= MATCHFLG_CLEAR_LIST; /* Tentative! */ + filter->flags |= MATCHFLG_CLEAR_LIST; /* Tentative! */ } else { - char ch = 0, *mods = ""; + char ch = 0; + BOOL prefix_specifies_side = False; switch (*s) { case 'c': if ((s = RULE_STRCMP(s, "clear")) != NULL) @@ -873,104 +881,126 @@ static const char *parse_rule_tok(const char *p, uint32 mflags, int xflags, } switch (ch) { case ':': - new_mflags |= MATCHFLG_PERDIR_MERGE - | MATCHFLG_FINISH_SETUP; + filter->flags |= MATCHFLG_PERDIR_MERGE + | MATCHFLG_FINISH_SETUP; /* FALL THROUGH */ case '.': - new_mflags |= MATCHFLG_MERGE_FILE; - mods = MODIFIERS_INCL_EXCL MODIFIERS_MERGE_FILE; + filter->flags |= MATCHFLG_MERGE_FILE; break; case '+': - new_mflags |= MATCHFLG_INCLUDE; + filter->flags |= MATCHFLG_INCLUDE; /* FALL THROUGH */ case '-': - mods = MODIFIERS_INCL_EXCL; break; case 'S': - new_mflags |= MATCHFLG_INCLUDE; + filter->flags |= MATCHFLG_INCLUDE; /* FALL THROUGH */ case 'H': - new_mflags |= MATCHFLG_SENDER_SIDE; - mods = MODIFIERS_HIDE_PROTECT; + filter->flags |= MATCHFLG_SENDER_SIDE; + prefix_specifies_side = True; break; case 'R': - new_mflags |= MATCHFLG_INCLUDE; + filter->flags |= MATCHFLG_INCLUDE; /* FALL THROUGH */ case 'P': - new_mflags |= MATCHFLG_RECEIVER_SIDE; - mods = MODIFIERS_HIDE_PROTECT; + filter->flags |= MATCHFLG_RECEIVER_SIDE; + prefix_specifies_side = True; break; case '!': - new_mflags |= MATCHFLG_CLEAR_LIST; - mods = NULL; + filter->flags |= MATCHFLG_CLEAR_LIST; break; default: - rprintf(FERROR, "Unknown filter rule: `%s'\n", p); + rprintf(FERROR, "Unknown filter rule: `%s'\n", *rulestr_ptr); exit_cleanup(RERR_SYNTAX); } - while (mods && *++s && *s != ' ' && *s != '_') { - if (strchr(mods, *s) == NULL) { - if (mflags & MATCHFLG_WORD_SPLIT && isspace(*s)) { - s--; - break; - } + while (ch != '!' && *++s && *s != ' ' && *s != '_') { + if (template->flags & MATCHFLG_WORD_SPLIT && isspace(*s)) { + s--; + break; + } + switch (*s) { + default: invalid: rprintf(FERROR, - "invalid modifier sequence at '%c' in filter rule: %s\n", - *s, p); + "invalid modifier '%c' at position %d in filter rule: %s\n", + *s, s - (const uchar *)*rulestr_ptr, *rulestr_ptr); exit_cleanup(RERR_SYNTAX); - } - switch (*s) { case '-': - if (new_mflags & MATCHFLG_NO_PREFIXES) - goto invalid; - new_mflags |= MATCHFLG_NO_PREFIXES; + if (!BITS_SETnUNSET(filter->flags, MATCHFLG_MERGE_FILE, MATCHFLG_NO_PREFIXES)) + goto invalid; + filter->flags |= MATCHFLG_NO_PREFIXES; break; case '+': - if (new_mflags & MATCHFLG_NO_PREFIXES) - goto invalid; - new_mflags |= MATCHFLG_NO_PREFIXES - | MATCHFLG_INCLUDE; + if (!BITS_SETnUNSET(filter->flags, MATCHFLG_MERGE_FILE, MATCHFLG_NO_PREFIXES)) + goto invalid; + filter->flags |= MATCHFLG_NO_PREFIXES + | MATCHFLG_INCLUDE; break; case '/': - new_mflags |= MATCHFLG_ABS_PATH; + filter->flags |= MATCHFLG_ABS_PATH; break; case '!': - new_mflags |= MATCHFLG_NEGATE; + /* Negation really goes with the pattern, so it + * isn't useful as a merge-file default. */ + if (filter->flags & MATCHFLG_MERGE_FILE) + goto invalid; + filter->flags |= MATCHFLG_NEGATE; break; case 'C': - if (new_mflags & MATCHFLG_NO_PREFIXES) - goto invalid; - new_mflags |= MATCHFLG_NO_PREFIXES - | MATCHFLG_WORD_SPLIT - | MATCHFLG_NO_INHERIT - | MATCHFLG_CVS_IGNORE; + if (filter->flags & MATCHFLG_NO_PREFIXES || prefix_specifies_side) + goto invalid; + filter->flags |= MATCHFLG_NO_PREFIXES + | MATCHFLG_WORD_SPLIT + | MATCHFLG_NO_INHERIT + | MATCHFLG_CVS_IGNORE; break; case 'e': - new_mflags |= MATCHFLG_EXCLUDE_SELF; + if (!(filter->flags & MATCHFLG_MERGE_FILE)) + goto invalid; + filter->flags |= MATCHFLG_EXCLUDE_SELF; break; case 'n': - new_mflags |= MATCHFLG_NO_INHERIT; + if (!(filter->flags & MATCHFLG_MERGE_FILE)) + goto invalid; + filter->flags |= MATCHFLG_NO_INHERIT; break; case 'p': - new_mflags |= MATCHFLG_PERISHABLE; + filter->flags |= MATCHFLG_PERISHABLE; break; case 'r': - new_mflags |= MATCHFLG_RECEIVER_SIDE; + if (prefix_specifies_side) + goto invalid; + filter->flags |= MATCHFLG_RECEIVER_SIDE; break; case 's': - new_mflags |= MATCHFLG_SENDER_SIDE; + if (prefix_specifies_side) + goto invalid; + filter->flags |= MATCHFLG_SENDER_SIDE; break; case 'w': - new_mflags |= MATCHFLG_WORD_SPLIT; + if (!(filter->flags & MATCHFLG_MERGE_FILE)) + goto invalid; + filter->flags |= MATCHFLG_WORD_SPLIT; break; } } if (*s) s++; } + if (template->flags & MATCHFLGS_SIDES) { + if (filter->flags & MATCHFLGS_SIDES) { + /* The filter and template both specify side(s). This + * is dodgy (and won't work correctly if the template is + * a one-sided per-dir merge rule), so reject it. */ + rprintf(FERROR, + "specified-side merge file contains specified-side filter: %s\n", + *rulestr_ptr); + exit_cleanup(RERR_SYNTAX); + } + filter->flags |= template->flags & MATCHFLGS_SIDES; + } - if (mflags & MATCHFLG_WORD_SPLIT) { + if (template->flags & MATCHFLG_WORD_SPLIT) { const uchar *cp = s; /* Token ends at whitespace or the end of the string. */ while (!isspace(*cp) && *cp != '\0') @@ -979,17 +1009,17 @@ static const char *parse_rule_tok(const char *p, uint32 mflags, int xflags, } else len = strlen((char*)s); - if (new_mflags & MATCHFLG_CLEAR_LIST) { - if (!(mflags & MATCHFLG_NO_PREFIXES) + if (filter->flags & MATCHFLG_CLEAR_LIST) { + if (!(filter->flags & MATCHFLG_NO_PREFIXES) && !(xflags & XFLG_OLD_PREFIXES) && len) { rprintf(FERROR, - "'!' rule has trailing characters: %s\n", p); + "'!' rule has trailing characters: %s\n", *rulestr_ptr); exit_cleanup(RERR_SYNTAX); } if (len > 1) - new_mflags &= ~MATCHFLG_CLEAR_LIST; - } else if (!len && !(new_mflags & MATCHFLG_CVS_IGNORE)) { - rprintf(FERROR, "unexpected end of filter rule: %s\n", p); + filter->flags &= ~MATCHFLG_CLEAR_LIST; + } else if (!len && !(filter->flags & MATCHFLG_CVS_IGNORE)) { + rprintf(FERROR, "unexpected end of filter rule: %s\n", *rulestr_ptr); exit_cleanup(RERR_SYNTAX); } @@ -997,14 +1027,15 @@ static const char *parse_rule_tok(const char *p, uint32 mflags, int xflags, * sender-side rule. We also affect per-dir merge files that take * no prefixes as a simple optimization. */ if (delete_excluded - && !(new_mflags & (MATCHFLG_RECEIVER_SIDE|MATCHFLG_SENDER_SIDE)) - && (!(new_mflags & MATCHFLG_PERDIR_MERGE) - || new_mflags & MATCHFLG_NO_PREFIXES)) - new_mflags |= MATCHFLG_SENDER_SIDE; - - *len_ptr = len; - *mflags_ptr = new_mflags; - return (const char *)s; + && !(filter->flags & MATCHFLGS_SIDES) + && (!(filter->flags & MATCHFLG_PERDIR_MERGE) + || filter->flags & MATCHFLG_NO_PREFIXES)) + filter->flags |= MATCHFLG_SENDER_SIDE; + + *pat_ptr = (const char *)s; + *pat_len_ptr = len; + *rulestr_ptr = *pat_ptr + len; + return filter; } @@ -1018,110 +1049,129 @@ static char default_cvsignore[] = /* The rest we added to suit ourself. */ " .svn/ .git/ .bzr/"; -static void get_cvs_excludes(uint32 mflags) +static void get_cvs_excludes(struct filter_struct *template) { static int initialized = 0; char *p, fname[MAXPATHLEN]; + uint32 save_mflags; if (initialized) return; initialized = 1; - parse_rule(&cvs_filter_list, default_cvsignore, - mflags | (protocol_version >= 30 ? MATCHFLG_PERISHABLE : 0), - 0); + save_mflags = template->flags; + if (protocol_version >= 30) + template->flags |= MATCHFLG_PERISHABLE; + load_filter_str(&cvs_filter_list, default_cvsignore, template, 0); + template->flags = save_mflags; p = module_id >= 0 && lp_use_chroot(module_id) ? "/" : getenv("HOME"); if (p && pathjoin(fname, MAXPATHLEN, p, ".cvsignore") < MAXPATHLEN) - parse_filter_file(&cvs_filter_list, fname, mflags, 0); + load_filter_file(&cvs_filter_list, fname, template, 0); + + load_filter_str(&cvs_filter_list, getenv("CVSIGNORE"), template, 0); +} + - parse_rule(&cvs_filter_list, getenv("CVSIGNORE"), mflags, 0); +struct filter_struct *filter_template(uint32 mflags) +{ + static struct filter_struct template; /* zero-initialized */ + template.flags = mflags; + return &template; } -void parse_rule(struct filter_list_struct *listp, const char *pattern, - uint32 mflags, int xflags) +void load_filter_str(struct filter_list_struct *listp, const char *rulestr, + struct filter_struct *template, int xflags) { + struct filter_struct *filter; + const char *pat; unsigned int pat_len; - uint32 new_mflags; - const char *cp, *p; - if (!pattern) + if (!rulestr) return; while (1) { /* Remember that the returned string is NOT '\0' terminated! */ - cp = parse_rule_tok(pattern, mflags, xflags, - &pat_len, &new_mflags); - if (!cp) + filter = parse_rule_tok(&rulestr, template, xflags, + &pat, &pat_len); + if (!filter) break; - pattern = cp + pat_len; - if (pat_len >= MAXPATHLEN) { rprintf(FERROR, "discarding over-long filter: %.*s\n", - (int)pat_len, cp); + (int)pat_len, pat); + free_continue: + free_filter(filter); continue; } - if (new_mflags & MATCHFLG_CLEAR_LIST) { + if (filter->flags & MATCHFLG_CLEAR_LIST) { if (DEBUG_GTE(FILTER, 2)) { rprintf(FINFO, "[%s] clearing filter list%s\n", who_am_i(), listp->debug_type); } clear_filter_list(listp); - continue; + goto free_continue; } - if (new_mflags & MATCHFLG_MERGE_FILE) { - unsigned int len; + if (filter->flags & MATCHFLG_MERGE_FILE) { if (!pat_len) { - cp = ".cvsignore"; + pat = ".cvsignore"; pat_len = 10; } - len = pat_len; - if (new_mflags & MATCHFLG_EXCLUDE_SELF) { - const char *name = cp + len; - while (name > cp && name[-1] != '/') name--; - len -= name - cp; - add_rule(listp, name, len, 0, 0); - new_mflags &= ~MATCHFLG_EXCLUDE_SELF; - len = pat_len; + if (filter->flags & MATCHFLG_EXCLUDE_SELF) { + const char *name; + struct filter_struct *excl_self; + + if (!(excl_self = new0(struct filter_struct))) + out_of_memory("load_filter_str"); + /* Find the beginning of the basename. */ + for (name = pat + pat_len; name > pat && name[-1] != '/'; name--) + ; + add_rule(listp, name, (pat + pat_len) - name, excl_self, 0); + filter->flags &= ~MATCHFLG_EXCLUDE_SELF; } - if (new_mflags & MATCHFLG_PERDIR_MERGE) { + if (filter->flags & MATCHFLG_PERDIR_MERGE) { if (parent_dirscan) { - if (!(p = parse_merge_name(cp, &len, + const char *p; + unsigned int len = pat_len; + if ((p = parse_merge_name(pat, &len, module_dirlen))) - continue; - add_rule(listp, p, len, new_mflags, 0); + add_rule(listp, p, len, filter, 0); + else + free_filter(filter); continue; } } else { - if (!(p = parse_merge_name(cp, &len, 0))) - continue; - parse_filter_file(listp, p, new_mflags, - XFLG_FATAL_ERRORS); + const char *p; + unsigned int len = pat_len; + if ((p = parse_merge_name(pat, &len, 0))) { + load_filter_file(listp, p, filter, + XFLG_FATAL_ERRORS); + } + free_filter(filter); continue; } } - add_rule(listp, cp, pat_len, new_mflags, xflags); + if (filter->flags & MATCHFLG_CVS_IGNORE + && !(filter->flags & MATCHFLG_MERGE_FILE)) + get_cvs_excludes(filter); - if (new_mflags & MATCHFLG_CVS_IGNORE - && !(new_mflags & MATCHFLG_MERGE_FILE)) - get_cvs_excludes(new_mflags); + add_rule(listp, pat, pat_len, filter, xflags); } } -void parse_filter_file(struct filter_list_struct *listp, const char *fname, - uint32 mflags, int xflags) +void load_filter_file(struct filter_list_struct *listp, const char *fname, + struct filter_struct *template, int xflags) { FILE *fp; char line[BIGPATHBUFLEN]; char *eob = line + sizeof line - 1; - int word_split = mflags & MATCHFLG_WORD_SPLIT; + BOOL word_split = (template->flags & MATCHFLG_WORD_SPLIT) != 0; if (!fname || !*fname) return; @@ -1140,8 +1190,8 @@ void parse_filter_file(struct filter_list_struct *listp, const char *fname, fp = stdin; if (DEBUG_GTE(FILTER, 2)) { - rprintf(FINFO, "[%s] parse_filter_file(%s,%x,%x)%s\n", - who_am_i(), fname, mflags, xflags, + rprintf(FINFO, "[%s] load_filter_file(%s,%x,%x)%s\n", + who_am_i(), fname, template->flags, xflags, fp ? "" : " [not found]"); } @@ -1149,7 +1199,7 @@ void parse_filter_file(struct filter_list_struct *listp, const char *fname, if (xflags & XFLG_FATAL_ERRORS) { rsyserr(FERROR, errno, "failed to open %sclude file %s", - mflags & MATCHFLG_INCLUDE ? "in" : "ex", + template->flags & MATCHFLG_INCLUDE ? "in" : "ex", fname); exit_cleanup(RERR_FILEIO); } @@ -1184,7 +1234,7 @@ void parse_filter_file(struct filter_list_struct *listp, const char *fname, *s = '\0'; /* Skip an empty token and (when line parsing) comments. */ if (*line && (word_split || (*line != ';' && *line != '#'))) - parse_rule(listp, line, mflags, xflags); + load_filter_str(listp, line, template, xflags); if (ch == EOF) break; } @@ -1194,18 +1244,18 @@ void parse_filter_file(struct filter_list_struct *listp, const char *fname, /* If the "for_xfer" flag is set, the prefix is made compatible with the * current protocol_version (if possible) or a NULL is returned (if not * possible). */ -char *get_rule_prefix(int match_flags, const char *pat, int for_xfer, +char *get_rule_prefix(struct filter_struct *filter, const char *pat, int for_xfer, unsigned int *plen_ptr) { static char buf[MAX_RULE_PREFIX+1]; char *op = buf; int legal_len = for_xfer && protocol_version < 29 ? 1 : MAX_RULE_PREFIX-1; - if (match_flags & MATCHFLG_PERDIR_MERGE) { + if (filter->flags & MATCHFLG_PERDIR_MERGE) { if (legal_len == 1) return NULL; *op++ = ':'; - } else if (match_flags & MATCHFLG_INCLUDE) + } else if (filter->flags & MATCHFLG_INCLUDE) *op++ = '+'; else if (legal_len != 1 || ((*pat == '-' || *pat == '+') && pat[1] == ' ')) @@ -1213,32 +1263,34 @@ char *get_rule_prefix(int match_flags, const char *pat, int for_xfer, else legal_len = 0; - if (match_flags & MATCHFLG_NEGATE) + if (filter->flags & MATCHFLG_ABS_PATH) + *op++ = '/'; + if (filter->flags & MATCHFLG_NEGATE) *op++ = '!'; - if (match_flags & MATCHFLG_CVS_IGNORE) + if (filter->flags & MATCHFLG_CVS_IGNORE) *op++ = 'C'; else { - if (match_flags & MATCHFLG_NO_INHERIT) + if (filter->flags & MATCHFLG_NO_INHERIT) *op++ = 'n'; - if (match_flags & MATCHFLG_WORD_SPLIT) + if (filter->flags & MATCHFLG_WORD_SPLIT) *op++ = 'w'; - if (match_flags & MATCHFLG_NO_PREFIXES) { - if (match_flags & MATCHFLG_INCLUDE) + if (filter->flags & MATCHFLG_NO_PREFIXES) { + if (filter->flags & MATCHFLG_INCLUDE) *op++ = '+'; else *op++ = '-'; } } - if (match_flags & MATCHFLG_EXCLUDE_SELF) + if (filter->flags & MATCHFLG_EXCLUDE_SELF) *op++ = 'e'; - if (match_flags & MATCHFLG_SENDER_SIDE + if (filter->flags & MATCHFLG_SENDER_SIDE && (!for_xfer || protocol_version >= 29)) *op++ = 's'; - if (match_flags & MATCHFLG_RECEIVER_SIDE + if (filter->flags & MATCHFLG_RECEIVER_SIDE && (!for_xfer || protocol_version >= 29 || (delete_excluded && am_sender))) *op++ = 'r'; - if (match_flags & MATCHFLG_PERISHABLE) { + if (filter->flags & MATCHFLG_PERISHABLE) { if (!for_xfer || protocol_version >= 30) *op++ = 'p'; else if (am_sender) @@ -1270,13 +1322,13 @@ static void send_rules(int f_out, struct filter_list_struct *flp) * backward compatibility problem, and we elide any no-prefix * merge files as an optimization (since they can only have * include/exclude rules). */ - if (ent->match_flags & MATCHFLG_SENDER_SIDE) + if (ent->flags & MATCHFLG_SENDER_SIDE) elide = am_sender ? 1 : -1; - if (ent->match_flags & MATCHFLG_RECEIVER_SIDE) + if (ent->flags & MATCHFLG_RECEIVER_SIDE) elide = elide ? 0 : am_sender ? -1 : 1; else if (delete_excluded && !elide - && (!(ent->match_flags & MATCHFLG_PERDIR_MERGE) - || ent->match_flags & MATCHFLG_NO_PREFIXES)) + && (!(ent->flags & MATCHFLG_PERDIR_MERGE) + || ent->flags & MATCHFLG_NO_PREFIXES)) elide = am_sender ? 1 : -1; if (elide < 0) { if (prev) @@ -1287,14 +1339,14 @@ static void send_rules(int f_out, struct filter_list_struct *flp) prev = ent; if (elide > 0) continue; - if (ent->match_flags & MATCHFLG_CVS_IGNORE - && !(ent->match_flags & MATCHFLG_MERGE_FILE)) { + if (ent->flags & MATCHFLG_CVS_IGNORE + && !(ent->flags & MATCHFLG_MERGE_FILE)) { int f = am_sender || protocol_version < 29 ? f_out : -2; send_rules(f, &cvs_filter_list); if (f == f_out) continue; } - p = get_rule_prefix(ent->match_flags, ent->pattern, 1, &plen); + p = get_rule_prefix(ent, ent->pattern, 1, &plen); if (!p) { rprintf(FERROR, "filter rules are too modern for remote rsync.\n"); @@ -1303,7 +1355,7 @@ static void send_rules(int f_out, struct filter_list_struct *flp) if (f_out < 0) continue; len = strlen(ent->pattern); - dlen = ent->match_flags & MATCHFLG_DIRECTORY ? 1 : 0; + dlen = ent->flags & MATCHFLG_DIRECTORY ? 1 : 0; if (!(plen + len + dlen)) continue; write_int(f_out, plen + len + dlen); @@ -1326,8 +1378,8 @@ void send_filter_list(int f_out) f_out = -1; if (cvs_exclude && am_sender) { if (protocol_version >= 29) - parse_rule(&filter_list, ":C", 0, 0); - parse_rule(&filter_list, "-C", 0, 0); + load_filter_str(&filter_list, ":C", filter_template(0), 0); + load_filter_str(&filter_list, "-C", filter_template(0), 0); } send_rules(f_out, &filter_list); @@ -1337,9 +1389,9 @@ void send_filter_list(int f_out) if (cvs_exclude) { if (!am_sender || protocol_version < 29) - parse_rule(&filter_list, ":C", 0, 0); + load_filter_str(&filter_list, ":C", filter_template(0), 0); if (!am_sender) - parse_rule(&filter_list, "-C", 0, 0); + load_filter_str(&filter_list, "-C", filter_template(0), 0); } } @@ -1358,15 +1410,15 @@ void recv_filter_list(int f_in) if (len >= sizeof line) overflow_exit("recv_rules"); read_sbuf(f_in, line, len); - parse_rule(&filter_list, line, 0, xflags); + load_filter_str(&filter_list, line, filter_template(0), xflags); } } if (cvs_exclude) { if (local_server || am_sender || protocol_version < 29) - parse_rule(&filter_list, ":C", 0, 0); + load_filter_str(&filter_list, ":C", filter_template(0), 0); if (local_server || am_sender) - parse_rule(&filter_list, "-C", 0, 0); + load_filter_str(&filter_list, "-C", filter_template(0), 0); } if (local_server) /* filter out any rules that aren't for us. */ diff --git a/options.c b/options.c index 817e4305..c08a3376 100644 --- a/options.c +++ b/options.c @@ -1399,17 +1399,18 @@ int parse_arguments(int *argc_p, const char ***argv_p) break; case OPT_FILTER: - parse_rule(&filter_list, poptGetOptArg(pc), 0, 0); + load_filter_str(&filter_list, poptGetOptArg(pc), + filter_template(0), 0); break; case OPT_EXCLUDE: - parse_rule(&filter_list, poptGetOptArg(pc), - 0, XFLG_OLD_PREFIXES); + load_filter_str(&filter_list, poptGetOptArg(pc), + filter_template(0), XFLG_OLD_PREFIXES); break; case OPT_INCLUDE: - parse_rule(&filter_list, poptGetOptArg(pc), - MATCHFLG_INCLUDE, XFLG_OLD_PREFIXES); + load_filter_str(&filter_list, poptGetOptArg(pc), + filter_template(MATCHFLG_INCLUDE), XFLG_OLD_PREFIXES); break; case OPT_EXCLUDE_FROM: @@ -1431,8 +1432,8 @@ int parse_arguments(int *argc_p, const char ***argv_p) if (rej) goto options_rejected; } - parse_filter_file(&filter_list, arg, - opt == OPT_INCLUDE_FROM ? MATCHFLG_INCLUDE : 0, + load_filter_file(&filter_list, arg, + filter_template(opt == OPT_INCLUDE_FROM ? MATCHFLG_INCLUDE : 0), XFLG_FATAL_ERRORS | XFLG_OLD_PREFIXES); break; @@ -1489,10 +1490,10 @@ int parse_arguments(int *argc_p, const char ***argv_p) case 'F': switch (++F_option_cnt) { case 1: - parse_rule(&filter_list,": /.rsync-filter",0,0); + load_filter_str(&filter_list,": /.rsync-filter",filter_template(0),0); break; case 2: - parse_rule(&filter_list,"- .rsync-filter",0,0); + load_filter_str(&filter_list,"- .rsync-filter",filter_template(0),0); break; } break; @@ -1895,7 +1896,7 @@ int parse_arguments(int *argc_p, const char ***argv_p) list_only |= 1; if (xfer_dirs >= 4) { - parse_rule(&filter_list, "- /*/*", 0, 0); + load_filter_str(&filter_list, "- /*/*", filter_template(0), 0); recurse = xfer_dirs = 1; } else if (recurse) xfer_dirs = 1; @@ -2033,7 +2034,7 @@ int parse_arguments(int *argc_p, const char ***argv_p) } else if (make_backups && delete_mode && !delete_excluded && !am_server) { snprintf(backup_dir_buf, sizeof backup_dir_buf, "P *%s", backup_suffix); - parse_rule(&filter_list, backup_dir_buf, 0, 0); + load_filter_str(&filter_list, backup_dir_buf, filter_template(0), 0); } if (make_backups && !backup_dir) { diff --git a/rsync.h b/rsync.h index 3656c767..b85c0bb8 100644 --- a/rsync.h +++ b/rsync.h @@ -819,15 +819,12 @@ struct map_struct { #define MATCHFLG_CLEAR_LIST (1<<18)/* this item is the "!" token */ #define MATCHFLG_PERISHABLE (1<<19)/* perishable if parent dir goes away */ -#define MATCHFLGS_FROM_CONTAINER (MATCHFLG_ABS_PATH | MATCHFLG_INCLUDE \ - | MATCHFLG_DIRECTORY | MATCHFLG_SENDER_SIDE \ - | MATCHFLG_NEGATE | MATCHFLG_RECEIVER_SIDE \ - | MATCHFLG_PERISHABLE) +#define MATCHFLGS_SIDES (MATCHFLG_SENDER_SIDE | MATCHFLG_RECEIVER_SIDE) struct filter_struct { struct filter_struct *next; char *pattern; - uint32 match_flags; + uint32 flags; union { int slash_cnt; struct filter_list_struct *mergelist; @@ -857,8 +854,6 @@ struct stats { int xferred_files; }; -struct chmod_mode_struct; - struct flist_ndx_item { struct flist_ndx_item *next; int ndx; diff --git a/rsync.yo b/rsync.yo index 6b12dcc5..8d6aba30 100644 --- a/rsync.yo +++ b/rsync.yo @@ -2671,10 +2671,14 @@ itemization( also disabled). it() You may also specify any of the modifiers for the "+" or "-" rules (above) in order to have the rules that are read in from the file - default to having that modifier set. For instance, "merge,-/ .excl" would + default to having that modifier set (except for the bf(!) modifier, which + would not be useful). For instance, "merge,-/ .excl" would treat the contents of .excl as absolute-path excludes, while "dir-merge,s .filt" and ":sC" would each make all their - per-directory rules apply only on the sending side. + per-directory rules apply only on the sending side. If the merge rule + specifies sides to affect (via the bf(s) or bf(r) modifier or both), + then the rules in the file must not specify sides (via a modifier or + a rule prefix such as bf(hide)). ) Per-directory rules are inherited in all subdirectories of the directory