+void check_for_finished_hlinks(int itemizing, enum logcode code)
+{
+ struct file_struct *file;
+ int ndx;
+
+ while ((ndx = get_hlink_num()) != -1) {
+ if (ndx < 0 || ndx >= the_file_list->count)
+ continue;
+
+ file = the_file_list->files[ndx];
+ if (!file->link_u.links)
+ continue;
+
+ hard_link_cluster(file, ndx, itemizing, code);
+ }
+}
+
+static int phase = 0;
+
+/* Acts on the_file_list->file's ndx'th item, whose name is fname. If a dir,
+ * make sure it exists, and has the right permissions/timestamp info. For
+ * all other non-regular files (symlinks, etc.) we create them here. For
+ * regular files that have changed, we try to find a basis file and then
+ * start sending checksums.
+ *
+ * Note that f_out is set to -1 when doing final directory-permission and
+ * modification-time repair. */
+static void recv_generator(char *fname, struct file_struct *file, int ndx,
+ int itemizing, int maybe_PERMS_REPORT,
+ enum logcode code, int f_out, int f_out_name)
+{
+ static int missing_below = -1, excluded_below = -1;
+ static char *fuzzy_dirname = NULL;
+ static struct file_list *fuzzy_dirlist = NULL;
+ struct file_struct *fuzzy_file = NULL;
+ int fd = -1, f_copy = -1;
+ STRUCT_STAT st, partial_st;
+ struct file_struct *back_file = NULL;
+ int statret, stat_errno;
+ char *fnamecmp, *partialptr, *backupptr = NULL;
+ char fnamecmpbuf[MAXPATHLEN];
+ uchar fnamecmp_type;
+
+ if (list_only)
+ return;
+
+ if (!fname) {
+ if (fuzzy_dirlist) {
+ flist_free(fuzzy_dirlist);
+ fuzzy_dirlist = NULL;
+ fuzzy_dirname = NULL;
+ }
+ if (missing_below >= 0) {
+ dry_run--;
+ missing_below = -1;
+ }
+ return;
+ }
+
+ if (verbose > 2) {
+ rprintf(FINFO, "recv_generator(%s,%d)\n",
+ safe_fname(fname), ndx);
+ }
+
+ if (server_filter_list.head) {
+ if (excluded_below >= 0) {
+ if (file->dir.depth > excluded_below)
+ goto skipping;
+ excluded_below = -1;
+ }
+ if (check_filter(&server_filter_list, fname,
+ S_ISDIR(file->mode)) < 0) {
+ if (S_ISDIR(file->mode))
+ excluded_below = file->dir.depth;
+ skipping:
+ if (verbose) {
+ rprintf(FINFO,
+ "skipping server-excluded file \"%s\"\n",
+ safe_fname(fname));
+ }
+ return;
+ }
+ }
+
+ if (missing_below >= 0 && file->dir.depth <= missing_below) {
+ dry_run--;
+ missing_below = -1;
+ }
+ if (dry_run > 1) {
+ statret = -1;
+ stat_errno = ENOENT;
+ } else {
+ if (fuzzy_basis && S_ISREG(file->mode)) {
+ char *dn = file->dirname ? file->dirname : ".";
+ /* Yes, identical dirnames are guaranteed to have
+ * identical pointers at this point. */
+ if (fuzzy_dirname != dn) {
+ if (fuzzy_dirlist)
+ flist_free(fuzzy_dirlist);
+ fuzzy_dirname = dn;
+ fuzzy_dirlist = get_dirlist(fuzzy_dirname, -1,
+ 1);
+ }
+ }
+
+ statret = link_stat(fname, &st,
+ keep_dirlinks && S_ISDIR(file->mode));
+ stat_errno = errno;
+ }
+
+ if (only_existing && statret == -1 && stat_errno == ENOENT) {
+ /* we only want to update existing files */
+ if (verbose > 1) {
+ rprintf(FINFO, "not creating new file \"%s\"\n",
+ safe_fname(fname));
+ }
+ return;
+ }
+
+ if (statret == 0 && !preserve_perms
+ && S_ISDIR(st.st_mode) == S_ISDIR(file->mode)) {
+ /* if the file exists already and we aren't perserving
+ * permissions then act as though the remote end sent
+ * us the file permissions we already have */
+ file->mode = (file->mode & ~CHMOD_BITS)
+ | (st.st_mode & CHMOD_BITS);
+ }