A repeated `--old-args` does more escape disabling.
authorWayne Davison <wayne@opencoder.net>
Mon, 10 Jan 2022 02:20:20 +0000 (18:20 -0800)
committerWayne Davison <wayne@opencoder.net>
Mon, 10 Jan 2022 02:20:23 +0000 (18:20 -0800)
options.c
rsync.1.md

index 2dba06e3c0f960de5c764f51ad304f4045bd6ea9..0a7b4cc799db7ef85ab0942c513a824754dcd287 100644 (file)
--- a/options.c
+++ b/options.c
@@ -578,7 +578,7 @@ enum {OPT_SERVER = 1000, OPT_DAEMON, OPT_SENDER, OPT_EXCLUDE, OPT_EXCLUDE_FROM,
       OPT_READ_BATCH, OPT_WRITE_BATCH, OPT_ONLY_WRITE_BATCH, OPT_MAX_SIZE,
       OPT_NO_D, OPT_APPEND, OPT_NO_ICONV, OPT_INFO, OPT_DEBUG, OPT_BLOCK_SIZE,
       OPT_USERMAP, OPT_GROUPMAP, OPT_CHOWN, OPT_BWLIMIT, OPT_STDERR,
-      OPT_OLD_COMPRESS, OPT_NEW_COMPRESS, OPT_NO_COMPRESS,
+      OPT_OLD_COMPRESS, OPT_NEW_COMPRESS, OPT_NO_COMPRESS, OPT_OLD_ARGS,
       OPT_STOP_AFTER, OPT_STOP_AT,
       OPT_REFUSED_BASE = 9000};
 
@@ -781,7 +781,7 @@ static struct poptOption long_options[] = {
   {"files-from",       0,  POPT_ARG_STRING, &files_from, 0, 0, 0 },
   {"from0",           '0', POPT_ARG_VAL,    &eol_nulls, 1, 0, 0},
   {"no-from0",         0,  POPT_ARG_VAL,    &eol_nulls, 0, 0, 0},
-  {"old-args",         0,  POPT_ARG_VAL,    &old_style_args, 1, 0, 0},
+  {"old-args",         0,  POPT_ARG_NONE,   0, OPT_OLD_ARGS, 0, 0},
   {"no-old-args",      0,  POPT_ARG_VAL,    &old_style_args, 0, 0, 0},
   {"protect-args",    's', POPT_ARG_VAL,    &protect_args, 1, 0, 0},
   {"no-protect-args",  0,  POPT_ARG_VAL,    &protect_args, 0, 0, 0},
@@ -1608,6 +1608,13 @@ int parse_arguments(int *argc_p, const char ***argv_p)
                        compress_choice = NULL;
                        break;
 
+               case OPT_OLD_ARGS:
+                       if (old_style_args <= 0)
+                               old_style_args = 1;
+                       else
+                               old_style_args++;
+                       break;
+
                case 'M':
                        arg = poptGetOptArg(pc);
                        if (*arg != '-') {
@@ -1927,7 +1934,7 @@ int parse_arguments(int *argc_p, const char ***argv_p)
 
        if (old_style_args < 0) {
                if (!am_server && (arg = getenv("RSYNC_OLD_ARGS")) != NULL && *arg)
-                       old_style_args = atoi(arg) ? 1 : 0;
+                       old_style_args = atoi(arg);
                else
                        old_style_args = 0;
        }
@@ -2477,7 +2484,7 @@ char *safe_arg(const char *opt, const char *arg)
        int len2 = strlen(arg);
        int extras = escape_leading_dash ? 2 : 0;
        char *ret;
-       if (!protect_args && (!old_style_args || (!is_filename_arg && opt != SPLIT_ARG_WHEN_OLD))) {
+       if (!protect_args && old_style_args < 2 && (!old_style_args || (!is_filename_arg && opt != SPLIT_ARG_WHEN_OLD))) {
                const char *f;
                for (f = arg; *f; f++) {
                        if (strchr(escapes, *f))
index f94e468c5522cc2e604949500e0b608cb6275feb..73532573530c599d56b882216cbb12e694a6b1ba 100644 (file)
@@ -2187,14 +2187,16 @@ your home directory (remove the '=' for that).
     even wildcards escaped).  The only active wildcard characters on the remote
     side are: `*`, `?`, `[`, & `]`.
 
-    If you have a script that wants to use old-style arg splitting, this option
-    should get it going.
+    If you have a script that wants to use old-style arg splitting in the
+    filenames, specify this option once.  If the remote shell has a problem
+    with any backslash escapes, specify the option twice.
 
     You may also control this setting via the RSYNC_OLD_ARGS environment
-    variable.  If this variable has a non-zero value, this setting will be
-    enabled by default, otherwise it will be disabled by default.  Either state
-    is overridden by a manually specified positive or negative version of this
-    option (the negative is `--no-old-args`).
+    variable.  If it has the value "1", rsync will default to a single-option
+    setting.  If it has the value "2" (or more), rsync will default to a
+    repeated-option setting.  If it is "0", you'll get the default escaping
+    behavior.  The environment is always overridden by manually specified
+    positive or negative options (the negative is `--no-old-args`).
 
 0.  `--protect-args`, `-s`
 
@@ -2212,7 +2214,7 @@ your home directory (remove the '=' for that).
     `--files-from` option.
 
     You may also control this setting via the RSYNC_PROTECT_ARGS environment
-    variable.  If this variable has a non-zero value, this setting will be
+    variable.  If it has a non-zero value, this setting will be
     enabled by default, otherwise it will be disabled by default.  Either state
     is overridden by a manually specified positive or negative version of this
     option (note that `--no-s` and `--no-protect-args` are the negative
@@ -4162,9 +4164,10 @@ file is included or excluded.
 
 0.  `RSYNC_OLD_ARGS`
 
-    Specify a non-zero numeric value if you want the `--old-args` option to be
-    enabled by default, or a zero value to make sure that it is disabled by
-    default. (First supported in 3.2.4.)
+    Specify a "1" if you want the `--old-args` option to be enabled by default,
+    a "2" (or more) if you want it to be enabled in the option-repeated state,
+    or a "0" to make sure that it is disabled by default. (First supported in
+    3.2.4.)
 
 0.  `RSYNC_PROTECT_ARGS`