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