Add a CAUTION message to --debug=FILTER for trailing whitespace.
authorWayne Davison <wayne@opencoder.net>
Thu, 27 Jan 2022 16:31:24 +0000 (08:31 -0800)
committerWayne Davison <wayne@opencoder.net>
Thu, 27 Jan 2022 16:53:41 +0000 (08:53 -0800)
NEWS.md
exclude.c
rsync.1.md

diff --git a/NEWS.md b/NEWS.md
index 3083ca3a84327136c91594a4d2ea383bac7fcddd..87abba2103f3ed143702653b0316a39b20381412 100644 (file)
--- a/NEWS.md
+++ b/NEWS.md
 
  - More ASM optimizations from Shark64.
 
+ - Using `--debug=FILTER` now outputs a caution message if a filter rule
+   has trailing whitespace.
+
  - Transformed rrsync into a python script with improvements:
    - Security has been beefed up.
    - The known rsync options were updated to include recent additions.
index e0957443b3403b30ca212254c31565ad5704df18..4ee06a84eacf101be32e0b9684f6433d10f2df31 100644 (file)
--- a/exclude.c
+++ b/exclude.c
@@ -152,13 +152,17 @@ static void add_rule(filter_rule_list *listp, const char *pat, unsigned int pat_
 {
        const char *cp;
        unsigned int pre_len, suf_len, slash_cnt = 0;
+       char *mention_rule_suffix;
 
-       if (DEBUG_GTE(FILTER, 2)) {
-               rprintf(FINFO, "[%s] add_rule(%s%.*s%s)%s\n",
+       if (DEBUG_GTE(FILTER, 1) && pat_len && (pat[pat_len-1] == ' ' || pat[pat_len-1] == '\t'))
+               mention_rule_suffix = " -- CAUTION: trailing whitespace!";
+       else
+               mention_rule_suffix = DEBUG_GTE(FILTER, 2) ? "" : NULL;
+       if (mention_rule_suffix) {
+               rprintf(FINFO, "[%s] add_rule(%s%.*s%s)%s%s\n",
                        who_am_i(), get_rule_prefix(rule, pat, 0, NULL),
-                       (int)pat_len, pat,
-                       (rule->rflags & FILTRULE_DIRECTORY) ? "/" : "",
-                       listp->debug_type);
+                       (int)pat_len, pat, (rule->rflags & FILTRULE_DIRECTORY) ? "/" : "",
+                       listp->debug_type, mention_rule_suffix);
        }
 
        /* These flags also indicate that we're reading a list that
index b5685d3fd1cc62d9c64802f0ebdca80c23813833..563f835b0addc88a0e5c3850087986d97a3085b6 100644 (file)
@@ -3723,6 +3723,14 @@ first matching pattern is acted on: if it is an exclude pattern, then that file
 is skipped; if it is an include pattern then that filename is not skipped; if
 no matching pattern is found, then the filename is not skipped.
 
+Aside: because the interactions of filter rules can be complex, it is useful to
+use the `--debug=FILTER` option if things aren't working they way you expect.
+The level-1 output (the default if no level number is specified) mentions the
+filter rule that is first matched by each file in the transfer.  It also warns
+if a filter rule has trailing whitespace.  The level-2 output mentions a lot
+more filter events, including the definition of each rule and the handling of
+per-directory filter files.
+
 Rsync builds an ordered list of filter rules as specified on the command-line.
 Filter rules have the following syntax: