Clean generated files for distclean.
[rsync/rsync.git] / io.c
diff --git a/io.c b/io.c
index a19017a..afe837f 100644 (file)
--- a/io.c
+++ b/io.c
@@ -100,7 +100,7 @@ static char ff_lastchar;
 #ifdef ICONV_OPTION
 static xbuf iconv_buf = EMPTY_XBUF;
 #endif
-static int defer_forwarding_messages = 0;
+static int defer_forwarding_messages = 0, defer_forwarding_keep = 0;
 static int select_timeout = SELECT_TIMEOUT;
 static int active_filecnt = 0;
 static OFF_T active_bytecnt = 0;
@@ -181,7 +181,6 @@ static void got_flist_entry_status(enum festatus status, const char *buf)
        struct file_list *flist = flist_for_ndx(ndx);
 
        assert(flist != NULL);
-       assert(ndx >= flist->ndx_start);
 
        if (remove_source_files) {
                active_filecnt--;
@@ -197,8 +196,10 @@ static void got_flist_entry_status(enum festatus status, const char *buf)
                        send_msg(MSG_SUCCESS, buf, 4, 0);
                if (preserve_hard_links) {
                        struct file_struct *file = flist->files[ndx - flist->ndx_start];
-                       if (F_IS_HLINKED(file))
+                       if (F_IS_HLINKED(file)) {
                                flist_ndx_push(&hlink_list, ndx);
+                               flist->in_progress++;
+                       }
                }
                break;
        case FES_REDO:
@@ -439,7 +440,7 @@ static void read_msg_fd(void)
 
        no_flush--;
        msg_fd_in = fd;
-       if (!--defer_forwarding_messages)
+       if (!--defer_forwarding_messages && !no_flush)
                msg_flush();
 }
 
@@ -479,7 +480,9 @@ static void mplex_write(int fd, enum msgcode code, const char *buf, size_t len,
        else
                memcpy(buffer + 4, buf, n);
 
+       defer_forwarding_keep = 1; /* defer_forwarding_messages++ on return */
        writefd_unbuffered(fd, buffer, n+4);
+       defer_forwarding_keep = 0;
 
        len -= n;
        buf += n;
@@ -491,22 +494,18 @@ static void mplex_write(int fd, enum msgcode code, const char *buf, size_t len,
                INIT_CONST_XBUF(outbuf, buffer);
                INIT_XBUF(inbuf, (char*)buf, len, -1);
 
-               defer_forwarding_messages++;
                do {
                        iconvbufs(ic_send, &inbuf, &outbuf,
                                  ICB_INCLUDE_BAD | ICB_INCLUDE_INCOMPLETE);
                        writefd_unbuffered(fd, outbuf.buf, outbuf.len);
                } while (inbuf.len);
-               if (!--defer_forwarding_messages)
-                       msg_flush();
        } else
 #endif
-       if (len) {
-               defer_forwarding_messages++;
+       if (len)
                writefd_unbuffered(fd, buf, len);
-               if (!--defer_forwarding_messages)
-                       msg_flush();
-       }
+
+       if (!--defer_forwarding_messages && !no_flush)
+               msg_flush();
 }
 
 int send_msg(enum msgcode code, const char *buf, int len, int convert)
@@ -1511,7 +1510,8 @@ static void writefd_unbuffered(int fd, const char *buf, size_t len)
        }
 
        no_flush--;
-       if (!(defer_forwarding_messages -= defer_inc))
+       defer_inc -= defer_forwarding_keep;
+       if (!(defer_forwarding_messages -= defer_inc) && !no_flush)
                msg_flush();
 }
 
@@ -1861,6 +1861,8 @@ void start_write_batch(int fd)
         * actual communication so far depends on whether a daemon
         * is involved. */
        write_int(batch_fd, protocol_version);
+       if (protocol_version >= 30)
+               write_byte(batch_fd, inc_recurse);
        write_int(batch_fd, checksum_seed);
 
        if (am_sender)