]> git.ipfire.org Git - thirdparty/rsync.git/commitdiff
Fix a bug in the writing of the batch.sh file
authorWayne Davison <wayne@opencoder.net>
Fri, 22 May 2020 15:10:41 +0000 (08:10 -0700)
committerWayne Davison <wayne@opencoder.net>
Fri, 22 May 2020 15:27:07 +0000 (08:27 -0700)
Fix the code that writes the options and the default destination path
into the batch.sh file to be able to handle options being specified
after source/dest args.

batch.c
main.c

diff --git a/batch.c b/batch.c
index 263a9a357d21b52609606c67cce2cd307e6f9090..8915d9e0f3560243bfeec0a8d8bd65cf9399234a 100644 (file)
--- a/batch.c
+++ b/batch.c
@@ -213,7 +213,7 @@ static void write_filter_rules(int fd)
  * understand most of the options, so it uses some overly simple
  * heuristics to munge the command line into something that will
  * (hopefully) work. */
-void write_batch_shell_file(int argc, char *argv[], int file_arg_cnt)
+void write_batch_shell_file(int argc, char *argv[], int file_argc, char *file_argv[])
 {
        int fd, i, len, err = 0;
        char *p, *p2, filename[MAXPATHLEN];
@@ -237,8 +237,15 @@ void write_batch_shell_file(int argc, char *argv[], int file_arg_cnt)
                else
                        write_sbuf(fd, " --exclude-from=-");
        }
-       for (i = 1; i < argc - file_arg_cnt; i++) {
+       for (i = 1; i < argc; i++) {
                p = argv[i];
+               if (file_argc && p == file_argv[0]) {
+                       if (file_argc > 1) {
+                               file_argv++;
+                               file_argc--;
+                       }
+                       continue;
+               }
                if (strncmp(p, "--files-from", 12) == 0
                    || strncmp(p, "--filter", 8) == 0
                    || strncmp(p, "--include", 9) == 0
@@ -267,8 +274,8 @@ void write_batch_shell_file(int argc, char *argv[], int file_arg_cnt)
                                err = 1;
                }
        }
-       if (!(p = check_for_hostspec(argv[argc - 1], &p2, &i)))
-               p = argv[argc - 1];
+       if (!(p = check_for_hostspec(file_argv[file_argc - 1], &p2, &i)))
+               p = file_argv[file_argc - 1];
        if (write(fd, " ${1:-", 6) != 6
         || write_arg(fd, p) < 0)
                err = 1;
diff --git a/main.c b/main.c
index ca96270a14c34f54b84afe747bdcefad2e5f28c1..2e2094d26bcafb8e31a55bc81693168b0bec6b39 100644 (file)
--- a/main.c
+++ b/main.c
@@ -1726,7 +1726,7 @@ int main(int argc,char *argv[])
 
        if ((write_batch || read_batch) && !am_server) {
                if (write_batch)
-                       write_batch_shell_file(orig_argc, orig_argv, argc);
+                       write_batch_shell_file(orig_argc, orig_argv, argc, argv);
 
                if (read_batch && strcmp(batch_name, "-") == 0)
                        batch_fd = STDIN_FILENO;