Better error messages
[rsync/rsync.git] / options.c
1 /* 
2    Copyright (C) Andrew Tridgell 1998
3    
4    This program is free software; you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation; either version 2 of the License, or
7    (at your option) any later version.
8    
9    This program is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    GNU General Public License for more details.
13    
14    You should have received a copy of the GNU General Public License
15    along with this program; if not, write to the Free Software
16    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 */
18
19 /* options parsing code */
20
21 #include "rsync.h"
22
23
24 int make_backups = 0;
25 int whole_file = 0;
26 int copy_links = 0;
27 int preserve_links = 0;
28 int preserve_hard_links = 0;
29 int preserve_perms = 0;
30 int preserve_devices = 0;
31 int preserve_uid = 0;
32 int preserve_gid = 0;
33 int preserve_times = 0;
34 int update_only = 0;
35 int cvs_exclude = 0;
36 int dry_run=0;
37 int local_server=0;
38 int ignore_times=0;
39 int delete_mode=0;
40 int delete_excluded=0;
41 int one_file_system=0;
42 int remote_version=0;
43 int sparse_files=0;
44 int do_compression=0;
45 int am_root=0;
46 int orig_umask=0;
47 int relative_paths=0;
48 int numeric_ids = 0;
49 int force_delete = 0;
50 int io_timeout = 0;
51 int io_error = 0;
52 int read_only = 0;
53 int module_id = -1;
54 int am_server = 0;
55 int am_sender=0;
56 int recurse = 0;
57 int am_daemon=0;
58 int do_stats=0;
59 int do_progress=0;
60 int keep_partial=0;
61 int safe_symlinks=0;
62 int copy_unsafe_links=0;
63 int block_size=BLOCK_SIZE;
64 int size_only=0;
65 int bwlimit=0;
66 int delete_after=0;
67 int only_existing=0;
68 int max_delete=0;
69 int ignore_errors=0;
70 #ifdef _WIN32
71 int modify_window=2;
72 #else
73 int modify_window=0;
74 #endif
75 int blocking_io=0;
76
77 char *backup_suffix = BACKUP_SUFFIX;
78 char *tmpdir = NULL;
79 char *compare_dest = NULL;
80 char *config_file = RSYNCD_CONF;
81 char *shell_cmd = NULL;
82 char *log_format = NULL;
83 char *password_file = NULL;
84 char *rsync_path = RSYNC_NAME;
85 char *backup_dir = NULL;
86 int rsync_port = RSYNC_PORT;
87
88 int verbose = 0;
89 int quiet = 0;
90 int always_checksum = 0;
91 int list_only = 0;
92
93 static int modify_window_set;
94
95
96 struct in_addr socket_address = {INADDR_ANY};
97
98 void usage(enum logcode F)
99 {
100   rprintf(F,"rsync version %s Copyright Andrew Tridgell and Paul Mackerras\n\n",
101           VERSION);
102
103   rprintf(F,"rsync is a file transfer program capable of efficient remote update\nvia a fast differencing algorithm.\n\n");
104
105   rprintf(F,"Usage: rsync [OPTION]... SRC [SRC]... [USER@]HOST:DEST\n");
106   rprintf(F,"  or   rsync [OPTION]... [USER@]HOST:SRC DEST\n");
107   rprintf(F,"  or   rsync [OPTION]... SRC [SRC]... DEST\n");
108   rprintf(F,"  or   rsync [OPTION]... [USER@]HOST::SRC [DEST]\n");
109   rprintf(F,"  or   rsync [OPTION]... SRC [SRC]... [USER@]HOST::DEST\n");
110   rprintf(F,"  or   rsync [OPTION]... rsync://[USER@]HOST[:PORT]/SRC [DEST]\n");
111   rprintf(F,"SRC on single-colon remote HOST will be expanded by remote shell\n");
112   rprintf(F,"SRC on server remote HOST may contain shell wildcards or multiple\n");
113   rprintf(F,"  sources separated by space as long as they have same top-level\n");
114   rprintf(F,"\nOptions\n");
115   rprintf(F," -v, --verbose               increase verbosity\n");
116   rprintf(F," -q, --quiet                 decrease verbosity\n");
117   rprintf(F," -c, --checksum              always checksum\n");
118   rprintf(F," -a, --archive               archive mode\n");
119   rprintf(F," -r, --recursive             recurse into directories\n");
120   rprintf(F," -R, --relative              use relative path names\n");
121   rprintf(F," -b, --backup                make backups (default %s suffix)\n",BACKUP_SUFFIX);
122   rprintf(F,"     --backup-dir            make backups into this directory\n");
123   rprintf(F,"     --suffix=SUFFIX         override backup suffix\n");  
124   rprintf(F," -u, --update                update only (don't overwrite newer files)\n");
125   rprintf(F," -l, --links                 preserve soft links\n");
126   rprintf(F," -L, --copy-links            treat soft links like regular files\n");
127   rprintf(F,"     --copy-unsafe-links     copy links outside the source tree\n");
128   rprintf(F,"     --safe-links            ignore links outside the destination tree\n");
129   rprintf(F," -H, --hard-links            preserve hard links\n");
130   rprintf(F," -p, --perms                 preserve permissions\n");
131   rprintf(F," -o, --owner                 preserve owner (root only)\n");
132   rprintf(F," -g, --group                 preserve group\n");
133   rprintf(F," -D, --devices               preserve devices (root only)\n");
134   rprintf(F," -t, --times                 preserve times\n");  
135   rprintf(F," -S, --sparse                handle sparse files efficiently\n");
136   rprintf(F," -n, --dry-run               show what would have been transferred\n");
137   rprintf(F," -W, --whole-file            copy whole files, no incremental checks\n");
138   rprintf(F," -x, --one-file-system       don't cross filesystem boundaries\n");
139   rprintf(F," -B, --block-size=SIZE       checksum blocking size (default %d)\n",BLOCK_SIZE);  
140   rprintf(F," -e, --rsh=COMMAND           specify rsh replacement\n");
141   rprintf(F,"     --rsync-path=PATH       specify path to rsync on the remote machine\n");
142   rprintf(F," -C, --cvs-exclude           auto ignore files in the same way CVS does\n");
143   rprintf(F,"     --existing              only update files that already exist\n");
144   rprintf(F,"     --delete                delete files that don't exist on the sending side\n");
145   rprintf(F,"     --delete-excluded       also delete excluded files on the receiving side\n");
146   rprintf(F,"     --delete-after          delete after transferring, not before\n");
147   rprintf(F,"     --ignore-errors         delete even if there are IO errors\n");
148   rprintf(F,"     --max-delete=NUM        don't delete more than NUM files\n");
149   rprintf(F,"     --partial               keep partially transferred files\n");
150   rprintf(F,"     --force                 force deletion of directories even if not empty\n");
151   rprintf(F,"     --numeric-ids           don't map uid/gid values by user/group name\n");
152   rprintf(F,"     --timeout=TIME          set IO timeout in seconds\n");
153   rprintf(F," -I, --ignore-times          don't exclude files that match length and time\n");
154   rprintf(F,"     --size-only             only use file size when determining if a file should be transferred\n");
155   rprintf(F,"     --modify-window=NUM     Timestamp window (seconds) for file match (default=%d)\n",modify_window);
156   rprintf(F," -T  --temp-dir=DIR          create temporary files in directory DIR\n");
157   rprintf(F,"     --compare-dest=DIR      also compare destination files relative to DIR\n");
158   rprintf(F," -P                          equivalent to --partial --progress\n");
159   rprintf(F," -z, --compress              compress file data\n");
160   rprintf(F,"     --exclude=PATTERN       exclude files matching PATTERN\n");
161   rprintf(F,"     --exclude-from=FILE     exclude patterns listed in FILE\n");
162   rprintf(F,"     --include=PATTERN       don't exclude files matching PATTERN\n");
163   rprintf(F,"     --include-from=FILE     don't exclude patterns listed in FILE\n");
164   rprintf(F,"     --version               print version number\n");  
165   rprintf(F,"     --daemon                run as a rsync daemon\n");  
166   rprintf(F,"     --address               bind to the specified address\n");  
167   rprintf(F,"     --config=FILE           specify alternate rsyncd.conf file\n");  
168   rprintf(F,"     --port=PORT             specify alternate rsyncd port number\n");
169   rprintf(F,"     --blocking-io           use blocking IO for the remote shell\n");  
170   rprintf(F,"     --stats                 give some file transfer stats\n");  
171   rprintf(F,"     --progress              show progress during transfer\n");  
172   rprintf(F,"     --log-format=FORMAT     log file transfers using specified format\n");  
173   rprintf(F,"     --password-file=FILE    get password from FILE\n");
174   rprintf(F,"     --bwlimit=KBPS          limit I/O bandwidth, KBytes per second\n");
175   rprintf(F," -h, --help                  show this help screen\n");
176
177   rprintf(F,"\n");
178
179   rprintf(F,"\nPlease see the rsync(1) and rsyncd.conf(5) man pages for full documentation\n");
180   rprintf(F,"See http://rsync.samba.org/ for updates and bug reports\n");
181 }
182
183 enum {OPT_VERSION, OPT_SUFFIX, OPT_SENDER, OPT_SERVER, OPT_EXCLUDE,
184       OPT_EXCLUDE_FROM, OPT_DELETE, OPT_DELETE_EXCLUDED, OPT_NUMERIC_IDS,
185       OPT_RSYNC_PATH, OPT_FORCE, OPT_TIMEOUT, OPT_DAEMON, OPT_CONFIG, OPT_PORT,
186       OPT_INCLUDE, OPT_INCLUDE_FROM, OPT_STATS, OPT_PARTIAL, OPT_PROGRESS,
187       OPT_COPY_UNSAFE_LINKS, OPT_SAFE_LINKS, OPT_COMPARE_DEST,
188       OPT_LOG_FORMAT, OPT_PASSWORD_FILE, OPT_SIZE_ONLY, OPT_ADDRESS,
189       OPT_DELETE_AFTER, OPT_EXISTING, OPT_MAX_DELETE, OPT_BACKUP_DIR, 
190       OPT_IGNORE_ERRORS, OPT_BWLIMIT, OPT_BLOCKING_IO,
191       OPT_MODIFY_WINDOW};
192
193 static char *short_options = "oblLWHpguDCtcahvqrRIxnSe:B:T:zP";
194
195 static struct option long_options[] = {
196   {"version",     0,     0,    OPT_VERSION},
197   {"server",      0,     0,    OPT_SERVER},
198   {"sender",      0,     0,    OPT_SENDER},
199   {"existing",    0,     0,    OPT_EXISTING},
200   {"delete",      0,     0,    OPT_DELETE},
201   {"delete-excluded", 0, 0,    OPT_DELETE_EXCLUDED},
202   {"force",       0,     0,    OPT_FORCE},
203   {"numeric-ids", 0,     0,    OPT_NUMERIC_IDS},
204   {"exclude",     1,     0,    OPT_EXCLUDE},
205   {"exclude-from",1,     0,    OPT_EXCLUDE_FROM},
206   {"include",     1,     0,    OPT_INCLUDE},
207   {"include-from",1,     0,    OPT_INCLUDE_FROM},
208   {"rsync-path",  1,     0,    OPT_RSYNC_PATH},
209   {"password-file", 1,  0,     OPT_PASSWORD_FILE},
210   {"one-file-system",0,  0,    'x'},
211   {"ignore-times",0,     0,    'I'},
212   {"size-only",   0,     0,    OPT_SIZE_ONLY},
213   {"modify-window",1,    0,    OPT_MODIFY_WINDOW},
214   {"help",        0,     0,    'h'},
215   {"dry-run",     0,     0,    'n'},
216   {"sparse",      0,     0,    'S'},
217   {"cvs-exclude", 0,     0,    'C'},
218   {"archive",     0,     0,    'a'},
219   {"checksum",    0,     0,    'c'},
220   {"backup",      0,     0,    'b'},
221   {"update",      0,     0,    'u'},
222   {"verbose",     0,     0,    'v'},
223   {"quiet",       0,     0,    'q'},
224   {"recursive",   0,     0,    'r'},
225   {"relative",    0,     0,    'R'},
226   {"devices",     0,     0,    'D'},
227   {"perms",       0,     0,    'p'},
228   {"links",       0,     0,    'l'},
229   {"copy-links",  0,     0,    'L'},
230   {"copy-unsafe-links", 0, 0,  OPT_COPY_UNSAFE_LINKS},
231   {"safe-links",  0,     0,    OPT_SAFE_LINKS},
232   {"whole-file",  0,     0,    'W'},
233   {"hard-links",  0,     0,    'H'},
234   {"owner",       0,     0,    'o'},
235   {"group",       0,     0,    'g'},
236   {"times",       0,     0,    't'},
237   {"rsh",         1,     0,    'e'},
238   {"suffix",      1,     0,    OPT_SUFFIX},
239   {"block-size",  1,     0,    'B'},
240   {"timeout",     1,     0,    OPT_TIMEOUT},
241   {"temp-dir",    1,     0,    'T'},
242   {"compare-dest", 1,    0,    OPT_COMPARE_DEST},
243   {"compress",    0,     0,    'z'},
244   {"daemon",      0,     0,    OPT_DAEMON},
245   {"stats",       0,     0,    OPT_STATS},
246   {"progress",    0,     0,    OPT_PROGRESS},
247   {"partial",     0,     0,    OPT_PARTIAL},
248   {"delete-after",0,     0,    OPT_DELETE_AFTER},
249   {"ignore-errors",0,     0,   OPT_IGNORE_ERRORS},
250   {"blocking-io" ,0,     0,    OPT_BLOCKING_IO},
251   {"config",      1,     0,    OPT_CONFIG},
252   {"port",        1,     0,    OPT_PORT},
253   {"log-format",  1,     0,    OPT_LOG_FORMAT},
254   {"bwlimit",     1,     0,    OPT_BWLIMIT},
255   {"address",     1,     0,    OPT_ADDRESS},
256   {"max-delete",  1,     0,    OPT_MAX_DELETE},
257   {"backup-dir",  1,     0,    OPT_BACKUP_DIR},
258   {0,0,0,0}};
259
260
261 static char err_buf[100];
262
263 void option_error(void)
264 {
265         if (err_buf[0]) {
266                 rprintf(FLOG,"%s", err_buf);
267                 rprintf(FERROR,"%s", err_buf);
268         } else {
269                 rprintf(FLOG,"Error parsing options - unsupported option?\n");
270                 rprintf(FERROR,"Error parsing options - unsupported option?\n");
271         }
272         exit_cleanup(RERR_UNSUPPORTED);
273 }
274
275 /* check to see if we should refuse this option */
276 static int check_refuse_options(char *ref, int opt)
277 {
278         int i, len;
279         char *p;
280         const char *name;
281
282         for (i=0; long_options[i].name; i++) {
283                 if (long_options[i].val == opt) break;
284         }
285         
286         if (!long_options[i].name) return 0;
287
288         name = long_options[i].name;
289         len = strlen(name);
290
291         while ((p = strstr(ref,name))) {
292                 if ((p==ref || p[-1]==' ') &&
293                     (p[len] == ' ' || p[len] == 0)) {
294                         slprintf(err_buf,sizeof(err_buf),
295                                  "The '%s' option is not supported by this server\n", name);
296                         return 1;
297                 }
298                 ref += len;
299         }
300         return 0;
301 }
302
303
304 int parse_arguments(int argc, char *argv[], int frommain)
305 {
306         int opt;
307         int option_index;
308         char *ref = lp_refuse_options(module_id);
309
310         while ((opt = getopt_long(argc, argv, 
311                                   short_options, long_options, &option_index)) 
312                != -1) {
313
314                 if (ref) {
315                         if (check_refuse_options(ref, opt)) return 0;
316                 }
317
318                 switch (opt) {
319                 case OPT_VERSION:
320                         rprintf(FINFO,"rsync version %s  protocol version %d\n\n",
321                                 VERSION,PROTOCOL_VERSION);
322                         rprintf(FINFO,"Written by Andrew Tridgell and Paul Mackerras\n");
323                         exit_cleanup(0);
324                         
325                 case OPT_SUFFIX:
326                         backup_suffix = optarg;
327                         break;
328                         
329                 case OPT_RSYNC_PATH:
330                         rsync_path = optarg;
331                         break;
332         
333                 case OPT_PASSWORD_FILE:
334                         password_file =optarg;
335                         break;          
336
337                 case 'I':
338                         ignore_times = 1;
339                         break;
340
341                 case OPT_SIZE_ONLY:
342                         size_only = 1;
343                         break;
344
345                 case OPT_MODIFY_WINDOW:
346                         modify_window = atoi(optarg);
347                         modify_window_set = 1;
348                         break;
349                         
350                 case 'x':
351                         one_file_system=1;
352                         break;
353
354                 case OPT_DELETE:
355                         delete_mode = 1;
356                         break;
357
358                 case OPT_EXISTING:
359                         only_existing = 1;
360                         break;
361
362                 case OPT_DELETE_AFTER:
363                         delete_after = 1;
364                         break;
365
366                 case OPT_DELETE_EXCLUDED:
367                         delete_excluded = 1;
368                         delete_mode = 1;
369                         break;
370
371                 case OPT_FORCE:
372                         force_delete = 1;
373                         break;
374
375                 case OPT_NUMERIC_IDS:
376                         numeric_ids = 1;
377                         break;
378
379                 case OPT_EXCLUDE:
380                         add_exclude(optarg, 0);
381                         break;
382
383                 case OPT_INCLUDE:
384                         add_exclude(optarg, 1);
385                         break;
386
387                 case OPT_EXCLUDE_FROM:
388                         add_exclude_file(optarg,1, 0);
389                         break;
390
391                 case OPT_INCLUDE_FROM:
392                         add_exclude_file(optarg,1, 1);
393                         break;
394
395                 case OPT_COPY_UNSAFE_LINKS:
396                         copy_unsafe_links=1;
397                         break;
398
399                 case OPT_SAFE_LINKS:
400                         safe_symlinks=1;
401                         break;
402
403                 case 'h':
404                         usage(FINFO);
405                         exit_cleanup(0);
406
407                 case 'b':
408                         make_backups=1;
409                         break;
410
411                 case 'n':
412                         dry_run=1;
413                         break;
414
415                 case 'S':
416                         sparse_files=1;
417                         break;
418
419                 case 'C':
420                         cvs_exclude=1;
421                         break;
422
423                 case 'u':
424                         update_only=1;
425                         break;
426
427                 case 'l':
428                         preserve_links=1;
429                         break;
430
431                 case 'L':
432                         copy_links=1;
433                         break;
434
435                 case 'W':
436                         whole_file=1;
437                         break;
438
439                 case 'H':
440 #if SUPPORT_HARD_LINKS
441                         preserve_hard_links=1;
442 #else 
443                         slprintf(err_buf,sizeof(err_buf),"hard links are not supported on this server\n");
444                         rprintf(FERROR,"ERROR: hard links not supported on this platform\n");
445                         return 0;
446 #endif
447                         break;
448
449                 case 'p':
450                         preserve_perms=1;
451                         break;
452
453                 case 'o':
454                         preserve_uid=1;
455                         break;
456
457                 case 'g':
458                         preserve_gid=1;
459                         break;
460
461                 case 'D':
462                         preserve_devices=1;
463                         break;
464
465                 case 't':
466                         preserve_times=1;
467                         break;
468
469                 case 'c':
470                         always_checksum=1;
471                         break;
472
473                 case 'v':
474                         verbose++;
475                         break;
476
477                 case 'q':
478                         if (frommain) quiet++;
479                         break;
480
481                 case 'a':
482                         recurse=1;
483 #if SUPPORT_LINKS
484                         preserve_links=1;
485 #endif
486                         preserve_perms=1;
487                         preserve_times=1;
488                         preserve_gid=1;
489                         preserve_uid=1;
490                         preserve_devices=1;
491                         break;
492
493                 case OPT_SERVER:
494                         am_server = 1;
495                         break;
496
497                 case OPT_SENDER:
498                         if (!am_server) {
499                                 usage(FERROR);
500                                 exit_cleanup(RERR_SYNTAX);
501                         }
502                         am_sender = 1;
503                         break;
504
505                 case 'r':
506                         recurse = 1;
507                         break;
508
509                 case 'R':
510                         relative_paths = 1;
511                         break;
512
513                 case 'e':
514                         shell_cmd = optarg;
515                         break;
516
517                 case 'B':
518                         block_size = atoi(optarg);
519                         break;
520
521                 case OPT_MAX_DELETE:
522                         max_delete = atoi(optarg);
523                         break;
524
525                 case OPT_TIMEOUT:
526                         io_timeout = atoi(optarg);
527                         break;
528
529                 case 'T':
530                         tmpdir = optarg;
531                         break;
532
533                 case OPT_COMPARE_DEST:
534                         compare_dest = optarg;
535                         break;
536
537                 case 'z':
538                         do_compression = 1;
539                         break;
540
541                 case OPT_DAEMON:
542                         am_daemon = 1;
543                         break;
544
545                 case OPT_STATS:
546                         do_stats = 1;
547                         break;
548
549                 case OPT_PROGRESS:
550                         do_progress = 1;
551                         break;
552
553                 case OPT_PARTIAL:
554                         keep_partial = 1;
555                         break;
556
557                 case OPT_IGNORE_ERRORS:
558                         ignore_errors = 1;
559                         break;
560
561                 case OPT_BLOCKING_IO:
562                         blocking_io = 1;
563                         break;
564
565                 case 'P':
566                         do_progress = 1;
567                         keep_partial = 1;
568                         break;
569
570                 case OPT_CONFIG:
571                         config_file = optarg;
572                         break;
573
574                 case OPT_PORT:
575                         rsync_port = atoi(optarg);
576                         break;
577
578                 case OPT_LOG_FORMAT:
579                         log_format = optarg;
580                         break;
581         
582                 case OPT_BWLIMIT:
583                         bwlimit = atoi(optarg);
584                         break;
585
586                 case OPT_ADDRESS:
587                         {
588                                 struct in_addr *ia;
589                                 if ((ia = ip_address(optarg))) {
590                                         socket_address = *ia;
591                                 }
592                         }
593                         break;
594
595                 case OPT_BACKUP_DIR:
596                         backup_dir = optarg;
597                         break;
598
599                 default:
600                         slprintf(err_buf,sizeof(err_buf),"unrecognised option\n");
601                         return 0;
602                 }
603         }
604         return 1;
605 }
606
607
608 /* need to pass all the valid options from the client to the server */
609
610 void server_options(char **args,int *argc)
611 {
612         int ac = *argc;
613         static char argstr[50];
614         static char bsize[30];
615         static char iotime[30];
616         static char mdelete[30];
617         static char mwindow[30];
618         static char bw[50];
619
620         int i, x;
621
622         args[ac++] = "--server";
623
624         if (!am_sender)
625                 args[ac++] = "--sender";
626
627         x = 1;
628         argstr[0] = '-';
629         for (i=0;i<verbose;i++)
630                 argstr[x++] = 'v';
631
632         /* the -q option is intentionally left out */
633         if (make_backups)
634                 argstr[x++] = 'b';
635         if (update_only)
636                 argstr[x++] = 'u';
637         if (dry_run)
638                 argstr[x++] = 'n';
639         if (preserve_links)
640                 argstr[x++] = 'l';
641         if (copy_links)
642                 argstr[x++] = 'L';
643         if (whole_file)
644                 argstr[x++] = 'W';
645         if (preserve_hard_links)
646                 argstr[x++] = 'H';
647         if (preserve_uid)
648                 argstr[x++] = 'o';
649         if (preserve_gid)
650                 argstr[x++] = 'g';
651         if (preserve_devices)
652                 argstr[x++] = 'D';
653         if (preserve_times)
654                 argstr[x++] = 't';
655         if (preserve_perms)
656                 argstr[x++] = 'p';
657         if (recurse)
658                 argstr[x++] = 'r';
659         if (always_checksum)
660                 argstr[x++] = 'c';
661         if (cvs_exclude)
662                 argstr[x++] = 'C';
663         if (ignore_times)
664                 argstr[x++] = 'I';
665         if (relative_paths)
666                 argstr[x++] = 'R';
667         if (one_file_system)
668                 argstr[x++] = 'x';
669         if (sparse_files)
670                 argstr[x++] = 'S';
671         if (do_compression)
672                 argstr[x++] = 'z';
673
674         /* this is a complete hack - blame Rusty 
675
676            this is a hack to make the list_only (remote file list)
677            more useful */
678         if (list_only && !recurse) 
679                 argstr[x++] = 'r';
680
681         argstr[x] = 0;
682
683         if (x != 1) args[ac++] = argstr;
684
685         if (block_size != BLOCK_SIZE) {
686                 slprintf(bsize,sizeof(bsize),"-B%d",block_size);
687                 args[ac++] = bsize;
688         }    
689
690         if (max_delete && am_sender) {
691                 slprintf(mdelete,sizeof(mdelete),"--max-delete=%d",max_delete);
692                 args[ac++] = mdelete;
693         }    
694
695         if (io_timeout) {
696                 slprintf(iotime,sizeof(iotime),"--timeout=%d",io_timeout);
697                 args[ac++] = iotime;
698         }    
699
700         if (bwlimit) {
701                 slprintf(bw,sizeof(bw),"--bwlimit=%d",bwlimit);
702                 args[ac++] = bw;
703         }
704
705         if (strcmp(backup_suffix, BACKUP_SUFFIX)) {
706                 args[ac++] = "--suffix";
707                 args[ac++] = backup_suffix;
708         }
709
710         if (delete_mode && !delete_excluded)
711                 args[ac++] = "--delete";
712
713         if (delete_excluded)
714                 args[ac++] = "--delete-excluded";
715
716         if (size_only)
717                 args[ac++] = "--size-only";
718
719         if (modify_window_set) {
720                 slprintf(mwindow,sizeof(mwindow),"--modify-window=%d",
721                          modify_window);
722                 args[ac++] = mwindow;
723         }
724
725         if (keep_partial)
726                 args[ac++] = "--partial";
727
728         if (force_delete)
729                 args[ac++] = "--force";
730
731         if (delete_after)
732                 args[ac++] = "--delete-after";
733
734         if (ignore_errors)
735                 args[ac++] = "--ignore-errors";
736
737         if (copy_unsafe_links)
738                 args[ac++] = "--copy-unsafe-links";
739
740         if (safe_symlinks)
741                 args[ac++] = "--safe-links";
742
743         if (numeric_ids)
744                 args[ac++] = "--numeric-ids";
745
746         if (only_existing && am_sender)
747                 args[ac++] = "--existing";
748
749         if (tmpdir) {
750                 args[ac++] = "--temp-dir";
751                 args[ac++] = tmpdir;
752         }
753
754         if (backup_dir && am_sender) {
755                 /* only the receiver needs this option, if we are the sender
756                  *   then we need to send it to the receiver.
757                  */
758                 args[ac++] = "--backup-dir";
759                 args[ac++] = backup_dir;
760         }
761
762         if (compare_dest && am_sender) {
763                 /* the server only needs this option if it is not the sender,
764                  *   and it may be an older version that doesn't know this
765                  *   option, so don't send it if client is the sender.
766                  */
767                 args[ac++] = "--compare-dest";
768                 args[ac++] = compare_dest;
769         }
770
771
772         *argc = ac;
773 }
774