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; |
5b56cc19 AT |
70 | #ifdef _WIN32 |
71 | int modify_window=2; | |
72 | #else | |
73 | int modify_window=0; | |
74 | #endif | |
c80ccabb | 75 | int blocking_io=0; |
7a6421fa AT |
76 | |
77 | char *backup_suffix = BACKUP_SUFFIX; | |
78 | char *tmpdir = NULL; | |
375a4556 | 79 | char *compare_dest = NULL; |
7a6421fa AT |
80 | char *config_file = RSYNCD_CONF; |
81 | char *shell_cmd = NULL; | |
b6062654 | 82 | char *log_format = NULL; |
65575e96 | 83 | char *password_file = NULL; |
7a6421fa | 84 | char *rsync_path = RSYNC_NAME; |
66203a98 | 85 | char *backup_dir = NULL; |
7a6421fa AT |
86 | int rsync_port = RSYNC_PORT; |
87 | ||
88 | int verbose = 0; | |
b86f0cef | 89 | int quiet = 0; |
7a6421fa | 90 | int always_checksum = 0; |
f7632fc6 | 91 | int list_only = 0; |
7a6421fa | 92 | |
5b56cc19 AT |
93 | static int modify_window_set; |
94 | ||
95 | ||
5c9730a4 AT |
96 | struct in_addr socket_address = {INADDR_ANY}; |
97 | ||
0f3203c3 | 98 | void usage(enum logcode F) |
7a6421fa AT |
99 | { |
100 | rprintf(F,"rsync version %s Copyright Andrew Tridgell and Paul Mackerras\n\n", | |
101 | VERSION); | |
704f908e AT |
102 | |
103 | rprintf(F,"rsync is a file transfer program capable of efficient remote update\nvia a fast differencing algorithm.\n\n"); | |
104 | ||
9ef53907 | 105 | rprintf(F,"Usage: rsync [OPTION]... SRC [SRC]... [USER@]HOST:DEST\n"); |
704f908e | 106 | rprintf(F," or rsync [OPTION]... [USER@]HOST:SRC DEST\n"); |
9ef53907 | 107 | rprintf(F," or rsync [OPTION]... SRC [SRC]... DEST\n"); |
14d43f1f | 108 | rprintf(F," or rsync [OPTION]... [USER@]HOST::SRC [DEST]\n"); |
9ef53907 | 109 | rprintf(F," or rsync [OPTION]... SRC [SRC]... [USER@]HOST::DEST\n"); |
14d43f1f | 110 | rprintf(F," or rsync [OPTION]... rsync://[USER@]HOST[:PORT]/SRC [DEST]\n"); |
9ef53907 DD |
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"); | |
704f908e AT |
114 | rprintf(F,"\nOptions\n"); |
115 | rprintf(F," -v, --verbose increase verbosity\n"); | |
b86f0cef | 116 | rprintf(F," -q, --quiet decrease verbosity\n"); |
704f908e AT |
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"); | |
9ef53907 | 121 | rprintf(F," -b, --backup make backups (default %s suffix)\n",BACKUP_SUFFIX); |
e20c5e95 | 122 | rprintf(F," --backup-dir make backups into this directory\n"); |
9ef53907 | 123 | rprintf(F," --suffix=SUFFIX override backup suffix\n"); |
704f908e AT |
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"); | |
b5313607 | 127 | rprintf(F," --copy-unsafe-links copy links outside the source tree\n"); |
d853783f | 128 | rprintf(F," --safe-links ignore links outside the destination tree\n"); |
704f908e AT |
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"); | |
9ef53907 | 139 | rprintf(F," -B, --block-size=SIZE checksum blocking size (default %d)\n",BLOCK_SIZE); |
704f908e AT |
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"); | |
1347d512 | 143 | rprintf(F," --existing only update files that already exist\n"); |
704f908e | 144 | rprintf(F," --delete delete files that don't exist on the sending side\n"); |
b33b791e | 145 | rprintf(F," --delete-excluded also delete excluded files on the receiving side\n"); |
57df171b | 146 | rprintf(F," --delete-after delete after transferring, not before\n"); |
ef55c686 | 147 | rprintf(F," --ignore-errors delete even if there are IO errors\n"); |
0b73ca12 | 148 | rprintf(F," --max-delete=NUM don't delete more than NUM files\n"); |
c95da96a | 149 | rprintf(F," --partial keep partially transferred files\n"); |
704f908e AT |
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"); | |
f83f0548 | 154 | rprintf(F," --size-only only use file size when determining if a file should be transferred\n"); |
5b56cc19 | 155 | rprintf(F," --modify-window=NUM Timestamp window (seconds) for file match (default=%d)\n",modify_window); |
704f908e | 156 | rprintf(F," -T --temp-dir=DIR create temporary files in directory DIR\n"); |
375a4556 | 157 | rprintf(F," --compare-dest=DIR also compare destination files relative to DIR\n"); |
d9fcc198 | 158 | rprintf(F," -P equivalent to --partial --progress\n"); |
704f908e | 159 | rprintf(F," -z, --compress compress file data\n"); |
2acf81eb | 160 | rprintf(F," --exclude=PATTERN exclude files matching PATTERN\n"); |
858fb9eb | 161 | rprintf(F," --exclude-from=FILE exclude patterns listed in FILE\n"); |
2acf81eb | 162 | rprintf(F," --include=PATTERN don't exclude files matching PATTERN\n"); |
858fb9eb | 163 | rprintf(F," --include-from=FILE don't exclude patterns listed in FILE\n"); |
704f908e AT |
164 | rprintf(F," --version print version number\n"); |
165 | rprintf(F," --daemon run as a rsync daemon\n"); | |
5c9730a4 | 166 | rprintf(F," --address bind to the specified address\n"); |
704f908e AT |
167 | rprintf(F," --config=FILE specify alternate rsyncd.conf file\n"); |
168 | rprintf(F," --port=PORT specify alternate rsyncd port number\n"); | |
c80ccabb | 169 | rprintf(F," --blocking-io use blocking IO for the remote shell\n"); |
704f908e | 170 | rprintf(F," --stats give some file transfer stats\n"); |
eb86d661 | 171 | rprintf(F," --progress show progress during transfer\n"); |
b6062654 | 172 | rprintf(F," --log-format=FORMAT log file transfers using specified format\n"); |
65575e96 | 173 | rprintf(F," --password-file=FILE get password from FILE\n"); |
ef5d23eb | 174 | rprintf(F," --bwlimit=KBPS limit I/O bandwidth, KBytes per second\n"); |
704f908e | 175 | rprintf(F," -h, --help show this help screen\n"); |
7a6421fa AT |
176 | |
177 | rprintf(F,"\n"); | |
b72f24c7 AT |
178 | |
179 | rprintf(F,"\nPlease see the rsync(1) and rsyncd.conf(5) man pages for full documentation\n"); | |
9e3c856a | 180 | rprintf(F,"See http://rsync.samba.org/ for updates and bug reports\n"); |
7a6421fa AT |
181 | } |
182 | ||
b33b791e DD |
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, | |
d853783f | 186 | OPT_INCLUDE, OPT_INCLUDE_FROM, OPT_STATS, OPT_PARTIAL, OPT_PROGRESS, |
b5313607 | 187 | OPT_COPY_UNSAFE_LINKS, OPT_SAFE_LINKS, OPT_COMPARE_DEST, |
57df171b | 188 | OPT_LOG_FORMAT, OPT_PASSWORD_FILE, OPT_SIZE_ONLY, OPT_ADDRESS, |
ef55c686 | 189 | OPT_DELETE_AFTER, OPT_EXISTING, OPT_MAX_DELETE, OPT_BACKUP_DIR, |
5b56cc19 AT |
190 | OPT_IGNORE_ERRORS, OPT_BWLIMIT, OPT_BLOCKING_IO, |
191 | OPT_MODIFY_WINDOW}; | |
7a6421fa | 192 | |
d9fcc198 | 193 | static char *short_options = "oblLWHpguDCtcahvqrRIxnSe:B:T:zP"; |
7a6421fa AT |
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}, | |
1347d512 | 199 | {"existing", 0, 0, OPT_EXISTING}, |
7a6421fa | 200 | {"delete", 0, 0, OPT_DELETE}, |
b33b791e | 201 | {"delete-excluded", 0, 0, OPT_DELETE_EXCLUDED}, |
7a6421fa AT |
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}, | |
2b6b4d53 AT |
206 | {"include", 1, 0, OPT_INCLUDE}, |
207 | {"include-from",1, 0, OPT_INCLUDE_FROM}, | |
7a6421fa | 208 | {"rsync-path", 1, 0, OPT_RSYNC_PATH}, |
65575e96 | 209 | {"password-file", 1, 0, OPT_PASSWORD_FILE}, |
7a6421fa AT |
210 | {"one-file-system",0, 0, 'x'}, |
211 | {"ignore-times",0, 0, 'I'}, | |
f83f0548 | 212 | {"size-only", 0, 0, OPT_SIZE_ONLY}, |
5b56cc19 | 213 | {"modify-window",1, 0, OPT_MODIFY_WINDOW}, |
7a6421fa AT |
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'}, | |
b86f0cef | 223 | {"quiet", 0, 0, 'q'}, |
7a6421fa AT |
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'}, | |
b5313607 | 230 | {"copy-unsafe-links", 0, 0, OPT_COPY_UNSAFE_LINKS}, |
d853783f | 231 | {"safe-links", 0, 0, OPT_SAFE_LINKS}, |
7a6421fa AT |
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'}, | |
375a4556 | 242 | {"compare-dest", 1, 0, OPT_COMPARE_DEST}, |
7a6421fa AT |
243 | {"compress", 0, 0, 'z'}, |
244 | {"daemon", 0, 0, OPT_DAEMON}, | |
a800434a | 245 | {"stats", 0, 0, OPT_STATS}, |
eb86d661 | 246 | {"progress", 0, 0, OPT_PROGRESS}, |
c95da96a | 247 | {"partial", 0, 0, OPT_PARTIAL}, |
57df171b | 248 | {"delete-after",0, 0, OPT_DELETE_AFTER}, |
ef55c686 | 249 | {"ignore-errors",0, 0, OPT_IGNORE_ERRORS}, |
c80ccabb | 250 | {"blocking-io" ,0, 0, OPT_BLOCKING_IO}, |
7a6421fa AT |
251 | {"config", 1, 0, OPT_CONFIG}, |
252 | {"port", 1, 0, OPT_PORT}, | |
b6062654 | 253 | {"log-format", 1, 0, OPT_LOG_FORMAT}, |
ef5d23eb | 254 | {"bwlimit", 1, 0, OPT_BWLIMIT}, |
5c9730a4 | 255 | {"address", 1, 0, OPT_ADDRESS}, |
0b73ca12 | 256 | {"max-delete", 1, 0, OPT_MAX_DELETE}, |
66203a98 | 257 | {"backup-dir", 1, 0, OPT_BACKUP_DIR}, |
7a6421fa AT |
258 | {0,0,0,0}}; |
259 | ||
b11ed3b1 | 260 | |
cd8185f2 AT |
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))) { | |
055af776 AT |
292 | if ((p==ref || p[-1]==' ') && |
293 | (p[len] == ' ' || p[len] == 0)) { | |
cd8185f2 AT |
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 | ||
b86f0cef | 304 | int parse_arguments(int argc, char *argv[], int frommain) |
7a6421fa | 305 | { |
d853783f AT |
306 | int opt; |
307 | int option_index; | |
cd8185f2 | 308 | char *ref = lp_refuse_options(module_id); |
d853783f AT |
309 | |
310 | while ((opt = getopt_long(argc, argv, | |
311 | short_options, long_options, &option_index)) | |
312 | != -1) { | |
cd8185f2 AT |
313 | |
314 | if (ref) { | |
315 | if (check_refuse_options(ref, opt)) return 0; | |
316 | } | |
317 | ||
d853783f AT |
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; | |
65575e96 AT |
332 | |
333 | case OPT_PASSWORD_FILE: | |
334 | password_file =optarg; | |
335 | break; | |
f83f0548 | 336 | |
d853783f AT |
337 | case 'I': |
338 | ignore_times = 1; | |
339 | break; | |
340 | ||
f83f0548 AT |
341 | case OPT_SIZE_ONLY: |
342 | size_only = 1; | |
343 | break; | |
344 | ||
5b56cc19 AT |
345 | case OPT_MODIFY_WINDOW: |
346 | modify_window = atoi(optarg); | |
347 | modify_window_set = 1; | |
348 | break; | |
349 | ||
d853783f AT |
350 | case 'x': |
351 | one_file_system=1; | |
352 | break; | |
353 | ||
354 | case OPT_DELETE: | |
355 | delete_mode = 1; | |
356 | break; | |
357 | ||
1347d512 AT |
358 | case OPT_EXISTING: |
359 | only_existing = 1; | |
360 | break; | |
361 | ||
57df171b AT |
362 | case OPT_DELETE_AFTER: |
363 | delete_after = 1; | |
364 | break; | |
365 | ||
b33b791e DD |
366 | case OPT_DELETE_EXCLUDED: |
367 | delete_excluded = 1; | |
368 | delete_mode = 1; | |
369 | break; | |
370 | ||
d853783f AT |
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 | ||
b5313607 DD |
395 | case OPT_COPY_UNSAFE_LINKS: |
396 | copy_unsafe_links=1; | |
397 | break; | |
398 | ||
d853783f AT |
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': | |
7a6421fa | 440 | #if SUPPORT_HARD_LINKS |
d853783f | 441 | preserve_hard_links=1; |
7a6421fa | 442 | #else |
cd8185f2 | 443 | slprintf(err_buf,sizeof(err_buf),"hard links are not supported on this server\n"); |
d853783f | 444 | rprintf(FERROR,"ERROR: hard links not supported on this platform\n"); |
b11ed3b1 | 445 | return 0; |
7a6421fa | 446 | #endif |
d853783f | 447 | break; |
7a6421fa | 448 | |
d853783f AT |
449 | case 'p': |
450 | preserve_perms=1; | |
451 | break; | |
7a6421fa | 452 | |
d853783f AT |
453 | case 'o': |
454 | preserve_uid=1; | |
455 | break; | |
7a6421fa | 456 | |
d853783f AT |
457 | case 'g': |
458 | preserve_gid=1; | |
459 | break; | |
7a6421fa | 460 | |
d853783f AT |
461 | case 'D': |
462 | preserve_devices=1; | |
463 | break; | |
7a6421fa | 464 | |
d853783f AT |
465 | case 't': |
466 | preserve_times=1; | |
467 | break; | |
7a6421fa | 468 | |
d853783f AT |
469 | case 'c': |
470 | always_checksum=1; | |
471 | break; | |
7a6421fa | 472 | |
d853783f AT |
473 | case 'v': |
474 | verbose++; | |
475 | break; | |
7a6421fa | 476 | |
b86f0cef DD |
477 | case 'q': |
478 | if (frommain) quiet++; | |
479 | break; | |
480 | ||
d853783f AT |
481 | case 'a': |
482 | recurse=1; | |
7a6421fa | 483 | #if SUPPORT_LINKS |
d853783f | 484 | preserve_links=1; |
7a6421fa | 485 | #endif |
d853783f AT |
486 | preserve_perms=1; |
487 | preserve_times=1; | |
488 | preserve_gid=1; | |
e20c5e95 AT |
489 | preserve_uid=1; |
490 | preserve_devices=1; | |
d853783f AT |
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); | |
65417579 | 500 | exit_cleanup(RERR_SYNTAX); |
d853783f AT |
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 | ||
0b73ca12 AT |
521 | case OPT_MAX_DELETE: |
522 | max_delete = atoi(optarg); | |
523 | break; | |
524 | ||
d853783f AT |
525 | case OPT_TIMEOUT: |
526 | io_timeout = atoi(optarg); | |
527 | break; | |
528 | ||
529 | case 'T': | |
530 | tmpdir = optarg; | |
531 | break; | |
532 | ||
375a4556 DD |
533 | case OPT_COMPARE_DEST: |
534 | compare_dest = optarg; | |
535 | break; | |
536 | ||
d853783f AT |
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 | ||
ef55c686 AT |
557 | case OPT_IGNORE_ERRORS: |
558 | ignore_errors = 1; | |
559 | break; | |
560 | ||
c80ccabb AT |
561 | case OPT_BLOCKING_IO: |
562 | blocking_io = 1; | |
563 | break; | |
564 | ||
d9fcc198 AT |
565 | case 'P': |
566 | do_progress = 1; | |
567 | keep_partial = 1; | |
568 | break; | |
569 | ||
d853783f AT |
570 | case OPT_CONFIG: |
571 | config_file = optarg; | |
572 | break; | |
573 | ||
574 | case OPT_PORT: | |
575 | rsync_port = atoi(optarg); | |
576 | break; | |
577 | ||
b6062654 AT |
578 | case OPT_LOG_FORMAT: |
579 | log_format = optarg; | |
580 | break; | |
ef5d23eb DD |
581 | |
582 | case OPT_BWLIMIT: | |
583 | bwlimit = atoi(optarg); | |
584 | break; | |
b6062654 | 585 | |
5c9730a4 AT |
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 | ||
66203a98 AT |
595 | case OPT_BACKUP_DIR: |
596 | backup_dir = optarg; | |
597 | break; | |
598 | ||
d853783f | 599 | default: |
cd8185f2 | 600 | slprintf(err_buf,sizeof(err_buf),"unrecognised option\n"); |
b11ed3b1 | 601 | return 0; |
d853783f | 602 | } |
7a6421fa | 603 | } |
b11ed3b1 | 604 | return 1; |
7a6421fa AT |
605 | } |
606 | ||
607 | ||
66203a98 AT |
608 | /* need to pass all the valid options from the client to the server */ |
609 | ||
7a6421fa AT |
610 | void server_options(char **args,int *argc) |
611 | { | |
d853783f AT |
612 | int ac = *argc; |
613 | static char argstr[50]; | |
614 | static char bsize[30]; | |
615 | static char iotime[30]; | |
0b73ca12 | 616 | static char mdelete[30]; |
5b56cc19 | 617 | static char mwindow[30]; |
ef5d23eb DD |
618 | static char bw[50]; |
619 | ||
d853783f AT |
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'; | |
f0b36a48 | 631 | |
b86f0cef | 632 | /* the -q option is intentionally left out */ |
d853783f AT |
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'; | |
f0b36a48 AT |
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 | ||
d853783f AT |
681 | argstr[x] = 0; |
682 | ||
683 | if (x != 1) args[ac++] = argstr; | |
684 | ||
685 | if (block_size != BLOCK_SIZE) { | |
0b73ca12 | 686 | slprintf(bsize,sizeof(bsize),"-B%d",block_size); |
d853783f AT |
687 | args[ac++] = bsize; |
688 | } | |
689 | ||
0b73ca12 AT |
690 | if (max_delete && am_sender) { |
691 | slprintf(mdelete,sizeof(mdelete),"--max-delete=%d",max_delete); | |
692 | args[ac++] = mdelete; | |
693 | } | |
694 | ||
d853783f | 695 | if (io_timeout) { |
0b73ca12 | 696 | slprintf(iotime,sizeof(iotime),"--timeout=%d",io_timeout); |
d853783f AT |
697 | args[ac++] = iotime; |
698 | } | |
699 | ||
ef5d23eb DD |
700 | if (bwlimit) { |
701 | slprintf(bw,sizeof(bw),"--bwlimit=%d",bwlimit); | |
702 | args[ac++] = bw; | |
703 | } | |
704 | ||
d853783f AT |
705 | if (strcmp(backup_suffix, BACKUP_SUFFIX)) { |
706 | args[ac++] = "--suffix"; | |
707 | args[ac++] = backup_suffix; | |
708 | } | |
709 | ||
b33b791e | 710 | if (delete_mode && !delete_excluded) |
d853783f AT |
711 | args[ac++] = "--delete"; |
712 | ||
b33b791e DD |
713 | if (delete_excluded) |
714 | args[ac++] = "--delete-excluded"; | |
715 | ||
f83f0548 AT |
716 | if (size_only) |
717 | args[ac++] = "--size-only"; | |
718 | ||
5b56cc19 AT |
719 | if (modify_window_set) { |
720 | slprintf(mwindow,sizeof(mwindow),"--modify-window=%d", | |
721 | modify_window); | |
722 | args[ac++] = mwindow; | |
723 | } | |
724 | ||
d853783f AT |
725 | if (keep_partial) |
726 | args[ac++] = "--partial"; | |
727 | ||
728 | if (force_delete) | |
729 | args[ac++] = "--force"; | |
730 | ||
57df171b AT |
731 | if (delete_after) |
732 | args[ac++] = "--delete-after"; | |
733 | ||
ef55c686 AT |
734 | if (ignore_errors) |
735 | args[ac++] = "--ignore-errors"; | |
736 | ||
b5313607 DD |
737 | if (copy_unsafe_links) |
738 | args[ac++] = "--copy-unsafe-links"; | |
739 | ||
d853783f AT |
740 | if (safe_symlinks) |
741 | args[ac++] = "--safe-links"; | |
742 | ||
743 | if (numeric_ids) | |
744 | args[ac++] = "--numeric-ids"; | |
745 | ||
0b73ca12 | 746 | if (only_existing && am_sender) |
1347d512 AT |
747 | args[ac++] = "--existing"; |
748 | ||
d853783f AT |
749 | if (tmpdir) { |
750 | args[ac++] = "--temp-dir"; | |
751 | args[ac++] = tmpdir; | |
752 | } | |
753 | ||
66203a98 AT |
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 | ||
375a4556 DD |
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 | ||
d853783f | 772 | *argc = ac; |
7a6421fa AT |
773 | } |
774 |