Prefer send_msg_int() over send_msg() for better debug output.
[rsync/rsync.git] / receiver.c
index 965bb39..e8fa3d1 100644 (file)
@@ -425,6 +425,9 @@ static int gen_wants_ndx(int desired_ndx, int flist_num)
        if (got_eof)
                return 0;
 
+       /* TODO: integrate gen-reading I/O into perform_io() so this is not needed? */
+       io_flush(FULL_FLUSH);
+
        while (next_ndx < desired_ndx) {
                if (inc_recurse && flist_num <= done_cnt)
                        return 0;
@@ -452,7 +455,7 @@ static int gen_wants_ndx(int desired_ndx, int flist_num)
  * main routine for receiver process.
  *
  * Receiver process runs on the same host as the generator process. */
-int recv_files(int f_in, char *local_name)
+int recv_files(int f_in, int f_out, char *local_name)
 {
        int fd1,fd2;
        STRUCT_STAT st;
@@ -464,7 +467,6 @@ int recv_files(int f_in, char *local_name)
        char fnamecmpbuf[MAXPATHLEN];
        uchar fnamecmp_type;
        struct file_struct *file;
-       struct stats initial_stats;
        int itemizing = am_server ? logfile_format_has_i : stdout_format_has_i;
        enum logcode log_code = log_before_transfer ? FLOG : FINFO;
        int max_phase = protocol_version >= 29 ? 2 : 1;
@@ -484,7 +486,7 @@ int recv_files(int f_in, char *local_name)
                cleanup_disable();
 
                /* This call also sets cur_flist. */
-               ndx = read_ndx_and_attrs(f_in, &iflags, &fnamecmp_type,
+               ndx = read_ndx_and_attrs(f_in, f_out, &iflags, &fnamecmp_type,
                                         xname, &xlen);
                if (ndx == NDX_DONE) {
                        if (!am_server && INFO_GTE(PROGRESS, 2) && cur_flist) {
@@ -509,7 +511,7 @@ int recv_files(int f_in, char *local_name)
                                rprintf(FINFO, "recv_files phase=%d\n", phase);
                        if (phase == 2 && delay_updates)
                                handle_delayed_updates(local_name);
-                       send_msg(MSG_DONE, "", 0, 0);
+                       write_int(f_out, NDX_DONE);
                        continue;
                }
 
@@ -609,14 +611,17 @@ int recv_files(int f_in, char *local_name)
                        }
                }
 
+               if (!log_before_transfer)
+                       remember_initial_stats();
+
                if (!do_xfers) { /* log the transfer */
-                       log_item(FCLIENT, file, &stats, iflags, NULL);
+                       log_item(FCLIENT, file, iflags, NULL);
                        if (read_batch)
                                discard_receive_data(f_in, F_LENGTH(file));
                        continue;
                }
                if (write_batch < 0) {
-                       log_item(FCLIENT, file, &stats, iflags, NULL);
+                       log_item(FCLIENT, file, iflags, NULL);
                        if (!am_server)
                                discard_receive_data(f_in, F_LENGTH(file));
                        continue;
@@ -674,8 +679,6 @@ int recv_files(int f_in, char *local_name)
                                fnamecmp = fname;
                }
 
-               initial_stats = stats;
-
                /* open the file */
                fd1 = do_open(fnamecmp, O_RDONLY, 0);
 
@@ -770,7 +773,7 @@ int recv_files(int f_in, char *local_name)
 
                /* log the transfer */
                if (log_before_transfer)
-                       log_item(FCLIENT, file, &initial_stats, iflags, NULL);
+                       log_item(FCLIENT, file, iflags, NULL);
                else if (!am_server && INFO_GTE(NAME, 1) && INFO_EQ(PROGRESS, 1))
                        rprintf(FINFO, "%s\n", fname);
 
@@ -778,7 +781,7 @@ int recv_files(int f_in, char *local_name)
                recv_ok = receive_data(f_in, fnamecmp, fd1, st.st_size,
                                       fname, fd2, F_LENGTH(file));
 
-               log_item(log_code, file, &initial_stats, iflags, NULL);
+               log_item(log_code, file, iflags, NULL);
 
                if (fd1 != -1)
                        close(fd1);