+static void handle_delayed_updates(char *local_name)
+{
+ char *fname, *partialptr;
+ int ndx;
+
+ for (ndx = -1; (ndx = bitbag_next_bit(delayed_bits, ndx)) >= 0; ) {
+ struct file_struct *file = cur_flist->files[ndx];
+ fname = local_name ? local_name : f_name(file, NULL);
+ if ((partialptr = partial_dir_fname(fname)) != NULL) {
+ if (make_backups > 0 && !make_backup(fname, False))
+ continue;
+ if (DEBUG_GTE(RECV, 1)) {
+ rprintf(FINFO, "renaming %s to %s\n",
+ partialptr, fname);
+ }
+ /* We don't use robust_rename() here because the
+ * partial-dir must be on the same drive. */
+ if (do_rename(partialptr, fname) < 0) {
+ rsyserr(FERROR_XFER, errno,
+ "rename failed for %s (from %s)",
+ full_fname(fname), partialptr);
+ } else {
+ if (remove_source_files
+ || (preserve_hard_links && F_IS_HLINKED(file)))
+ send_msg_int(MSG_SUCCESS, ndx);
+ handle_partial_dir(partialptr, PDIR_DELETE);
+ }
+ }
+ }
+}
+
+static void no_batched_update(int ndx, BOOL is_redo)
+{
+ struct file_list *flist = flist_for_ndx(ndx, "no_batched_update");
+ struct file_struct *file = flist->files[ndx - flist->ndx_start];
+
+ rprintf(FERROR_XFER, "(No batched update for%s \"%s\")\n",
+ is_redo ? " resend of" : "", f_name(file, NULL));
+
+ if (inc_recurse)
+ send_msg_int(MSG_NO_SEND, ndx);
+}
+
+static int we_want_redo(int desired_ndx)
+{
+ static int redo_ndx = -1;
+
+ while (redo_ndx < desired_ndx) {
+ if (redo_ndx >= 0)
+ no_batched_update(redo_ndx, True);
+ if ((redo_ndx = flist_ndx_pop(&batch_redo_list)) < 0)
+ return 0;
+ }
+
+ if (redo_ndx == desired_ndx) {
+ redo_ndx = -1;
+ return 1;
+ }
+
+ return 0;
+}
+
+static int gen_wants_ndx(int desired_ndx, int flist_num)
+{
+ static int next_ndx = -1;
+ static int done_cnt = 0;
+ static BOOL got_eof = False;
+
+ if (got_eof)
+ return 0;
+
+ while (next_ndx < desired_ndx) {
+ if (inc_recurse && flist_num <= done_cnt)
+ return 0;
+ if (next_ndx >= 0)
+ no_batched_update(next_ndx, False);
+ if ((next_ndx = read_int(batch_gen_fd)) < 0) {
+ if (inc_recurse) {
+ done_cnt++;
+ continue;
+ }
+ got_eof = True;
+ return 0;
+ }
+ }
+
+ if (next_ndx == desired_ndx) {
+ next_ndx = -1;
+ return 1;
+ }
+
+ return 0;
+}