Changed a couple log_recv() calls back to log_send().
[rsync/rsync.git] / generator.c
index 188f51f..fe7f16b 100644 (file)
 
 extern int verbose;
 extern int dry_run;
+extern int log_format_has_i;
+extern int log_format_has_o_or_i;
+extern int daemon_log_format_has_i;
+extern int am_root;
+extern int am_server;
+extern int am_daemon;
 extern int relative_paths;
 extern int keep_dirlinks;
 extern int preserve_links;
-extern int am_root;
 extern int preserve_devices;
 extern int preserve_hard_links;
 extern int preserve_perms;
@@ -61,6 +66,7 @@ extern int only_existing;
 extern int orig_umask;
 extern int safe_symlinks;
 extern long block_size; /* "long" because popt can't set an int32. */
+extern struct stats stats;
 
 extern struct filter_list_struct server_filter_list;
 
@@ -92,28 +98,32 @@ static void itemize(struct file_struct *file, int statret, STRUCT_STAT *st,
        if (statret >= 0) {
                if (S_ISREG(file->mode) && file->length != st->st_size)
                        iflags |= ITEM_REPORT_SIZE;
+               if (!(sflags & SID_NO_DEST_AND_NO_UPDATE)) {
+                       int keep_time = !preserve_times ? 0
+                           : S_ISDIR(file->mode) ? !omit_dir_times
+                           : !S_ISLNK(file->mode);
+
+                       if ((iflags & ITEM_UPDATING && !keep_time)
+                           || (keep_time && file->modtime != st->st_mtime))
+                               iflags |= ITEM_REPORT_TIME;
+                       if (preserve_perms && file->mode != st->st_mode)
+                               iflags |= ITEM_REPORT_PERMS;
+                       if (preserve_uid && am_root && file->uid != st->st_uid)
+                               iflags |= ITEM_REPORT_OWNER;
+                       if (preserve_gid && file->gid != GID_NONE
+                           && st->st_gid != file->gid)
+                               iflags |= ITEM_REPORT_GROUP;
+               }
        } else
-               iflags |= ITEM_IS_NEW;
-       if (statret >= 0 && !(sflags & SID_NO_DEST_AND_NO_UPDATE)) {
-               int keep_time = !preserve_times ? 0
-                   : S_ISDIR(file->mode) ? !omit_dir_times : !S_ISLNK(file->mode);
-
-               if ((iflags & ITEM_UPDATING && !keep_time)
-                   || (keep_time && file->modtime != st->st_mtime))
-                       iflags |= ITEM_REPORT_TIME;
-               if (preserve_perms && file->mode != st->st_mode)
-                       iflags |= ITEM_REPORT_PERMS;
-               if (preserve_uid && am_root && file->uid != st->st_uid)
-                       iflags |= ITEM_REPORT_OWNER;
-               if (preserve_gid && file->gid != GID_NONE && st->st_gid != file->gid)
-                       iflags |= ITEM_REPORT_GROUP;
-       }
-
-       if (iflags && !read_batch) {
-               if (ndx >= 0)
-                       write_int(f_out, ndx);
-               write_byte(f_out, iflags);
-               write_byte(f_out, iflags >> 8);
+               iflags |= ITEM_IS_NEW | ITEM_UPDATING;
+
+       if ((iflags || verbose > 1) && !read_batch) {
+               if (protocol_version >= 29) {
+                       if (ndx >= 0)
+                               write_int(f_out, ndx);
+                       write_shortint(f_out, iflags);
+               } else if (ndx >= 0)
+                       log_recv(file, &stats, iflags);
        }
 }
 
@@ -344,11 +354,35 @@ static void recv_generator(char *fname, struct file_list *flist,
        int statret, stat_errno;
        char *fnamecmp, *partialptr, *backupptr = NULL;
        char fnamecmpbuf[MAXPATHLEN];
+       int itemizing, maybe_DEL_TERSE, maybe_PERMS_REPORT;
        uchar fnamecmp_type;
+       enum logcode code;
 
        if (list_only)
                return;
 
+       if (protocol_version >= 29) {
+               itemizing = 1;
+               code = daemon_log_format_has_i ? 0 : FLOG;
+               maybe_DEL_TERSE = log_format_has_o_or_i ? 0 : DEL_TERSE;
+               maybe_PERMS_REPORT = log_format_has_i ? 0 : PERMS_REPORT;
+       } else if (am_daemon) {
+               itemizing = daemon_log_format_has_i && !dry_run;
+               code = itemizing || dry_run ? FCLIENT : FINFO;
+               maybe_DEL_TERSE = DEL_TERSE;
+               maybe_PERMS_REPORT = PERMS_REPORT;
+       } else if (!am_server) {
+               itemizing = log_format_has_i;
+               code = itemizing ? 0 : FINFO;
+               maybe_DEL_TERSE = log_format_has_o_or_i ? 0 : DEL_TERSE;
+               maybe_PERMS_REPORT = log_format_has_i ? 0 : PERMS_REPORT;
+       } else {
+               itemizing = 0;
+               code = FINFO;
+               maybe_DEL_TERSE = DEL_TERSE;
+               maybe_PERMS_REPORT = PERMS_REPORT;
+       }
+
        if (!fname) {
                if (fuzzy_dirlist) {
                        flist_free(fuzzy_dirlist);
@@ -427,14 +461,14 @@ static void recv_generator(char *fname, struct file_list *flist,
                 * we need to delete it.  If it doesn't exist, then
                 * (perhaps recursively) create it. */
                if (statret == 0 && !S_ISDIR(st.st_mode)) {
-                       delete_file(fname, DEL_TERSE);
+                       delete_file(fname, st.st_mode, maybe_DEL_TERSE);
                        statret = -1;
                }
                if (dry_run && statret != 0 && missing_below < 0) {
                        missing_below = file->dir.depth;
                        dry_run++;
                }
-               if (protocol_version >= 29 && f_out != -1)
+               if (itemizing && f_out != -1)
                        itemize(file, statret, &st, 0, f_out, ndx);
                if (statret != 0 && do_mkdir(fname,file->mode) != 0 && errno != EEXIST) {
                        if (!relative_paths || errno != ENOENT
@@ -446,14 +480,14 @@ static void recv_generator(char *fname, struct file_list *flist,
                        }
                }
                if (set_perms(fname, file, statret ? NULL : &st, 0)
-                   && verbose && protocol_version < 29 && f_out != -1)
-                       rprintf(FINFO, "%s/\n", safe_fname(fname));
+                   && verbose && code && f_out != -1)
+                       rprintf(code, "%s/\n", safe_fname(fname));
                if (delete_during && f_out != -1 && csum_length != SUM_LENGTH
                    && (file->flags & FLAG_DEL_HERE))
                        delete_in_dir(flist, fname, file);
                return;
        }
-       
+
        if (max_size && file->length > max_size) {
                if (verbose > 1) {
                        rprintf(FINFO, "%s is over max-size\n",
@@ -474,40 +508,45 @@ static void recv_generator(char *fname, struct file_list *flist,
                        return;
                }
                if (statret == 0) {
-                       int dflag = S_ISDIR(st.st_mode) ? DEL_DIR : 0;
                        char lnk[MAXPATHLEN];
                        int len;
 
-                       if (!dflag
+                       if (!S_ISDIR(st.st_mode)
                            && (len = readlink(fname, lnk, MAXPATHLEN-1)) > 0) {
                                lnk[len] = 0;
                                /* A link already pointing to the
                                 * right place -- no further action
                                 * required. */
                                if (strcmp(lnk, file->u.link) == 0) {
-                                       if (protocol_version >= 29) {
+                                       if (itemizing) {
                                                itemize(file, 0, &st, 0,
                                                        f_out, ndx);
                                        }
                                        set_perms(fname, file, &st,
-                                                 PERMS_REPORT);
+                                                 maybe_PERMS_REPORT);
                                        return;
                                }
                        }
                        /* Not the right symlink (or not a symlink), so
                         * delete it. */
-                       delete_file(fname, dflag | DEL_TERSE);
+                       if (S_ISLNK(st.st_mode))
+                               delete_file(fname, st.st_mode, DEL_TERSE);
+                       else {
+                               delete_file(fname, st.st_mode, maybe_DEL_TERSE);
+                               statret = -1;
+                       }
                }
                if (do_symlink(file->u.link,fname) != 0) {
                        rsyserr(FERROR, errno, "symlink %s -> \"%s\" failed",
                                full_fname(fname), safe_fname(file->u.link));
                } else {
                        set_perms(fname,file,NULL,0);
-                       if (protocol_version >= 29) {
+                       if (itemizing) {
                                itemize(file, statret, &st, SID_UPDATING,
                                        f_out, ndx);
-                       } else if (verbose) {
-                               rprintf(FINFO, "%s -> %s\n", safe_fname(fname),
+                       }
+                       if (code && verbose) {
+                               rprintf(code, "%s -> %s\n", safe_fname(fname),
                                        safe_fname(file->u.link));
                        }
                }
@@ -519,12 +558,12 @@ static void recv_generator(char *fname, struct file_list *flist,
                if (statret != 0 ||
                    st.st_mode != file->mode ||
                    st.st_rdev != file->u.rdev) {
-                       int dflag = S_ISDIR(st.st_mode) ? DEL_DIR : 0;
-                       if (protocol_version >= 29) {
-                               itemize(file, statret, &st, SID_UPDATING,
-                                       f_out, ndx);
+                       if (IS_DEVICE(st.st_mode))
+                               delete_file(fname, st.st_mode, DEL_TERSE);
+                       else {
+                               delete_file(fname, st.st_mode, maybe_DEL_TERSE);
+                               statret = -1;
                        }
-                       delete_file(fname, dflag | DEL_TERSE);
                        if (verbose > 2) {
                                rprintf(FINFO,"mknod(%s,0%o,0x%x)\n",
                                        safe_fname(fname),
@@ -535,17 +574,21 @@ static void recv_generator(char *fname, struct file_list *flist,
                                        full_fname(fname));
                        } else {
                                set_perms(fname,file,NULL,0);
-                               if (verbose && protocol_version < 29) {
-                                       rprintf(FINFO, "%s\n",
+                               if (itemizing) {
+                                       itemize(file, statret, &st, SID_UPDATING,
+                                               f_out, ndx);
+                               }
+                               if (code && verbose) {
+                                       rprintf(code, "%s\n",
                                                safe_fname(fname));
                                }
                        }
                } else {
-                       if (protocol_version >= 29) {
+                       if (itemizing) {
                                itemize(file, statret, &st, 0,
                                        f_out, ndx);
                        }
-                       set_perms(fname, file, &st, PERMS_REPORT);
+                       set_perms(fname, file, &st, maybe_PERMS_REPORT);
                }
                return;
        }
@@ -618,8 +661,7 @@ static void recv_generator(char *fname, struct file_list *flist,
        }
 
        if (statret == 0 && !S_ISREG(st.st_mode)) {
-               int dflag = S_ISDIR(st.st_mode) ? DEL_DIR : 0;
-               if (delete_file(fname, dflag | DEL_TERSE) != 0)
+               if (delete_file(fname, st.st_mode, maybe_DEL_TERSE) != 0)
                        return;
                statret = -1;
                stat_errno = ENOENT;
@@ -682,14 +724,14 @@ static void recv_generator(char *fname, struct file_list *flist,
        else if (fnamecmp_type == FNAMECMP_FUZZY)
                ;
        else if (unchanged_file(fnamecmp, file, &st)) {
-               if (protocol_version >= 29) {
+               if (itemizing) {
                        itemize(file, statret, &st,
                                fnamecmp_type == FNAMECMP_FNAME
                                               ? 0 : SID_NO_DEST_AND_NO_UPDATE,
                                f_out, ndx);
                }
                if (fnamecmp_type == FNAMECMP_FNAME)
-                       set_perms(fname, file, &st, PERMS_REPORT);
+                       set_perms(fname, file, &st, maybe_PERMS_REPORT);
                return;
        }
 
@@ -766,7 +808,7 @@ prepare_to_open:
 
 notify_others:
        write_int(f_out, ndx);
-       if (protocol_version >= 29) {
+       if (itemizing) {
                itemize(file, statret, &st, SID_UPDATING
                        | (always_checksum ? SID_REPORT_CHECKSUM : 0),
                        f_out, -1);