Patch from Jos Backus -- Fix breakage from dev_t to DEV64_T in batch
authorMartin Pool <mbp@samba.org>
Wed, 23 Jan 2002 05:51:06 +0000 (05:51 +0000)
committerMartin Pool <mbp@samba.org>
Wed, 23 Jan 2002 05:51:06 +0000 (05:51 +0000)
mode.

Also, drop -f and -F for batch mode: these should be reserved for
options that are more commonly used.

It also appends a newline to the argvs file and skips adding the
source directory to the command line.

batch.c
main.c
options.c
rsync.yo
sender.c
util.c

diff --git a/batch.c b/batch.c
index 4074e05..3482673 100644 (file)
--- a/batch.c
+++ b/batch.c
@@ -35,6 +35,7 @@ void create_batch_file_ext()
                timeptr->tm_year + 1900, timeptr->tm_mon + 1,
                timeptr->tm_mday, timeptr->tm_hour, timeptr->tm_min,
                timeptr->tm_sec);
+       rprintf(FINFO,"batch file extension: %s\n", batch_file_ext);
 }
 
 void set_batch_file_ext(char *ext)
@@ -84,12 +85,16 @@ void write_batch_flist_info(int flist_count, struct file_struct **fptr)
 
        /* Write flist info to batch file */
 
-       bytes_to_write = sizeof(unsigned) +
+       bytes_to_write =
+           sizeof(unsigned) +
            sizeof(time_t) +
            sizeof(OFF_T) +
            sizeof(mode_t) +
            sizeof(INO64_T) +
-           (2 * sizeof(DEV64_T)) + sizeof(uid_t) + sizeof(gid_t);
+           sizeof(DEV64_T) +
+           sizeof(DEV64_T) +
+           sizeof(uid_t) +
+           sizeof(gid_t);
 
        fdb_open = 1;
        fdb_close = 0;
@@ -128,7 +133,7 @@ void write_char_bufs(char *buf)
        }
 }
 
-void write_batch_argvs_file(int orig_argc, int argc, char **argv)
+void write_batch_argvs_file(int argc, char *argv[])
 {
        int fdb;
        int i;
@@ -149,23 +154,27 @@ void write_batch_argvs_file(int orig_argc, int argc, char **argv)
        buff[0] = '\0';
        /* Write argvs info to batch file */
 
-       for (i = argc - orig_argc; i < argc; i++) {
-               /* FIXME: This apparently crashes if rsync is run with
-                * just "rsync -F".  I think directly manipulating
-                * argv[] is probably bogus -- what if -F is part of a
-                * run of several short options? */
-               if (!strcmp(argv[i], "-F")) {   /* safer to change it here than script */
-                       strncat(buff, "-f ", 3);        /* chg to -f + ext to get ready for remote */
-                       strncat(buff, batch_file_ext,
-                               strlen(batch_file_ext));
+       for (i = 0; i < argc; ++i) {
+               if (i == argc - 2)
+                   continue;
+               /*
+                * FIXME:
+                * I think directly manipulating argv[] is probably bogus
+                */
+               if (!strcmp(argv[i], "--write-batch")) {
+                       /* Safer to change it here than script */
+                       /* Change to --read-batch + ext * to get ready for remote */
+                       strlcat(buff, "--read-batch ", sizeof(buff));
+                       strlcat(buff, batch_file_ext, sizeof(buff));
                } else {
-                       strncat(buff, argv[i], strlen(argv[i]));
+                       strlcat(buff, argv[i], sizeof(buff));
                }
 
                if (i < (argc - 1)) {
-                       strncat(buff, " ", 1);
+                       strlcat(buff, " ", sizeof(buff));
                }
        }
+       strlcat(buff, "\n", sizeof(buff));
        if (!write(fdb, buff, strlen(buff))) {
                rprintf(FERROR, "Batch file %s write error: %s\n",
                        rsync_argvs_file, strerror(errno));
@@ -291,7 +300,7 @@ void read_batch_flist_info(struct file_struct **fptr)
        read_batch_flist_file((char *) &file->mode, sizeof(mode_t));
        read_batch_flist_file((char *) &file->inode, sizeof(INO64_T));
        read_batch_flist_file((char *) &file->dev, sizeof(DEV64_T));
-       read_batch_flist_file((char *) &file->rdev, sizeof(dev_t));
+       read_batch_flist_file((char *) &file->rdev, sizeof(DEV64_T));
        read_batch_flist_file((char *) &file->uid, sizeof(uid_t));
        read_batch_flist_file((char *) &file->gid, sizeof(gid_t));
        read_batch_flist_file(char_str_len, sizeof(char_str_len));
diff --git a/main.c b/main.c
index 37ab2fb..fd30211 100644 (file)
--- a/main.c
+++ b/main.c
@@ -803,8 +803,10 @@ int main(int argc,char *argv[])
        extern int write_batch;  /*  dw */
        extern char *batch_ext;   /*  dw */
        int orig_argc;  /* dw */
+       char **orig_argv;
 
        orig_argc = argc;   /* dw */
+       orig_argv = argv;
 
        signal(SIGUSR1, sigusr1_handler);
        signal(SIGUSR2, sigusr2_handler);
@@ -844,7 +846,7 @@ int main(int argc,char *argv[])
 
        if (write_batch) { /* dw */
            create_batch_file_ext();
-           write_batch_argvs_file(orig_argc, argc, argv);
+           write_batch_argvs_file(orig_argc, orig_argv);
        }
 
        if (read_batch) { /* dw */
index 66c2d0c..922965a 100644 (file)
--- a/options.c
+++ b/options.c
@@ -240,8 +240,8 @@ void usage(enum logcode F)
   rprintf(F,"     --log-format=FORMAT     log file transfers using specified format\n");  
   rprintf(F,"     --password-file=FILE    get password from FILE\n");
   rprintf(F,"     --bwlimit=KBPS          limit I/O bandwidth, KBytes per second\n");
-  rprintf(F," -f  --read-batch=EXT        read batch file\n");
-  rprintf(F," -F  --write-batch           write batch file\n");
+  rprintf(F,"     --read-batch=EXT        read batch file\n");
+  rprintf(F,"     --write-batch           write batch file\n");
   rprintf(F," -h, --help                  show this help screen\n");
 #ifdef INET6
   rprintf(F," -4                          prefer IPv4\n");
@@ -262,7 +262,7 @@ enum {OPT_VERSION = 1000, OPT_SUFFIX, OPT_SENDER, OPT_SERVER, OPT_EXCLUDE,
       OPT_LOG_FORMAT, OPT_PASSWORD_FILE, OPT_SIZE_ONLY, OPT_ADDRESS,
       OPT_DELETE_AFTER, OPT_EXISTING, OPT_MAX_DELETE, OPT_BACKUP_DIR, 
       OPT_IGNORE_ERRORS, OPT_BWLIMIT, OPT_BLOCKING_IO,
-      OPT_MODIFY_WINDOW};
+      OPT_MODIFY_WINDOW, OPT_READ_BATCH, OPT_WRITE_BATCH};
 
 static struct poptOption long_options[] = {
   /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
@@ -331,8 +331,8 @@ static struct poptOption long_options[] = {
   {"address",          0,  POPT_ARG_STRING, &bind_address, 0},
   {"backup-dir",       0,  POPT_ARG_STRING, &backup_dir},
   {"hard-links",      'H', POPT_ARG_NONE,   &preserve_hard_links},
-  {"read-batch",      'f', POPT_ARG_STRING, &batch_ext, 'f'},
-  {"write-batch",     'F', POPT_ARG_NONE,   &write_batch, 0},
+  {"read-batch",       0,  POPT_ARG_STRING, &batch_ext, OPT_READ_BATCH},
+  {"write-batch",      0,  POPT_ARG_NONE,   &write_batch},
 #ifdef INET6
   {0,                '4', POPT_ARG_VAL,    &default_af_hint,   AF_INET },
   {0,                '6', POPT_ARG_VAL,    &default_af_hint,   AF_INET6 },
@@ -511,9 +511,8 @@ int parse_arguments(int *argc, const char ***argv, int frommain)
                        keep_partial = 1;
                        break;
 
-
-               case 'f':
-                       /* The filename is stored for us by popt */
+               case OPT_READ_BATCH:
+                       /* The filename is stored in batch_ext for us by popt */
                        read_batch = 1;
                        break;
 
@@ -550,7 +549,8 @@ void server_options(char **args,int *argc)
        static char mdelete[30];
        static char mwindow[30];
        static char bw[50];
-       static char fext[20]; /* dw */
+       static char fext[20];
+       static char wbatch[14];
 
        int i, x;
 
@@ -605,8 +605,6 @@ void server_options(char **args,int *argc)
                argstr[x++] = 'S';
        if (do_compression)
                argstr[x++] = 'z';
-       if (write_batch)
-           argstr[x++] = 'F'; /* dw */
 
        /* this is a complete hack - blame Rusty 
 
@@ -629,8 +627,13 @@ void server_options(char **args,int *argc)
                args[ac++] = mdelete;
        }    
        
+       if (write_batch) {
+               snprintf(wbatch,sizeof(wbatch),"--write-batch");
+               args[ac++] = wbatch;
+       }
+
        if (batch_ext != NULL) {
-               sprintf(fext,"-f%s",batch_ext);
+               snprintf(fext,sizeof(fext),"--read-batch=%s",batch_ext);
                args[ac++] = fext;
        }
 
index c53aaaf..15eec7c 100644 (file)
--- a/rsync.yo
+++ b/rsync.yo
@@ -277,8 +277,8 @@ verb(
      --log-format=FORMAT     log file transfers using specified format
      --password-file=FILE    get password from FILE
      --bwlimit=KBPS          limit I/O bandwidth, KBytes per second
-f, --read-batch=FILE       read batch file
-F, --write-batch           write batch file
    --read-batch=FILE       read batch file
    --write-batch           write batch file
  -h, --help                  show this help screen
 
 
@@ -798,7 +798,7 @@ for synchronizing the contents of bf(target_dir) with the updates found in
 bf(src_dir)
 
 quote(
-$ rsync -F [other rsync options here] \nl()
+$ rsync --write-batch [other rsync options here] \nl()
            /somewhere/src_dir /somewhere/target_dir
 )
 
index ee34bc9..d9fc5e6 100644 (file)
--- a/sender.c
+++ b/sender.c
@@ -159,13 +159,14 @@ void send_files(struct file_list *flist,int f_out,int f_in)
                initial_stats = stats;
 
                s = receive_sums(f_in);
-               if (write_batch) /* dw */
-                   write_batch_csum_info(&i,flist->count,s);
                if (!s) {
                        io_error = 1;
                        rprintf(FERROR,"receive_sums failed\n");
                        return;
                }
+
+               if (write_batch)
+                   write_batch_csum_info(&i,flist->count,s);
          
                if (!read_batch) {
                        fd = do_open(fname, O_RDONLY, 0);
diff --git a/util.c b/util.c
index e6acf50..5554d00 100644 (file)
--- a/util.c
+++ b/util.c
@@ -173,10 +173,7 @@ pid_t local_child(int argc, char **argv,int *f_in,int *f_out)
                extern int am_sender;
                extern int am_server;
 
-               if (read_batch)
-                   am_sender = 0;
-               else
-                   am_sender = !am_sender;
+               am_sender = read_batch ? 0 : !am_sender;
                am_server = 1;          
 
                if (dup2(to_child_pipe[0], STDIN_FILENO) < 0 ||