Moved the delete-after support into generator.c.
[rsync/rsync.git] / log.c
diff --git a/log.c b/log.c
index b2c46a7..54c043f 100644 (file)
--- a/log.c
+++ b/log.c
@@ -27,6 +27,8 @@
   */
 #include "rsync.h"
 
+extern int verbose;
+extern int dry_run;
 extern int am_daemon;
 extern int am_server;
 extern int am_sender;
@@ -36,6 +38,7 @@ extern int msg_fd_out;
 extern int protocol_version;
 extern int preserve_times;
 extern int log_format_has_o_or_i;
+extern int daemon_log_format_has_o_or_i;
 extern char *auth_user;
 extern char *log_format;
 
@@ -88,28 +91,6 @@ static char const *rerr_name(int code)
        return NULL;
 }
 
-void log_open(void)
-{
-       if (logfname && !logfile) {
-               extern int orig_umask;
-               int old_umask = umask(022 | orig_umask);
-               logfile = fopen(logfname, "a");
-               umask(old_umask);
-               if (!logfile) {
-                       am_daemon = 0; /* avoid trying to log again */
-                       rsyserr(FERROR, errno, "fopen() of log-file failed");
-                       exit_cleanup(RERR_FILESELECT);
-               }
-       }
-}
-
-void log_close(void)
-{
-       if (logfile) {
-               fclose(logfile);
-               logfile = NULL;
-       }
-}
 
 static void logit(int priority, char *buf)
 {
@@ -164,6 +145,29 @@ void log_init(void)
 #endif
 }
 
+void log_open(void)
+{
+       if (logfname && !logfile) {
+               extern int orig_umask;
+               int old_umask = umask(022 | orig_umask);
+               logfile = fopen(logfname, "a");
+               umask(old_umask);
+               if (!logfile) {
+                       am_daemon = 0; /* avoid trying to log again */
+                       rsyserr(FERROR, errno, "fopen() of log-file failed");
+                       exit_cleanup(RERR_FILESELECT);
+               }
+       }
+}
+
+void log_close(void)
+{
+       if (logfile) {
+               fclose(logfile);
+               logfile = NULL;
+       }
+}
+
 /* this is the underlying (unformatted) rsync debugging function. Call
  * it with FINFO, FERROR or FLOG */
 void rwrite(enum logcode code, char *buf, int len)
@@ -185,7 +189,9 @@ void rwrite(enum logcode code, char *buf, int len)
                return;
        }
 
-       if (am_daemon) {
+       if (code == FCLIENT)
+               code = FINFO;
+       else if (am_daemon) {
                static int in_block;
                char msg[2048];
                int priority = code == FERROR ? LOG_WARNING : LOG_INFO;
@@ -524,26 +530,27 @@ void log_delete(char *fname, int mode)
 {
        static struct file_struct file;
        int len = strlen(fname);
-       enum logcode code;
        char *fmt;
 
        file.mode = mode;
        file.basename = fname;
 
-       if (am_server && protocol_version >= 29 && len < MAXPATHLEN) {
+       if (!verbose && !log_format)
+               ;
+       else if (am_server && protocol_version >= 29 && len < MAXPATHLEN) {
                if (S_ISDIR(mode))
                        len++; /* directories include trailing null */
                send_msg(MSG_DELETED, fname, len);
-               if (!am_daemon)
-                       return;
-               fmt = lp_log_format(module_id);
-               code = FLOG;
        } else {
                fmt = log_format_has_o_or_i ? log_format : "%i %n";
-               code = FINFO;
+               log_formatted(FCLIENT, fmt, "del.", &file, &stats, ITEM_DELETED);
        }
 
-       log_formatted(code, fmt, "del.", &file, &stats, ITEM_DELETED);
+       if (!am_daemon || dry_run || !lp_transfer_logging(module_id))
+               return;
+
+       fmt = daemon_log_format_has_o_or_i ? lp_log_format(module_id) : "%i %n";
+       log_formatted(FLOG, fmt, "del.", &file, &stats, ITEM_DELETED);
 }
 
 
@@ -556,7 +563,7 @@ void log_delete(char *fname, int mode)
 void log_exit(int code, const char *file, int line)
 {
        if (code == 0) {
-               rprintf(FLOG,"wrote %.0f bytes  read %.0f bytes  total size %.0f\n",
+               rprintf(FLOG,"sent %.0f bytes  received %.0f bytes  total size %.0f\n",
                        (double)stats.total_written,
                        (double)stats.total_read,
                        (double)stats.total_size);