Fix a couple batchfile issues.
authorWayne Davison <wayne@opencoder.net>
Wed, 10 Jun 2020 18:05:09 +0000 (11:05 -0700)
committerWayne Davison <wayne@opencoder.net>
Wed, 10 Jun 2020 18:23:14 +0000 (11:23 -0700)
batch.c
checksum.c
main.c

diff --git a/batch.c b/batch.c
index b60752fc710feac27c16a996e7d747685ec47ebe..b81d9556d9ea07b439541117934826a174bb4682 100644 (file)
--- a/batch.c
+++ b/batch.c
@@ -38,6 +38,7 @@ extern int do_compression;
 extern int inplace;
 extern int append_mode;
 extern int write_batch;
+extern int xfersum_type;
 extern int protocol_version;
 extern int raw_argc, cooked_argc;
 extern char **raw_argv, **cooked_argv;
@@ -256,7 +257,7 @@ void open_batch_files(void)
  * (hopefully) work. */
 void write_batch_shell_file(void)
 {
-       int i, len, err = 0;
+       int i, j, len, err = 0;
        char *p, *p2;
 
        /* Write argvs info to BATCH.sh file */
@@ -273,15 +274,20 @@ void write_batch_shell_file(void)
         * do a string-based negotation (since we don't write them into the file). */
        if (do_compression)
                err |= write_opt("--compress-choice", compress_choice);
-       err |= write_opt("--checksum-choice", checksum_choice);
+       if (strchr(checksum_choice, ',') || xfersum_type != parse_csum_name(NULL, -1))
+               err |= write_opt("--checksum-choice", checksum_choice);
+
+       /* Elide the filename args from the option list, but scan for them in reverse. */
+       for (i = raw_argc-1, j = cooked_argc-1; i > 0 && j >= 0; i--) {
+               if (strcmp(raw_argv[i], cooked_argv[j]) == 0) {
+                       raw_argv[i] = NULL;
+                       j--;
+               }
+       }
 
        for (i = 1; i < raw_argc; i++) {
-               p = raw_argv[i];
-               if (cooked_argc && p[0] == cooked_argv[0][0] && strcmp(p, cooked_argv[0]) == 0) {
-                       cooked_argv++;
-                       cooked_argc--;
+               if (!(p = raw_argv[i]))
                        continue;
-               }
                if (strncmp(p, "--files-from", 12) == 0
                    || strncmp(p, "--filter", 8) == 0
                    || strncmp(p, "--include", 9) == 0
index d7b2ebdd50c21adb34d8040bf4d9eaeb2f42baeb..87e836583a347887b3194dcb5bc444ab01a72a6c 100644 (file)
@@ -54,7 +54,7 @@ struct name_num_obj valid_checksums = {
 int xfersum_type = 0; /* used for the file transfer checksums */
 int checksum_type = 0; /* used for the pre-transfer (--checksum) checksums */
 
-static int parse_csum_name(const char *name, int len)
+int parse_csum_name(const char *name, int len)
 {
        struct name_num_item *nni;
 
diff --git a/main.c b/main.c
index 98bbaa6872f6fd24babd7c6b850f7ed40676aec5..155b178cecb40278209e1cd96e4e280077437d68 100644 (file)
--- a/main.c
+++ b/main.c
@@ -1706,8 +1706,13 @@ int main(int argc,char *argv[])
                option_error();
                exit_cleanup(RERR_SYNTAX);
        }
-       cooked_argc = argc;
-       cooked_argv = argv;
+       if (write_batch) {
+               int j;
+               cooked_argc = argc;
+               cooked_argv = new_array(char*, argc+1);
+               for (j = 0; j <= argc; j++)
+                       cooked_argv[j] = argv[j];
+       }
 
        SIGACTMASK(SIGINT, sig_int);
        SIGACTMASK(SIGHUP, sig_int);