X-Git-Url: https://mattmccutchen.net/rsync/rsync.git/blobdiff_plain/ea5164d18118edc0d980795bfa760e5384c8d286..daa598df119f67e96739a1bfcdf5d6ea75efee78:/options.c diff --git a/options.c b/options.c index 772a87fa..52fc8c75 100644 --- a/options.c +++ b/options.c @@ -21,6 +21,8 @@ #include "rsync.h" #include "popt.h" +extern struct exclude_struct **exclude_list; + int make_backups = 0; /** @@ -77,7 +79,7 @@ int do_progress=0; int keep_partial=0; int safe_symlinks=0; int copy_unsafe_links=0; -int block_size=BLOCK_SIZE; +int block_size=0; int size_only=0; int bwlimit=0; int delete_after=0; @@ -103,9 +105,10 @@ int no_detach = 0; int write_batch = 0; int read_batch = 0; -int suffix_specified = 0; +int backup_dir_len = 0; +int backup_suffix_len; -char *backup_suffix = BACKUP_SUFFIX; +char *backup_suffix = NULL; char *tmpdir = NULL; char *compare_dest = NULL; char *config_file = NULL; @@ -254,6 +257,7 @@ void usage(enum logcode F) rprintf(F," --modify-window=NUM Timestamp window (seconds) for file match (default=%d)\n",modify_window); rprintf(F," -T --temp-dir=DIR create temporary files in directory DIR\n"); rprintf(F," --compare-dest=DIR also compare destination files relative to DIR\n"); + rprintf(F," --link-dest=DIR create hardlinks to DIR for unchanged files\n"); rprintf(F," -P equivalent to --partial --progress\n"); rprintf(F," -z, --compress compress file data\n"); rprintf(F," -C, --cvs-exclude auto ignore files in the same way CVS does\n"); @@ -290,20 +294,15 @@ void usage(enum logcode F) rprintf(F,"See http://rsync.samba.org/ for updates, bug reports, and answers\n"); } -enum {OPT_VERSION = 1000, OPT_SUFFIX, OPT_SENDER, OPT_SERVER, OPT_EXCLUDE, - OPT_EXCLUDE_FROM, OPT_DELETE, OPT_DELETE_EXCLUDED, OPT_NUMERIC_IDS, - OPT_RSYNC_PATH, OPT_FORCE, OPT_TIMEOUT, OPT_DAEMON, OPT_CONFIG, OPT_PORT, - OPT_INCLUDE, OPT_INCLUDE_FROM, OPT_STATS, OPT_PARTIAL, OPT_PROGRESS, - OPT_COPY_UNSAFE_LINKS, OPT_SAFE_LINKS, OPT_COMPARE_DEST, OPT_LINK_DEST, - OPT_LOG_FORMAT, OPT_PASSWORD_FILE, OPT_SIZE_ONLY, OPT_ADDRESS, - OPT_DELETE_AFTER, OPT_EXISTING, OPT_MAX_DELETE, OPT_BACKUP_DIR, - OPT_IGNORE_ERRORS, OPT_BWLIMIT, - OPT_MODIFY_WINDOW, OPT_READ_BATCH, OPT_WRITE_BATCH, OPT_IGNORE_EXISTING}; +enum {OPT_VERSION = 1000, OPT_SENDER, OPT_EXCLUDE, OPT_EXCLUDE_FROM, + OPT_DELETE_AFTER, OPT_DELETE_EXCLUDED, OPT_LINK_DEST, + OPT_INCLUDE, OPT_INCLUDE_FROM, OPT_MODIFY_WINDOW, + OPT_READ_BATCH, OPT_WRITE_BATCH}; static struct poptOption long_options[] = { /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */ {"version", 0, POPT_ARG_NONE, 0, OPT_VERSION, 0, 0}, - {"suffix", 0, POPT_ARG_STRING, &backup_suffix, OPT_SUFFIX, 0, 0 }, + {"suffix", 0, POPT_ARG_STRING, &backup_suffix, 0, 0, 0 }, {"rsync-path", 0, POPT_ARG_STRING, &rsync_path, 0, 0, 0 }, {"password-file", 0, POPT_ARG_STRING, &password_file, 0, 0, 0 }, {"ignore-times", 'I', POPT_ARG_NONE, &ignore_times, 0, 0, 0 }, @@ -482,13 +481,6 @@ int parse_arguments(int *argc, const char ***argv, int frommain) print_rsync_version(FINFO); exit_cleanup(0); - case OPT_SUFFIX: - /* The value has already been set by popt, but - * we need to remember that a suffix was specified - * in case a backup-directory is used. */ - suffix_specified = 1; - break; - case OPT_MODIFY_WINDOW: /* The value has already been set by popt, but * we need to remember that we're using a @@ -507,19 +499,23 @@ int parse_arguments(int *argc, const char ***argv, int frommain) break; case OPT_EXCLUDE: - add_exclude(poptGetOptArg(pc), 0); + add_exclude(&exclude_list, poptGetOptArg(pc), + ADD_EXCLUDE); break; case OPT_INCLUDE: - add_exclude(poptGetOptArg(pc), 1); + add_exclude(&exclude_list, poptGetOptArg(pc), + ADD_INCLUDE); break; case OPT_EXCLUDE_FROM: - add_exclude_file(poptGetOptArg(pc), 1, 0); + add_exclude_file(&exclude_list, poptGetOptArg(pc), + MISSING_FATAL, ADD_EXCLUDE); break; case OPT_INCLUDE_FROM: - add_exclude_file(poptGetOptArg(pc), 1, 1); + add_exclude_file(&exclude_list, poptGetOptArg(pc), + MISSING_FATAL, ADD_INCLUDE); break; case 'h': @@ -536,10 +532,10 @@ int parse_arguments(int *argc, const char ***argv, int frommain) * rprintf? Everybody who gets this message * ought to send it to the client and also to * the logs. */ - snprintf(err_buf,sizeof(err_buf), + snprintf(err_buf, sizeof err_buf, "hard links are not supported on this %s\n", am_server ? "server" : "client"); - rprintf(FERROR,"ERROR: hard links not supported on this platform\n"); + rprintf(FERROR, "ERROR: %s", err_buf); return 0; #endif /* SUPPORT_HARD_LINKS */ break; @@ -581,10 +577,10 @@ int parse_arguments(int *argc, const char ***argv, int frommain) link_dest = 1; break; #else - snprintf(err_buf,sizeof(err_buf), + snprintf(err_buf, sizeof err_buf, "hard links are not supported on this %s\n", am_server ? "server" : "client"); - rprintf(FERROR,"ERROR: hard links not supported on this platform\n"); + rprintf(FERROR, "ERROR: %s", err_buf); return 0; #endif @@ -602,19 +598,15 @@ int parse_arguments(int *argc, const char ***argv, int frommain) } if (write_batch && read_batch) { - snprintf(err_buf,sizeof(err_buf), - "write-batch and read-batch can not be used together\n"); - rprintf(FERROR,"ERROR: write-batch and read-batch" - " can not be used together\n"); - return 0; + rprintf(FERROR, + "write-batch and read-batch can not be used together\n"); + exit_cleanup(RERR_SYNTAX); } if (do_compression && (write_batch || read_batch)) { - snprintf(err_buf,sizeof(err_buf), - "compress can not be used with write-batch or read-batch\n"); - rprintf(FERROR,"ERROR: compress can not be used with" - " write-batch or read-batch\n"); - return 0; + rprintf(FERROR, + "compress can not be used with write-batch or read-batch\n"); + exit_cleanup(RERR_SYNTAX); } if (archive_mode) { @@ -633,6 +625,25 @@ int parse_arguments(int *argc, const char ***argv, int frommain) if (relative_paths < 0) relative_paths = files_from? 1 : 0; + if (!backup_suffix) + backup_suffix = backup_dir? "" : BACKUP_SUFFIX; + backup_suffix_len = strlen(backup_suffix); + if (strchr(backup_suffix, '/') != NULL) { + rprintf(FERROR, "--suffix cannot contain slashes: %s\n", + backup_suffix); + exit_cleanup(RERR_SYNTAX); + } + if (backup_dir) + backup_dir_len = strlen(backup_dir); + else if (!backup_suffix_len) { + rprintf(FERROR, + "--suffix cannot be a null string without --backup-dir\n"); + exit_cleanup(RERR_SYNTAX); + } + + if (do_progress && !verbose) + verbose = 1; + *argv = poptGetArgs(pc); if (*argv) *argc = count_args(*argv); @@ -775,7 +786,7 @@ void server_options(char **args,int *argc) if (x != 1) args[ac++] = argstr; - if (block_size != BLOCK_SIZE) { + if (block_size) { snprintf(bsize,sizeof(bsize),"-B%d",block_size); args[ac++] = bsize; } @@ -806,9 +817,19 @@ void server_options(char **args,int *argc) args[ac++] = bw; } - if (strcmp(backup_suffix, BACKUP_SUFFIX)) { - args[ac++] = "--suffix"; - args[ac++] = backup_suffix; + if (backup_dir) { + args[ac++] = "--backup-dir"; + args[ac++] = backup_dir; + } + + /* Only send --suffix if it specifies a non-default value. */ + if (strcmp(backup_suffix, backup_dir? "" : BACKUP_SUFFIX) != 0) { + char *s = malloc(9+backup_suffix_len+1); + if (!s) + out_of_memory("server_options"); + /* We use the following syntax to avoid weirdness with '~'. */ + sprintf(s, "--suffix=%s", backup_suffix); + args[ac++] = s; } if (delete_mode && !delete_excluded) @@ -858,14 +879,6 @@ void server_options(char **args,int *argc) args[ac++] = tmpdir; } - if (backup_dir && am_sender) { - /* only the receiver needs this option, if we are the sender - * then we need to send it to the receiver. - */ - args[ac++] = "--backup-dir"; - args[ac++] = backup_dir; - } - if (compare_dest && am_sender) { /* the server only needs this option if it is not the sender, * and it may be an older version that doesn't know this @@ -908,5 +921,3 @@ char *find_colon(char *s) return p; } - -