Fixed hang when --hard-links was processing a large directory
[rsync/rsync.git] / generator.c
index 530c274..24435ea 100644 (file)
@@ -1957,7 +1957,7 @@ void check_for_finished_files(int itemizing, enum logcode code, int check_redo)
 
                if (delete_during == 2 || !dir_tweaking) {
                        /* Skip directory touch-up. */
-               } else if (first_flist->ndx_start != 0)
+               } else if (first_flist->parent_ndx >= 0)
                        touch_up_dirs(dir_flist, first_flist->parent_ndx);
 
                flist_free(first_flist); /* updates first_flist */
@@ -2027,12 +2027,18 @@ void generate_files(int f_out, const char *local_name)
        do {
 #ifdef SUPPORT_HARD_LINKS
                if (preserve_hard_links && inc_recurse) {
-                       while (!flist_eof && file_total < FILECNT_LOOKAHEAD/2)
+                       while (!flist_eof) {
+                               int cnt = first_flist->prev
+                                       ? first_flist->prev->ndx_end - first_flist->ndx_start + 1
+                                       : first_flist->ndx_end - first_flist->ndx_start + 1;
+                               if (cnt >= FILECNT_LOOKAHEAD/2)
+                                       break;
                                wait_for_receiver();
+                       }
                }
 #endif
 
-               if (inc_recurse && cur_flist->ndx_start) {
+               if (inc_recurse && cur_flist->parent_ndx >= 0) {
                        struct file_struct *fp = dir_flist->files[cur_flist->parent_ndx];
                        f_name(fp, fbuf);
                        ndx = cur_flist->ndx_start - 1;