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