+ int future_cnt, save_io_error = io_error;
+
+ if (flist_eof)
+ return;
+
+ /* Keep sending data until we have the requested number of
+ * files in the upcoming file-lists. */
+ if (cur_flist->next) {
+ flist = first_flist->prev; /* the newest flist */
+ future_cnt = flist->count + flist->ndx_start
+ - cur_flist->next->ndx_start;
+ } else
+ future_cnt = 0;
+ while (future_cnt < at_least) {
+ struct file_struct *file = dir_flist->sorted[send_dir_ndx];
+ int start = dir_flist->count;
+ int32 *dp;
+
+ flist = flist_new(0, "send_extra_file_list");
+ start_write = stats.total_written;
+
+ /* If this is the first of a set of duplicate dirs, we must
+ * send all the dirs together in a single file-list. We must
+ * also send the index of the last dir in the header. */
+ if (file->flags & FLAG_DUPLICATE) {
+ int dir_ndx, end_ndx = send_dir_ndx;
+ struct file_struct *fp = file;
+
+ while (1) {
+ dp = F_DIRNODE_P(fp);
+ end_ndx = DIR_NEXT_SIBLING(dp);
+ fp = dir_flist->sorted[end_ndx];
+ if (!(fp->flags & FLAG_DUPLICATE))
+ break;
+ }
+
+#ifdef ICONV_OPTION
+ if (ic_ndx)
+ dir_ndx = F_NDX(fp);
+ else
+#endif
+ dir_ndx = end_ndx;
+ write_ndx(f, NDX_FLIST_OFFSET - dir_ndx);
+
+ while (1) {
+ send1extra(f, file, flist);
+ if (send_dir_ndx == end_ndx)
+ break;
+ dp = F_DIRNODE_P(file);
+ send_dir_ndx = DIR_NEXT_SIBLING(dp);
+ file = dir_flist->sorted[send_dir_ndx];
+ }
+ } else {
+ int dir_ndx;
+#ifdef ICONV_OPTION
+ if (ic_ndx)
+ dir_ndx = F_NDX(file);
+ else
+#endif
+ dir_ndx = send_dir_ndx;
+ write_ndx(f, NDX_FLIST_OFFSET - dir_ndx);
+
+ send1extra(f, file, flist);
+ }
+ write_byte(f, 0);
+
+#ifdef ICONV_OPTION
+ if (!need_unsorted_flist)
+#endif
+ dir_flist->sorted = dir_flist->files;
+ add_dirs_to_tree(send_dir_ndx, start, dir_flist->count - 1);
+
+#ifdef ICONV_OPTION
+ if (need_unsorted_flist) {
+ if (inc_recurse) {
+ if (!(flist->sorted = new_array(struct file_struct *, flist->count)))
+ out_of_memory("send_extra_file_list");
+ memcpy(flist->sorted, flist->files,
+ flist->count * sizeof (struct file_struct*));
+ clean_flist(flist, 0);
+ } else
+ flist->sorted = flist->files;
+ } else
+#endif
+ {
+ flist->sorted = flist->files;
+ clean_flist(flist, 0);
+ }