make repeated --fuzzy option look into alt-dest dirs.
[rsync.git] / main.c
diff --git a/main.c b/main.c
index 17ba62d65e975784df52565b980439e7988912bb..93cd50d3938df666e004dfedc48af54bcb2d0060 100644 (file)
--- a/main.c
+++ b/main.c
@@ -76,6 +76,7 @@ extern size_t bwlimit_writemax;
 extern unsigned int module_dirlen;
 extern BOOL flist_receiving_enabled;
 extern BOOL shutting_down;
+extern int basis_dir_cnt;
 extern struct stats stats;
 extern char *stdout_format;
 extern char *logfile_format;
@@ -705,33 +706,35 @@ static char *get_local_name(struct file_list *flist, char *dest_path)
 static void check_alt_basis_dirs(void)
 {
        STRUCT_STAT st;
-       char **dir_p, *slash = strrchr(curr_dir, '/');
-
-       for (dir_p = basis_dir; *dir_p; dir_p++) {
-               if (dry_run > 1 && **dir_p != '/') {
-                       int len = curr_dir_len + 1 + strlen(*dir_p) + 1;
+       char *slash = strrchr(curr_dir, '/');
+       int j;
+
+       for (j = 0; j < basis_dir_cnt; j++) {
+               char *bdir = basis_dir[j];
+               int bd_len = strlen(bdir);
+               if (bd_len > 1 && bdir[bd_len-1] == '/')
+                       bdir[--bd_len] = '\0';
+               if (dry_run > 1 && *bdir != '/') {
+                       int len = curr_dir_len + 1 + bd_len + 1;
                        char *new = new_array(char, len);
                        if (!new)
                                out_of_memory("check_alt_basis_dirs");
-                       if (slash && strncmp(*dir_p, "../", 3) == 0) {
+                       if (slash && strncmp(bdir, "../", 3) == 0) {
                            /* We want to remove only one leading "../" prefix for
                             * the directory we couldn't create in dry-run mode:
                             * this ensures that any other ".." references get
                             * evaluated the same as they would for a live copy. */
                            *slash = '\0';
-                           pathjoin(new, len, curr_dir, *dir_p + 3);
+                           pathjoin(new, len, curr_dir, bdir + 3);
                            *slash = '/';
                        } else
-                           pathjoin(new, len, curr_dir, *dir_p);
-                       *dir_p = new;
-               }
-               if (do_stat(*dir_p, &st) < 0) {
-                       rprintf(FWARNING, "%s arg does not exist: %s\n",
-                               dest_option, *dir_p);
-               } else if (!S_ISDIR(st.st_mode)) {
-                       rprintf(FWARNING, "%s arg is not a dir: %s\n",
-                               dest_option, *dir_p);
+                           pathjoin(new, len, curr_dir, bdir);
+                       basis_dir[j] = bdir = new;
                }
+               if (do_stat(bdir, &st) < 0)
+                       rprintf(FWARNING, "%s arg does not exist: %s\n", dest_option, bdir);
+               else if (!S_ISDIR(st.st_mode))
+                       rprintf(FWARNING, "%s arg is not a dir: %s\n", dest_option, bdir);
        }
 }