From 56aeed5e71f9592db33da42b687a85f6d94e0f2e Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Sun, 27 Apr 2025 11:06:38 +0200 Subject: [PATCH] Add negation to merge files Signed-off-by: Kaspar Schleiser --- exclude.c | 24 ++++++++++++++++++++---- rsync.h | 1 + 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/exclude.c b/exclude.c index 87edbcf71..377556422 100644 --- a/exclude.c +++ b/exclude.c @@ -1239,11 +1239,10 @@ static filter_rule *parse_rule_tok(const char **rulestr_ptr, rule->rflags |= FILTRULE_ABS_PATH; break; case '!': - /* Negation really goes with the pattern, so it - * isn't useful as a merge-file default. */ if (rule->rflags & FILTRULE_MERGE_FILE) - goto invalid; - rule->rflags |= FILTRULE_NEGATE; + rule->rflags |= FILTRULE_DEFAULT_NONE; + else + rule->rflags |= FILTRULE_NEGATE; break; case 'C': if (rule->rflags & FILTRULE_NO_PREFIXES || prefix_specifies_side) @@ -1483,6 +1482,16 @@ void parse_filter_file(filter_rule_list *listp, const char *fname, const filter_ } return; } + + if (template->rflags & FILTRULE_DEFAULT_NONE) { + if (! (template->rflags & FILTRULE_EXCLUDE_SELF)) { + filter_rule *incl_self; + incl_self = new0(filter_rule); + incl_self->rflags |= FILTRULE_INCLUDE | FILTRULE_ABS_PATH; + add_rule(listp, fname, strlen(fname), incl_self, 0); + } + } + dirbuf[dirbuf_len] = '\0'; while (1) { @@ -1517,6 +1526,13 @@ void parse_filter_file(filter_rule_list *listp, const char *fname, const filter_ break; } fclose(fp); + + if (template->rflags & FILTRULE_DEFAULT_NONE) { + const char *name = "/**"; + filter_rule *default_none; + default_none = new0(filter_rule); + add_rule(listp, name, strlen(name), default_none, 0); + } } /* If the "for_xfer" flag is set, the prefix is made compatible with the diff --git a/rsync.h b/rsync.h index 479ac4848..16d449468 100644 --- a/rsync.h +++ b/rsync.h @@ -1010,6 +1010,7 @@ struct map_struct { #define FILTRULE_CLEAR_LIST (1<<18)/* this item is the "!" token */ #define FILTRULE_PERISHABLE (1<<19)/* perishable if parent dir goes away */ #define FILTRULE_XATTR (1<<20)/* rule only applies to xattr names */ +#define FILTRULE_DEFAULT_NONE (1<<21)/* for dir-merge, default do - ** */ #define FILTRULES_SIDES (FILTRULE_SENDER_SIDE | FILTRULE_RECEIVER_SIDE)