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