Change filter MATCHFLGs to FILTRULEs.
[rsync/rsync.git] / options.c
index e7c6c61..49af4b4 100644 (file)
--- a/options.c
+++ b/options.c
@@ -204,18 +204,18 @@ struct chmod_mode_struct *chmod_modes = NULL;
 static const char *debug_verbosity[] = {
        /*0*/ NULL,
        /*1*/ NULL,
-       /*2*/ "bind,cmd,connect,del,deltasum,dup,filter,flist,iconv",
-       /*3*/ "acl,backup,deltasum2,del2,exit,filter2,flist2,fuzzy,genr,own,recv,send,time",
-       /*4*/ "cmd2,deltasum3,del3,exit2,flist3,iconv2,own2,proto,time2",
-       /*5*/ "chdir,deltasum4,flist4,fuzzy2,hash,hlink",
+       /*2*/ "BIND,CMD,CONNECT,DEL,DELTASUM,DUP,FILTER,FLIST,ICONV",
+       /*3*/ "ACL,BACKUP,DELTASUM2,DEL2,EXIT,FILTER2,FLIST2,FUZZY,GENR,OWN,RECV,SEND,TIME",
+       /*4*/ "CMD2,DELTASUM3,DEL3,EXIT2,FLIST3,ICONV2,OWN2,PROTO,TIME2",
+       /*5*/ "CHDIR,DELTASUM4,FLIST4,FUZZY2,HASH,HLINK",
 };
 
 #define MAX_VERBOSITY ((int)(sizeof debug_verbosity / sizeof debug_verbosity[0]) - 1)
 
 static const char *info_verbosity[1+MAX_VERBOSITY] = {
        /*0*/ NULL,
-       /*1*/ "copy,del,flist,misc,name,stats,symsafe",
-       /*2*/ "backup,mount,name2,remove,skip",
+       /*1*/ "COPY,DEL,FLIST,MISC,NAME,STATS,SYMSAFE",
+       /*2*/ "BACKUP,MOUNT,NAME2,REMOVE,SKIP",
 };
 
 #define MAX_OUT_LEVEL 4 /* The largest N allowed for any flagN word. */
@@ -1409,7 +1409,7 @@ int parse_arguments(int *argc_p, const char ***argv_p)
 
                case OPT_INCLUDE:
                        parse_rule(&filter_list, poptGetOptArg(pc),
-                                  MATCHFLG_INCLUDE, XFLG_OLD_PREFIXES);
+                                  FILTRULE_INCLUDE, XFLG_OLD_PREFIXES);
                        break;
 
                case OPT_EXCLUDE_FROM:
@@ -1432,7 +1432,7 @@ int parse_arguments(int *argc_p, const char ***argv_p)
                                        goto options_rejected;
                        }
                        parse_filter_file(&filter_list, arg,
-                               opt == OPT_INCLUDE_FROM ? MATCHFLG_INCLUDE : 0,
+                               opt == OPT_INCLUDE_FROM ? FILTRULE_INCLUDE : 0,
                                XFLG_FATAL_ERRORS | XFLG_OLD_PREFIXES);
                        break;
 
@@ -1854,6 +1854,12 @@ int parse_arguments(int *argc_p, const char ***argv_p)
                        "--read-batch cannot be used with --files-from\n");
                return 0;
        }
+       if (read_batch && remove_source_files) {
+               snprintf(err_buf, sizeof err_buf,
+                       "--read-batch cannot be used with --remove-%s-files\n",
+                       remove_source_files == 1 ? "source" : "sent");
+               return 0;
+       }
        if (batch_name && strlen(batch_name) > MAX_BATCH_NAME_LEN) {
                snprintf(err_buf, sizeof err_buf,
                        "the batch-file name must be %d characters or less.\n",
@@ -1997,22 +2003,32 @@ int parse_arguments(int *argc_p, const char ***argv_p)
                return 0;
        }
        if (backup_dir) {
+               while (*backup_dir == '.' && backup_dir[1] == '/')
+                       backup_dir += 2;
+               if (*backup_dir == '.' && backup_dir[1] == '\0')
+                       backup_dir++;
                backup_dir_len = strlcpy(backup_dir_buf, backup_dir, sizeof backup_dir_buf);
                backup_dir_remainder = sizeof backup_dir_buf - backup_dir_len;
-               if (backup_dir_remainder < 32) {
+               if (backup_dir_remainder < 128) {
                        snprintf(err_buf, sizeof err_buf,
                                "the --backup-dir path is WAY too long.\n");
                        return 0;
                }
-               if (backup_dir_buf[backup_dir_len - 1] != '/') {
+               if (!backup_dir_len) {
+                       backup_dir_len = -1;
+                       backup_dir = NULL;
+               } else if (backup_dir_buf[backup_dir_len - 1] != '/') {
                        backup_dir_buf[backup_dir_len++] = '/';
                        backup_dir_buf[backup_dir_len] = '\0';
                }
-               if (INFO_GTE(BACKUP, 1) && !am_sender)
-                       rprintf(FINFO, "backup_dir is %s\n", backup_dir_buf);
+       }
+       if (backup_dir) {
+               /* No need for a suffix or a protect rule. */
        } else if (!backup_suffix_len && (!am_server || !am_sender)) {
                snprintf(err_buf, sizeof err_buf,
-                       "--suffix cannot be a null string without --backup-dir\n");
+                       "--suffix cannot be empty %s\n", backup_dir_len < 0
+                       ? "when --backup-dir is the same as the dest dir"
+                       : "without a --backup-dir");
                return 0;
        } else if (make_backups && delete_mode && !delete_excluded && !am_server) {
                snprintf(backup_dir_buf, sizeof backup_dir_buf,