X-Git-Url: https://mattmccutchen.net/rsync/rsync.git/blobdiff_plain/71903f601a37392eb8ecb737c10fac78d18f5777..910e89b9633a345154704cccd7c5f4189f5ceb41:/receiver.c diff --git a/receiver.c b/receiver.c index a9a9cd2a..1afdf2d3 100644 --- a/receiver.c +++ b/receiver.c @@ -21,6 +21,8 @@ #include "rsync.h" extern int verbose; +extern int itemize_changes; +extern int log_before_transfer; extern int delete_after; extern int csum_length; extern struct stats stats; @@ -48,6 +50,7 @@ extern int keep_partial; extern int checksum_seed; extern int inplace; extern int delay_updates; +extern char *log_format; extern struct filter_list_struct server_filter_list; @@ -228,7 +231,7 @@ static int receive_data(int f_in, char *fname_r, int fd_r, OFF_T size_r, if (flush_write_file(fd) < 0) goto report_write_error; -#if HAVE_FTRUNCATE +#ifdef HAVE_FTRUNCATE if (inplace && fd != -1) ftruncate(fd, offset); #endif @@ -257,6 +260,36 @@ static int receive_data(int f_in, char *fname_r, int fd_r, OFF_T size_r, } +static void read_gen_name(int fd, char *dirname, char *buf) +{ + int dlen; + int len = read_byte(fd); + + if (len & 0x80) { +#if MAXPATHLEN > 32767 + uchar lenbuf[2]; + read_buf(fd, (char *)lenbuf, 2); + len = (len & ~0x80) * 0x10000 + lenbuf[0] * 0x100 + lenbuf[1]; +#else + len = (len & ~0x80) * 0x100 + read_byte(fd); +#endif + } + + if (dirname) { + dlen = strlcpy(buf, dirname, MAXPATHLEN); + buf[dlen++] = '/'; + } else + dlen = 0; + + if (dlen + len >= MAXPATHLEN) { + rprintf(FERROR, "bogus data on generator name pipe\n"); + exit_cleanup(RERR_PROTOCOL); + } + + read_sbuf(fd, buf + dlen, len); +} + + static void discard_receive_data(int f_in, OFF_T length) { receive_data(f_in, NULL, -1, 0, NULL, -1, length); @@ -273,6 +306,7 @@ int recv_files(int f_in, struct file_list *flist, char *local_name, int next_gen_i = -1; int fd1,fd2; STRUCT_STAT st; + int iflags; char *fname, fbuf[MAXPATHLEN]; char template[MAXPATHLEN]; char fnametmp[MAXPATHLEN]; @@ -335,8 +369,19 @@ int recv_files(int f_in, struct file_list *flist, char *local_name, } file = flist->files[i]; - if (S_ISDIR(file->mode)) { - rprintf(FERROR, "[%s] got index of directory: %d\n", + + if (itemize_changes) { + iflags = read_byte(f_in); + if (!(iflags & ITEM_UPDATING) || !S_ISREG(file->mode)) { + if (!dry_run || !am_server) + log_recv(file, &stats, iflags); + continue; + } + } else + iflags = ITEM_UPDATING | ITEM_MISSING_DATA; + + if (!S_ISREG(file->mode)) { + rprintf(FERROR, "[%s] got index of non-regular file: %d\n", who_am_i(), i); exit_cleanup(RERR_PROTOCOL); } @@ -357,14 +402,14 @@ int recv_files(int f_in, struct file_list *flist, char *local_name, if (verbose > 2) rprintf(FINFO, "recv_files(%s)\n", safe_fname(fname)); - if (dry_run) { - if (!am_server && verbose) /* log the transfer */ + if (dry_run) { /* log the transfer */ + if (!am_server && verbose && !log_format) rprintf(FINFO, "%s\n", safe_fname(fname)); + else if (!am_server) + log_recv(file, &stats, iflags); continue; } - initial_stats = stats; - if (read_batch) { while (i > next_gen_i) { if (f_in_name >= 0 && next_gen_i >= 0) @@ -396,6 +441,10 @@ int recv_files(int f_in, struct file_list *flist, char *local_name, case FNAMECMP_BACKUP: fnamecmp = get_backup_name(fname); break; + case FNAMECMP_FUZZY: + read_gen_name(f_in_name, file->dirname, fnamecmpbuf); + fnamecmp = fnamecmpbuf; + break; default: if (j >= basis_dir_cnt) { rprintf(FERROR, @@ -411,6 +460,8 @@ int recv_files(int f_in, struct file_list *flist, char *local_name, } else fnamecmp = fname; + initial_stats = stats; + /* open the file */ fd1 = do_open(fnamecmp, O_RDONLY, 0); @@ -497,14 +548,18 @@ int recv_files(int f_in, struct file_list *flist, char *local_name, cleanup_set(fnametmp, partialptr, file, fd1, fd2); } - if (!am_server && verbose) /* log the transfer */ + /* log the transfer */ + if (log_before_transfer) + log_recv(file, &initial_stats, iflags); + else if (!am_server && verbose && (!log_format || do_progress)) 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 (!log_before_transfer) + log_recv(file, &initial_stats, iflags); if (fd1 != -1) close(fd1); @@ -514,7 +569,7 @@ int recv_files(int f_in, struct file_list *flist, char *local_name, exit_cleanup(RERR_FILEIO); } - if ((recv_ok && !delay_updates) || inplace) { + if ((recv_ok && (!delay_updates || !partialptr)) || inplace) { finish_transfer(fname, fnametmp, file, recv_ok, 1); if (partialptr != fname && fnamecmp == partialptr) { do_unlink(partialptr);