rem: if (partial_dir) { if ((partialptr = partial_dir_fname(fname)) != NULL) fnamecmp = partialptr; else
add: partialptr = partial_dir ? partial_dir_fname(fname) : fname;  if (f_in_name >= 0) { switch (read_byte(f_in_name)) { case FNAMECMP_FNAME:
context: int recv_files(int f_in, struct file_list *flist, char *local_name){	int next_gen_i = -1;	int fd1,fd2;	STRUCT_STAT st;	char *fname, fbuf[MAXPATHLEN];	char template[MAXPATHLEN];	char fnametmp[MAXPATHLEN];	char *fnamecmp, *partialptr;	char fnamecmpbuf[MAXPATHLEN];	struct file_struct *file;	struct stats initial_stats;	int save_make_backups = make_backups;	int i, recv_ok, phase = 0;	if (verbose > 2)		rprintf(FINFO,"recv_files(%d) starting\n",flist->count);	if (flist->hlink_pool) {		pool_destroy(flist->hlink_pool);		flist->hlink_pool = NULL;	}	while (1) {		cleanup_disable();		i = read_int(f_in);		if (i == -1) {			if (read_batch) {				if (next_gen_i != flist->count)					while (read_int(batch_gen_fd) != -1) {}				next_gen_i = -1;			}			if (phase)				break;			phase = 1;			csum_length = SUM_LENGTH;			if (verbose > 2)				rprintf(FINFO, "recv_files phase=%d\n", phase);			send_msg(MSG_DONE, "", 0);			if (keep_partial)				make_backups = 0; /* prevents double backup */			continue;		}		if (i < 0 || i >= flist->count) {			rprintf(FERROR,"Invalid file index %d in recv_files (count=%d)\n",				i, flist->count);			exit_cleanup(RERR_PROTOCOL);		}		file = flist->files[i];		stats.current_file_index = i;		stats.num_transferred_files++;		stats.total_transferred_size += file->length;		cleanup_got_literal = 0;		if (local_name)			fname = local_name;		else			fname = f_name_to(file, fbuf);		if (dry_run) {			if (!am_server && verbose) /* log the transfer */				rprintf(FINFO, "%s\n", safe_fname(fname));			continue;		}		initial_stats = stats;		if (verbose > 2)			rprintf(FINFO, "recv_files(%s)\n", safe_fname(fname));		if (read_batch) {			while (i > next_gen_i) {				next_gen_i = read_int(batch_gen_fd);				if (next_gen_i == -1)					next_gen_i = flist->count;			}			if (i < next_gen_i) {				rprintf(FINFO, "skipping update for \"%s\"\n",					safe_fname(fname));				discard_receive_data(f_in, file->length);				continue;			}		}		if (server_exclude_list.head		    && check_exclude(&server_exclude_list, fname,				     S_ISDIR(file->mode)) < 0) {			rprintf(FERROR, "attempt to hack rsync failed.\n");			exit_cleanup(RERR_PROTOCOL);		}		if (partial_dir) {			if ((partialptr = partial_dir_fname(fname)) != NULL)				fnamecmp = partialptr;			else				fnamecmp = fname;		} else			fnamecmp = partialptr = fname;		if (inplace && make_backups) {			if (!(fnamecmp = get_backup_name(fname)))				fnamecmp = partialptr;		}		/* open the file */		fd1 = do_open(fnamecmp, O_RDONLY, 0);		if (fd1 == -1 && fnamecmp != fname) {			fnamecmp = fname;			fd1 = do_open(fnamecmp, O_RDONLY, 0);		}		if (fd1 == -1 && compare_dest != NULL) {			/* try the file at compare_dest instead */			pathjoin(fnamecmpbuf, sizeof fnamecmpbuf,				 compare_dest, fname);			fnamecmp = fnamecmpbuf;			fd1 = do_open(fnamecmp, O_RDONLY, 0);		}		if (fd1 != -1 && do_fstat(fd1,&st) != 0) {			rsyserr(FERROR, errno, "fstat %s failed",				full_fname(fnamecmp));			discard_receive_data(f_in, file->length);			close(fd1);			continue;		}		if (fd1 != -1 && S_ISDIR(st.st_mode) && fnamecmp == fname) {			/* this special handling for directories			 * wouldn't be necessary if robust_rename()			 * and the underlying robust_unlink could cope			 * with directories			 */			rprintf(FERROR,"recv_files: %s is a directory\n",				full_fname(fnamecmp));			discard_receive_data(f_in, file->length);			close(fd1);			continue;		}		if (fd1 != -1 && !S_ISREG(st.st_mode)) {			close(fd1);			fd1 = -1;		}		if (fd1 != -1 && !preserve_perms) {			/* if the file exists already and we aren't preserving			 * permissions then act as though the remote end sent			 * us the file permissions we already have */			file->mode = st.st_mode;		}		/* We now check to see if we are writing file "inplace" */		if (inplace)  {			fd2 = do_open(fname, O_WRONLY|O_CREAT, 0);			if (fd2 == -1) {				rsyserr(FERROR, errno, "open %s failed",					full_fname(fname));				discard_receive_data(f_in, file->length);				if (fd1 != -1)					close(fd1);				continue;			}		} else {			if (!get_tmpname(fnametmp,fname)) {				discard_receive_data(f_in, file->length);				if (fd1 != -1)					close(fd1);				continue;			}			strlcpy(template, fnametmp, sizeof template);			/* we initially set the perms without the			 * setuid/setgid bits to ensure that there is no race			 * condition. They are then correctly updated after			 * the lchown. Thanks to snabb@epipe.fi for pointing			 * this out.  We also set it initially without group			 * access because of a similar race condition. */			fd2 = do_mkstemp(fnametmp, file->mode & INITACCESSPERMS);			/* in most cases parent directories will already exist			 * because their information should have been previously			 * transferred, but that may not be the case with -R */			if (fd2 == -1 && relative_paths && errno == ENOENT			    && create_directory_path(fnametmp, orig_umask) == 0) {				strlcpy(fnametmp, template, sizeof fnametmp);				fd2 = do_mkstemp(fnametmp, file->mode & INITACCESSPERMS);			}			if (fd2 == -1) {				rsyserr(FERROR, errno, "mkstemp %s failed",					full_fname(fnametmp));				discard_receive_data(f_in, file->length);				if (fd1 != -1)					close(fd1);				continue;			}			if (partialptr)				cleanup_set(fnametmp, partialptr, file, fd1, fd2);		}		if (!am_server && verbose) /* log the transfer */			rprintf(FINFO, "%s\n", safe_fname(fname));		/* recv file data */		recv_ok = receive_data(f_in, fnamecmp, fd1, st.st_size,				       fname, fd2, file->length);		log_recv(file, &initial_stats);		if (fd1 != -1)			close(fd1);		if (close(fd2) < 0) {			rsyserr(FERROR, errno, "close failed on %s",				full_fname(fnametmp));			exit_cleanup(RERR_FILEIO);		}		if (recv_ok || inplace)			finish_transfer(fname, fnametmp, file, recv_ok);		else if (keep_partial && partialptr		    && handle_partial_dir(partialptr, PDIR_CREATE))			finish_transfer(partialptr, fnametmp, file, 0);		else {			partialptr = NULL;			do_unlink(fnametmp);		}		if (partialptr != fname && fnamecmp == partialptr && recv_ok) {			do_unlink(partialptr);			handle_partial_dir(partialptr, PDIR_DELETE);		}		cleanup_disable();		if (!recv_ok) {			int msgtype = csum_length == SUM_LENGTH || read_batch ?				FERROR : FINFO;			if (msgtype == FERROR || verbose) {				char *errstr, *redostr, *keptstr;				if (!(keep_partial && partialptr) && !inplace)					keptstr = "discarded";				else if (partial_dir)					keptstr = "put into partial-dir";				else					keptstr = "retained";				if (msgtype == FERROR) {					errstr = "ERROR";					redostr = "";				} else {					errstr = "WARNING";					redostr = " (will try again)";				}				rprintf(msgtype,					"%s: %s failed verification -- update %s%s.\n",					errstr, safe_fname(fname),					keptstr, redostr);			}			if (csum_length != SUM_LENGTH) {				char buf[4];				SIVAL(buf, 0, i);				send_msg(MSG_REDO, buf, 4);			}		}	}	make_backups = save_make_backups;	if (delete_after && recurse && !local_name && flist->count > 0)		delete_files(flist);	if (verbose > 2)		rprintf(FINFO,"recv_files finished\n");	return 0;}