X-Git-Url: https://mattmccutchen.net/rsync/rsync.git/blobdiff_plain/e7bc9b64a3d55f1465faf61f2329e28fdcf24984..0e36d9da420af7c7e49bfd5e2c5aad712a85b633:/generator.c diff --git a/generator.c b/generator.c index 0e51defe..21ab0eb2 100644 --- a/generator.c +++ b/generator.c @@ -30,6 +30,9 @@ extern int preserve_links; extern int am_root; extern int preserve_devices; extern int preserve_hard_links; +extern int preserve_perms; +extern int preserve_uid; +extern int preserve_gid; extern int update_only; extern int opt_ignore_existing; extern int csum_length; @@ -50,18 +53,15 @@ static int skip_file(char *fname, return 0; } if (link_dest) { - extern int preserve_perms; - extern int preserve_uid; - extern int preserve_gid; - if (preserve_perms && (st->st_mode & ~_S_IFMT) != (file->mode & ~_S_IFMT)) return 0; - if (preserve_uid && st->st_uid != file->uid) + if (am_root && preserve_uid && st->st_uid != file->uid) return 0; - if (preserve_gid && st->st_gid != file->gid) + if (preserve_gid && file->gid != GID_NONE + && st->st_gid != file->gid) return 0; } @@ -99,9 +99,8 @@ static int skip_file(char *fname, /* - * NULL sum_struct means we have no checksums + * NULL sum_struct means we have no checksums */ - void write_sum_head(int f, struct sum_struct *sum) { static struct sum_struct null_sum; @@ -136,8 +135,9 @@ void write_sum_head(int f, struct sum_struct *sum) static void sum_sizes_sqroot(struct sum_struct *sum, uint64 len) { - extern int block_size; - int blength, s2length, b; + extern unsigned int block_size; + unsigned int blength; + int s2length; uint32 c; uint64 l; @@ -166,7 +166,7 @@ static void sum_sizes_sqroot(struct sum_struct *sum, uint64 len) } else if (csum_length == SUM_LENGTH) { s2length = SUM_LENGTH; } else { - b = BLOCKSUM_BIAS; + int b = BLOCKSUM_BIAS; l = len; while (l >>= 1) { b += 2; @@ -191,10 +191,9 @@ static void sum_sizes_sqroot(struct sum_struct *sum, uint64 len) sum->remainder = (len % blength); if (sum->count && verbose > 2) { - rprintf(FINFO, "count=%ld rem=%ld blength=%ld s2length=%ld flength=%.0f\n", - (long) sum->count, (long) sum->remainder, - (long) sum->blength, (long) sum->s2length, - (double) sum->flength); + rprintf(FINFO, "count=%.0f rem=%u blength=%u s2length=%d flength=%.0f\n", + (double)sum->count, sum->remainder, sum->blength, + sum->s2length, (double)sum->flength); } } @@ -226,7 +225,7 @@ static BOOL disable_deltas_p(void) * * Generate approximately one checksum every block_len bytes. */ -static void generate_and_send_sums(struct map_struct *buf, OFF_T len, int f_out) +static void generate_and_send_sums(struct map_struct *buf, size_t len, int f_out) { size_t i; struct sum_struct sum; @@ -237,7 +236,7 @@ static void generate_and_send_sums(struct map_struct *buf, OFF_T len, int f_out) write_sum_head(f_out, &sum); for (i = 0; i < sum.count; i++) { - int n1 = MIN(len, sum.blength); + unsigned int n1 = MIN(len, sum.blength); char *map = map_ptr(buf, offset, n1); uint32 sum1 = get_checksum1(map, n1); char sum2[SUM_LENGTH]; @@ -246,8 +245,9 @@ static void generate_and_send_sums(struct map_struct *buf, OFF_T len, int f_out) if (verbose > 3) { rprintf(FINFO, - "chunk[%ld] offset=%.0f len=%d sum1=%08lx\n", - (long)i,(double)offset,n1,(unsigned long)sum1); + "chunk[%.0f] offset=%.0f len=%u sum1=%08lx\n", + (double)i, (double)offset, n1, + (unsigned long)sum1); } write_int(f_out, sum1); write_buf(f_out, sum2, sum.s2length); @@ -270,14 +270,13 @@ void recv_generator(char *fname, struct file_list *flist, int i, int f_out) { int fd; STRUCT_STAT st; - struct map_struct *buf; + struct map_struct *mapbuf; int statret; struct file_struct *file = flist->files[i]; char *fnamecmp; char fnamecmpbuf[MAXPATHLEN]; extern char *compare_dest; extern int list_only; - extern int preserve_perms; extern int only_existing; extern int orig_umask; @@ -506,11 +505,10 @@ void recv_generator(char *fname, struct file_list *flist, int i, int f_out) return; } - if (st.st_size > 0) { - buf = map_file(fd,st.st_size); - } else { - buf = NULL; - } + if (st.st_size > 0) + mapbuf = map_file(fd,st.st_size); + else + mapbuf = NULL; if (verbose > 3) rprintf(FINFO,"gen mapped %s of size %.0f\n",fnamecmp,(double)st.st_size); @@ -519,10 +517,10 @@ void recv_generator(char *fname, struct file_list *flist, int i, int f_out) rprintf(FINFO, "generating and sending sums for %d\n", i); write_int(f_out,i); - generate_and_send_sums(buf, st.st_size, f_out); + generate_and_send_sums(mapbuf, st.st_size, f_out); close(fd); - if (buf) unmap_file(buf); + if (mapbuf) unmap_file(mapbuf); } @@ -531,7 +529,7 @@ void generate_files(int f,struct file_list *flist,char *local_name,int f_recv) { int i; int phase=0; - char buf[MAXPATHLEN]; + char fbuf[MAXPATHLEN]; if (verbose > 2) rprintf(FINFO,"generator starting pid=%d count=%d\n", @@ -564,7 +562,7 @@ void generate_files(int f,struct file_list *flist,char *local_name,int f_recv) } recv_generator(local_name? local_name - : f_name_to(file, buf, sizeof buf), flist, i, f); + : f_name_to(file,fbuf,sizeof fbuf), flist, i, f); file->mode = saved_mode; } @@ -583,7 +581,7 @@ void generate_files(int f,struct file_list *flist,char *local_name,int f_recv) for (i = read_int(f_recv); i != -1; i = read_int(f_recv)) { struct file_struct *file = flist->files[i]; recv_generator(local_name? local_name - : f_name_to(file, buf, sizeof buf), flist, i, f); + : f_name_to(file,fbuf,sizeof fbuf), flist, i, f); } phase++;