X-Git-Url: https://mattmccutchen.net/rsync/rsync.git/blobdiff_plain/b7e8628c4bc66be139ae1a7efcb16034c146edb7..17b5b32f75d4d00e00ff2664ca905c797f455bb1:/generator.c diff --git a/generator.c b/generator.c index f2b9cb04..5d051580 100644 --- a/generator.c +++ b/generator.c @@ -47,7 +47,7 @@ extern int protocol_version; extern int always_checksum; extern char *partial_dir; extern char *basis_dir[]; -extern int copy_dest; +extern int compare_dest; extern int link_dest; extern int whole_file; extern int local_server; @@ -56,7 +56,7 @@ extern int read_batch; extern int only_existing; extern int orig_umask; extern int safe_symlinks; -extern unsigned int block_size; +extern long block_size; /* "long" because popt can't set an int32. */ extern struct exclude_list_struct server_exclude_list; @@ -136,29 +136,30 @@ void write_sum_head(int f, struct sum_struct *sum) */ static void sum_sizes_sqroot(struct sum_struct *sum, uint64 len) { - unsigned int blength; + int32 blength; int s2length; - uint32 c; - uint64 l; - if (block_size) { + if (block_size) blength = block_size; - } else if (len <= BLOCK_SIZE * BLOCK_SIZE) { + else if (len <= BLOCK_SIZE * BLOCK_SIZE) blength = BLOCK_SIZE; - } else { - l = len; - c = 1; - while (l >>= 2) { - c <<= 1; + else { + int32 c; + uint64 l; + int cnt; + for (c = 1, l = len, cnt = 0; l >>= 2; c <<= 1, cnt++) {} + if (cnt >= 31 || c >= MAX_BLOCK_SIZE) + blength = MAX_BLOCK_SIZE; + else { + blength = 0; + do { + blength |= c; + if (len < (uint64)blength * blength) + blength &= ~c; + c >>= 1; + } while (c >= 8); /* round to multiple of 8 */ + blength = MAX(blength, BLOCK_SIZE); } - blength = 0; - do { - blength |= c; - if (len < (uint64)blength * blength) - blength &= ~c; - c >>= 1; - } while (c >= 8); /* round to multiple of 8 */ - blength = MAX(blength, BLOCK_SIZE); } if (protocol_version < 27) { @@ -166,20 +167,13 @@ static void sum_sizes_sqroot(struct sum_struct *sum, uint64 len) } else if (csum_length == SUM_LENGTH) { s2length = SUM_LENGTH; } else { + int32 c; + uint64 l; int b = BLOCKSUM_BIAS; - l = len; - while (l >>= 1) { - b += 2; - } - c = blength; - while (c >>= 1 && b) { - b--; - } - s2length = (b + 1 - 32 + 7) / 8; /* add a bit, - * subtract rollsum, - * round up - * --optimize in compiler-- - */ + for (l = len; l >>= 1; b += 2) {} + for (c = blength; c >>= 1 && b; b--) {} + /* add a bit, subtract rollsum, round up. */ + s2length = (b + 1 - 32 + 7) / 8; /* --optimize in compiler-- */ s2length = MAX(s2length, csum_length); s2length = MIN(s2length, SUM_LENGTH); } @@ -191,8 +185,9 @@ static void sum_sizes_sqroot(struct sum_struct *sum, uint64 len) sum->remainder = (len % blength); if (sum->count && verbose > 2) { - rprintf(FINFO, "count=%.0f rem=%u blength=%u s2length=%d flength=%.0f\n", - (double)sum->count, sum->remainder, sum->blength, + rprintf(FINFO, + "count=%.0f rem=%ld blength=%ld s2length=%d flength=%.0f\n", + (double)sum->count, (long)sum->remainder, (long)sum->blength, sum->s2length, (double)sum->flength); } } @@ -220,7 +215,7 @@ static void generate_and_send_sums(int fd, OFF_T len, int f_out, int f_copy) write_sum_head(f_out, &sum); for (i = 0; i < sum.count; i++) { - unsigned int n1 = MIN(len, sum.blength); + int32 n1 = (int32)MIN(len, (OFF_T)sum.blength); char *map = map_ptr(mapbuf, offset, n1); uint32 sum1 = get_checksum1(map, n1); char sum2[SUM_LENGTH]; @@ -232,8 +227,8 @@ static void generate_and_send_sums(int fd, OFF_T len, int f_out, int f_copy) if (verbose > 3) { rprintf(FINFO, - "chunk[%.0f] offset=%.0f len=%u sum1=%08lx\n", - (double)i, (double)offset, n1, + "chunk[%.0f] offset=%.0f len=%ld sum1=%08lx\n", + (double)i, (double)offset, (long)n1, (unsigned long)sum1); } write_int(f_out, sum1); @@ -475,13 +470,13 @@ static void recv_generator(char *fname, struct file_struct *file, int i, safe_fname(fname)); } fnamecmp = fnamecmpbuf; - fnamecmp_type = FNAMECMP_BASIS_DIR + i; + fnamecmp_type = i; } } else #endif { fnamecmp = fnamecmpbuf; - fnamecmp_type = FNAMECMP_BASIS_DIR + i; + fnamecmp_type = i; } } } @@ -493,7 +488,7 @@ static void recv_generator(char *fname, struct file_struct *file, int i, stat_errno = ENOENT; } - if (partial_dir && (partialptr = partial_dir_fname(fname)) + if (partial_dir && (partialptr = partial_dir_fname(fname)) != NULL && link_stat(partialptr, &partial_st, 0) == 0 && S_ISREG(partial_st.st_mode)) { if (statret == -1) @@ -527,7 +522,7 @@ static void recv_generator(char *fname, struct file_struct *file, int i, return; } - if ((link_dest || copy_dest) && fnamecmp_type != FNAMECMP_FNAME) + if (!compare_dest && fnamecmp_type <= FNAMECMP_BASIS_DIR_HIGH) ; else if (unchanged_file(fnamecmp, file, &st)) { if (fnamecmp_type == FNAMECMP_FNAME) @@ -536,6 +531,13 @@ static void recv_generator(char *fname, struct file_struct *file, int i, } prepare_to_open: + if (partialptr) { + st = partial_st; + fnamecmp = partialptr; + fnamecmp_type = FNAMECMP_PARTIAL_DIR; + statret = 0; + } + if (dry_run || whole_file > 0) { statret = -1; goto notify_others; @@ -543,12 +545,6 @@ prepare_to_open: if (read_batch) goto notify_others; - if (partialptr) { - st = partial_st; - fnamecmp = partialptr; - fnamecmp_type = FNAMECMP_PARTIAL_DIR; - } - /* open the file */ fd = do_open(fnamecmp, O_RDONLY, 0); @@ -600,6 +596,8 @@ prepare_to_open: notify_others: write_int(f_out, i); + if (protocol_version >= 29 && inplace && !read_batch) + write_byte(f_out, fnamecmp_type); if (f_out_name >= 0) write_byte(f_out_name, fnamecmp_type); @@ -693,6 +691,9 @@ void generate_files(int f_out, struct file_list *flist, char *local_name, write_int(f_out, -1); + /* Read post-redo-phase MSG_DONE and any prior messages. */ + get_redo_num(); + if (preserve_hard_links) do_hard_links();