From: Wayne Davison Date: Wed, 10 Jun 2020 18:05:09 +0000 (-0700) Subject: Fix a couple batchfile issues. X-Git-Tag: v3.2.0pre1~36 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f8683063fbe22eddc01146c78de1c7e72863ebbc;p=thirdparty%2Frsync.git Fix a couple batchfile issues. --- diff --git a/batch.c b/batch.c index b60752fc..b81d9556 100644 --- 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 diff --git a/checksum.c b/checksum.c index d7b2ebdd..87e83658 100644 --- a/checksum.c +++ b/checksum.c @@ -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 98bbaa68..155b178c 100644 --- 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);