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