rem: pathjoin(buf2, sizeof buf2, am_sender && file->dir.root ? file->dir.root : "", safe_fname(f_name(file))); clean_fname(buf2, 0); n = buf2; if (*n == '/') n++;
add: n = safe_fname(f_name(file)); if (am_sender && file->dir.root) { pathjoin(buf2, sizeof buf2, file->dir.root, n);  strcpy(n, buf2); } clean_fname(n, 0); if (*n == '/') n++;
context: static void log_formatted(enum logcode code, char *format, char *op,			  struct file_struct *file, struct stats *initial_stats,			  int iflags, char *hlink){	char buf[MAXPATHLEN+1024], buf2[MAXPATHLEN], fmt[32];	char *p, *s, *n;	size_t len, total;	int64 b;	*fmt = '%';	/* We expand % codes one by one in place in buf.  We don't	 * copy in the terminating nul of the inserted strings, but	 * rather keep going until we reach the nul of the format. */	total = strlcpy(buf, format, sizeof buf);		for (p = buf; (p = strchr(p, '%')) != NULL && p[1]; ) {		s = p++;		n = fmt + 1;		while (isdigit(*(uchar*)p) && n - fmt < 16)			*n++ = *p++;		*n = '\0';		n = NULL;		switch (*p++) {		case 'h': if (am_daemon) n = client_name(0); break;		case 'a': if (am_daemon) n = client_addr(0); break;		case 'l':			strlcat(fmt, ".0f", sizeof fmt);			snprintf(buf2, sizeof buf2, fmt,				 (double)file->length);			n = buf2;			break;		case 'p':			strlcat(fmt, "d", sizeof fmt);			snprintf(buf2, sizeof buf2, fmt,				 (int)getpid());			n = buf2;			break;		case 'o': n = op; break;		case 'f':			pathjoin(buf2, sizeof buf2,			    am_sender && file->dir.root ? file->dir.root : "",			    safe_fname(f_name(file)));			clean_fname(buf2, 0);			n = buf2;			if (*n == '/') n++;			break;		case 'n':			n = (char*)safe_fname(f_name(file));			if (S_ISDIR(file->mode)) {				/* The buffer from safe_fname() has more				 * room than MAXPATHLEN, so this is safe. */				strcat(n, "/");			}			break;		case 'L':			if (hlink && *hlink) {				snprintf(buf2, sizeof buf2, " => %s",					 safe_fname(hlink));				n = buf2;			} else if (S_ISLNK(file->mode) && file->u.link) {				snprintf(buf2, sizeof buf2, " -> %s",					 safe_fname(file->u.link));				n = buf2;			} else				n = "";			break;		case 'm': n = lp_name(module_id); break;		case 't': n = timestring(time(NULL)); break;		case 'P': n = lp_path(module_id); break;		case 'u': n = auth_user; break;		case 'b':			strlcat(fmt, ".0f", sizeof fmt);			if (am_sender) {				b = stats.total_written -					initial_stats->total_written;			} else {				b = stats.total_read -					initial_stats->total_read;			}			snprintf(buf2, sizeof buf2, fmt, (double)b);			n = buf2;			break;		case 'c':			strlcat(fmt, ".0f", sizeof fmt);			if (!am_sender) {				b = stats.total_written -					initial_stats->total_written;			} else {				b = stats.total_read -					initial_stats->total_read;			}			snprintf(buf2, sizeof buf2, fmt, (double)b);			n = buf2;			break;		case 'i':			if (iflags & ITEM_DELETED) {				n = "*deleting";				break;			}			n = buf2;			n[0] = iflags & ITEM_LOCAL_CHANGE			      ? iflags & ITEM_XNAME_FOLLOWS ? 'h' : 'c'			     : !(iflags & ITEM_TRANSFER) ? '.'			     : !local_server && *op == 's' ? '<' : '>';			n[1] = S_ISDIR(file->mode) ? 'd'			     : IS_DEVICE(file->mode) ? 'D'			     : S_ISLNK(file->mode) ? 'L' : 'f';			n[2] = !(iflags & ITEM_REPORT_CHECKSUM) ? '.' : 'c';			n[3] = !(iflags & ITEM_REPORT_SIZE) ? '.' : 's';			n[4] = !(iflags & ITEM_REPORT_TIME) ? '.'			     : !preserve_times || IS_DEVICE(file->mode)					       || S_ISLNK(file->mode) ? 'T' : 't';			n[5] = !(iflags & ITEM_REPORT_PERMS) ? '.' : 'p';			n[6] = !(iflags & ITEM_REPORT_OWNER) ? '.' : 'o';			n[7] = !(iflags & ITEM_REPORT_GROUP) ? '.' : 'g';			n[8] = !(iflags & ITEM_REPORT_XATTRS) ? '.' : 'a';			n[9] = '\0';			if (iflags & (ITEM_IS_NEW|ITEM_MISSING_DATA)) {				char ch = iflags & ITEM_IS_NEW ? '+' : '?';				int i;				for (i = 2; n[i]; i++)					n[i] = ch;			} else if (!(iflags & (ITEM_TRANSFER|ITEM_LOCAL_CHANGE))) {				int i;				for (i = 2; n[i]; i++) {					if (n[i] != '.')						break;				}				if (!n[i]) {					for (i = 2; n[i]; i++)						n[i] = ' ';				}			}			break;		}		/* Subtract the length of the escape from the string's size. */		total -= p - s;		/* "n" is the string to be inserted in place of this % code. */		if (!n)			continue;		len = strlen(n);		if (len + total >= sizeof buf) {			rprintf(FERROR,				"buffer overflow expanding %%%c -- exiting\n",				p[-1]);			exit_cleanup(RERR_MESSAGEIO);		}		/* Shuffle the rest of the string along to make space for n */		if (len != (size_t)(p - s))			memmove(s + len, p, total - (s - buf) + 1);		total += len;		/* Insert the contents of string "n", but NOT its null. */		if (len)			memcpy(s, n, len);		/* Skip over inserted string; continue looking */		p = s + len;	}	rprintf(code, "%s\n", buf);}