Fix --whole-file problem that caused it to be the default even for
[rsync/rsync.git] / options.c
index 98673cc..0f21634 100644 (file)
--- a/options.c
+++ b/options.c
 #include "popt.h"
 
 int make_backups = 0;
+
+/**
+ * Should we send the whole file as literal data rather than trying to
+ * create an incremental diff?  This is on by default when both source
+ * and destination are local and we're not doing a batch delta,
+ * because there it's no cheaper to read the whole basis file than to
+ * just rewrite it.
+ *
+ * -1 means "unspecified", i.e. depend on is_local; 0 means off; 1 means on.
+ **/
 int whole_file = -1;
+
 int copy_links = 0;
 int preserve_links = 0;
 int preserve_hard_links = 0;
@@ -87,9 +98,8 @@ int default_af_hint = AF_INET;        /* Must use IPv4 */
  * or under Unix process-monitors. **/
 int no_detach = 0;
 
-
-int read_batch=0;
-int write_batch=0;
+int write_batch = 0;
+int read_batch = 0;
 
 char *backup_suffix = BACKUP_SUFFIX;
 char *tmpdir = NULL;
@@ -107,7 +117,7 @@ int quiet = 0;
 int always_checksum = 0;
 int list_only = 0;
 
-char *batch_ext = NULL;
+char *batch_prefix = NULL;
 
 static int modify_window_set;
 
@@ -244,8 +254,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,"     --read-batch=EXT        read batch file\n");
-  rprintf(F,"     --write-batch           write batch file\n");
+  rprintf(F,"     --write-batch=PREFIX    write batch fileset starting with PREFIX\n");
+  rprintf(F,"     --read-batch=PREFIX     read batch fileset starting with PREFIX\n");
   rprintf(F," -h, --help                  show this help screen\n");
 #ifdef INET6
   rprintf(F," -4                          prefer IPv4\n");
@@ -339,8 +349,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",       0,  POPT_ARG_STRING, &batch_ext, OPT_READ_BATCH},
-  {"write-batch",      0,  POPT_ARG_NONE,   &write_batch},
+  {"read-batch",       0,  POPT_ARG_STRING, &batch_prefix, OPT_READ_BATCH},
+  {"write-batch",      0,  POPT_ARG_STRING, &batch_prefix, OPT_WRITE_BATCH},
 #ifdef INET6
   {0,                '4', POPT_ARG_VAL,    &default_af_hint,   AF_INET },
   {0,                '6', POPT_ARG_VAL,    &default_af_hint,   AF_INET6 },
@@ -460,6 +470,10 @@ int parse_arguments(int *argc, const char ***argv, int frommain)
                        add_exclude_file(poptGetOptArg(pc), 1, 0);
                        break;
 
+               case OPT_INCLUDE_FROM:
+                       add_exclude_file(poptGetOptArg(pc), 1, 1);
+                       break;
+
                case OPT_NO_WHOLE_FILE:
                        whole_file = 0;
                        break;
@@ -523,8 +537,13 @@ int parse_arguments(int *argc, const char ***argv, int frommain)
                        keep_partial = 1;
                        break;
 
+               case OPT_WRITE_BATCH:
+                       /* popt stores the filename in batch_prefix for us */
+                       write_batch = 1;
+                       break;
+
                case OPT_READ_BATCH:
-                       /* The filename is stored in batch_ext for us by popt */
+                       /* popt stores the filename in batch_prefix for us */
                        read_batch = 1;
                        break;
 
@@ -540,6 +559,22 @@ int parse_arguments(int *argc, const char ***argv, int frommain)
                }
        }
 
+       if (write_batch && read_batch) {
+           snprintf(err_buf,sizeof(err_buf),
+               "write-batch and read-batch can not be used together\n");
+           rprintf(FERROR,"ERROR: write-batch and read-batch"
+               " can not be used together\n");
+           return 0;
+       }
+
+       if (do_compression && (write_batch || read_batch)) {
+           snprintf(err_buf,sizeof(err_buf),
+               "compress can not be used with write-batch or read-batch\n");
+           rprintf(FERROR,"ERROR: compress can not be used with"
+               "  write-batch or read-batch\n");
+           return 0;
+       }
+
         *argv = poptGetArgs(pc);
         if (*argv)
                 *argc = count_args(*argv);
@@ -561,8 +596,8 @@ void server_options(char **args,int *argc)
        static char mdelete[30];
        static char mwindow[30];
        static char bw[50];
-       static char fext[20];
-       static char wbatch[14];
+       /* Leave room for ``--(write|read)-batch='' */
+       static char fext[MAXPATHLEN + 15];
 
        int i, x;
 
@@ -592,8 +627,13 @@ void server_options(char **args,int *argc)
                argstr[x++] = 'l';
        if (copy_links)
                argstr[x++] = 'L';
+
+       assert(whole_file == 0 || whole_file == -1);
        if (whole_file)
                argstr[x++] = 'W';
+       else 
+               args[ac++] = "--no-whole-file";
+       
        if (preserve_hard_links)
                argstr[x++] = 'H';
        if (preserve_uid)
@@ -644,13 +684,14 @@ 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) {
-               snprintf(fext,sizeof(fext),"--read-batch=%s",batch_ext);
+       if (batch_prefix != NULL) {
+               char *fmt = "";
+               if (write_batch)
+                   fmt = "--write-batch=%s";
+               else
+               if (read_batch)
+                   fmt = "--read-batch=%s";
+               snprintf(fext,sizeof(fext),fmt,batch_prefix);
                args[ac++] = fext;
        }
 
@@ -733,7 +774,6 @@ void server_options(char **args,int *argc)
                args[ac++] = compare_dest;
        }
 
-
        *argc = ac;
 }