Changed make_bak_dir() to take a const char *.
[rsync/rsync.git] / generator.c
index 45022ef..271b55f 100644 (file)
@@ -1072,6 +1072,35 @@ static int try_dests_non(struct file_struct *file, char *fname, int ndx,
        return j;
 }
 
+static void list_file_entry(struct file_struct *f)
+{
+       char permbuf[PERMSTRING_SIZE];
+       double len;
+
+       if (!F_IS_ACTIVE(f)) {
+               /* this can happen if duplicate names were removed */
+               return;
+       }
+
+       permstring(permbuf, f->mode);
+       len = F_LENGTH(f);
+
+       /* TODO: indicate '+' if the entry has an ACL. */
+
+#ifdef SUPPORT_LINKS
+       if (preserve_links && S_ISLNK(f->mode)) {
+               rprintf(FINFO, "%s %11.0f %s %s -> %s\n",
+                       permbuf, len, timestring(f->modtime),
+                       f_name(f, NULL), F_SYMLINK(f));
+       } else
+#endif
+       {
+               rprintf(FINFO, "%s %11.0f %s %s\n",
+                       permbuf, len, timestring(f->modtime),
+                       f_name(f, NULL));
+       }
+}
+
 static int phase = 0;
 static int dflt_perms;
 
@@ -1102,18 +1131,25 @@ static void recv_generator(char *fname, struct file_struct *file, int ndx,
        char *fnamecmp, *partialptr, *backupptr = NULL;
        char fnamecmpbuf[MAXPATHLEN];
        uchar fnamecmp_type;
+       int implied_dirs_are_missing = relative_paths && !implied_dirs && !inc_recurse;
        int del_opts = delete_mode || force_delete ? DEL_RECURSE : 0;
 
-       if (list_only)
-               return;
-
        if (verbose > 2)
                rprintf(FINFO, "recv_generator(%s,%d)\n", fname, ndx);
 
+       if (list_only) {
+               if (S_ISDIR(file->mode)
+                && ((!implied_dirs && !(file->flags & FLAG_XFER_DIR))
+                 || (inc_recurse && ndx != cur_flist->ndx_start - 1)))
+                       return;
+               list_file_entry(file);
+               return;
+       }
+
        if (server_filter_list.head) {
                if (excluded_below >= 0) {
                        if (F_DEPTH(file) > excluded_below
-                        && (implied_dirs || f_name_has_prefix(file, excluded_dir)))
+                        && (!implied_dirs_are_missing || f_name_has_prefix(file, excluded_dir)))
                                goto skipping;
                        excluded_below = -1;
                }
@@ -1135,7 +1171,7 @@ static void recv_generator(char *fname, struct file_struct *file, int ndx,
 
        if (missing_below >= 0) {
                if (F_DEPTH(file) <= missing_below
-                || (!implied_dirs && !f_name_has_prefix(file, missing_dir))) {
+                || (implied_dirs_are_missing && !f_name_has_prefix(file, missing_dir))) {
                        if (dry_run)
                                dry_run--;
                        missing_below = -1;
@@ -1212,8 +1248,9 @@ static void recv_generator(char *fname, struct file_struct *file, int ndx,
        }
 
        if (S_ISDIR(file->mode)) {
-               if (inc_recurse && ndx != cur_flist->ndx_start - 1
-                && file->flags & FLAG_XFER_DIR) {
+               if (!implied_dirs && !(file->flags & FLAG_XFER_DIR))
+                       goto cleanup;
+               if (inc_recurse && ndx != cur_flist->ndx_start - 1) {
                        /* In inc_recurse mode we want ot make sure any missing
                         * directories get created while we're still processing
                         * the parent dir (which allows us to touch the parent
@@ -1672,8 +1709,9 @@ static void recv_generator(char *fname, struct file_struct *file, int ndx,
                        close(fd);
                        goto cleanup;
                }
-               if ((f_copy = do_open(backupptr,
-                   O_WRONLY | O_CREAT | O_TRUNC | O_EXCL, 0600)) < 0) {
+               if ((f_copy = do_open(backupptr, O_WRONLY | O_CREAT | O_TRUNC | O_EXCL, 0600)) < 0
+                && (errno != ENOENT || make_bak_dir(backupptr) < 0
+                 || (f_copy = do_open(backupptr, O_WRONLY | O_CREAT | O_TRUNC | O_EXCL, 0600)) < 0)) {
                        rsyserr(FERROR, errno, "open %s",
                                full_fname(backupptr));
                        unmake_file(back_file);
@@ -1779,7 +1817,8 @@ static void touch_up_dirs(struct file_list *flist, int ndx)
         * transfer and/or re-set any tweaked modified-time values. */
        for (i = start; i <= end; i++, counter++) {
                file = flist->files[i];
-               if (!S_ISDIR(file->mode))
+               if (!S_ISDIR(file->mode)
+                || (relative_paths && !implied_dirs && !(file->flags & FLAG_XFER_DIR)))
                        continue;
                if (verbose > 3) {
                        fname = f_name(file, NULL);
@@ -1870,8 +1909,6 @@ void check_for_finished_files(int itemizing, enum logcode code, int check_redo)
                        /* Skip directory touch-up. */
                } else if (first_flist->ndx_start != 0)
                        touch_up_dirs(dir_flist, first_flist->parent_ndx);
-               else if (relative_paths && implied_dirs)
-                       touch_up_dirs(first_flist, -1);
 
                flist_free(first_flist); /* updates first_flist */
        }