X-Git-Url: https://mattmccutchen.net/rsync/rsync.git/blobdiff_plain/981791bd45b0a784be79661b45eba2a537cea2fe..34ccb63e71367fb1f93530f60147ef6e4ac4e3e4:/rsync.c diff --git a/rsync.c b/rsync.c index b8653535..bb249800 100644 --- a/rsync.c +++ b/rsync.c @@ -19,6 +19,8 @@ #include "rsync.h" +extern int csum_length; + extern int verbose; extern int am_server; extern int always_checksum; @@ -67,7 +69,7 @@ static void send_sums(struct sum_struct *s,int f_out) if (s) for (i=0;icount;i++) { write_int(f_out,s->sums[i].sum1); - write_buf(f_out,s->sums[i].sum2,SUM_LENGTH); + write_buf(f_out,s->sums[i].sum2,csum_length); } write_flush(f_out); } @@ -111,9 +113,10 @@ static struct sum_struct *generate_sums(char *buf,off_t len,int n) for (i=0;isums[i].sum1 = get_checksum1(buf,n1); - get_checksum2(buf,n1,s->sums[i].sum2); + s->sums[i].sum1 = get_checksum1(map,n1); + get_checksum2(map,n1,s->sums[i].sum2); s->sums[i].offset = offset; s->sums[i].len = n1; @@ -124,7 +127,6 @@ static struct sum_struct *generate_sums(char *buf,off_t len,int n) i,(int)s->sums[i].offset,s->sums[i].len,s->sums[i].sum1); len -= n1; - buf += n1; offset += n1; } @@ -164,7 +166,7 @@ static struct sum_struct *receive_sums(int f) for (i=0;icount;i++) { s->sums[i].sum1 = read_int(f); - read_buf(f,s->sums[i].sum2,SUM_LENGTH); + read_buf(f,s->sums[i].sum2,csum_length); s->sums[i].offset = offset; s->sums[i].i = i; @@ -203,7 +205,8 @@ static void set_perms(char *fname,struct file_struct *file,struct stat *st, st = &st2; } - if (preserve_times && st->st_mtime != file->modtime) { + if (preserve_times && !S_ISLNK(st->st_mode) && + st->st_mtime != file->modtime) { updated = 1; if (set_modtime(fname,file->modtime) != 0) { fprintf(stderr,"failed to set times on %s : %s\n", @@ -213,7 +216,8 @@ static void set_perms(char *fname,struct file_struct *file,struct stat *st, } #ifdef HAVE_CHMOD - if (preserve_perms && st->st_mode != file->mode) { + if (preserve_perms && !S_ISLNK(st->st_mode) && + st->st_mode != file->mode) { updated = 1; if (chmod(fname,file->mode) != 0) { fprintf(stderr,"failed to set permissions on %s : %s\n", @@ -267,8 +271,7 @@ void recv_generator(char *fname,struct file_list *flist,int i,int f_out) if (l > 0) { lnk[l] = 0; if (strcmp(lnk,flist->files[i].link) == 0) { - if (verbose > 1) - fprintf(am_server?stderr:stdout,"%s is uptodate\n",fname); + set_perms(fname,&flist->files[i],&st,1); return; } } @@ -278,16 +281,17 @@ void recv_generator(char *fname,struct file_list *flist,int i,int f_out) fprintf(stderr,"link %s -> %s : %s\n", fname,flist->files[i].link,strerror(errno)); } else { + set_perms(fname,&flist->files[i],NULL,0); if (verbose) - fprintf(am_server?stderr:stdout,"%s -> %s\n",fname,flist->files[i].link); + fprintf(am_server?stderr:stdout,"%s -> %s\n", + fname,flist->files[i].link); } return; } #endif #ifdef HAVE_MKNOD - if (preserve_devices && - (S_ISCHR(flist->files[i].mode) || S_ISBLK(flist->files[i].mode))) { + if (preserve_devices && IS_DEVICE(flist->files[i].mode)) { if (statret != 0 || st.st_mode != flist->files[i].mode || st.st_rdev != flist->files[i].dev) { @@ -344,7 +348,7 @@ void recv_generator(char *fname,struct file_list *flist,int i,int f_out) if (st.st_size == flist->files[i].length && ((!ignore_times && st.st_mtime == flist->files[i].modtime) || (always_checksum && S_ISREG(st.st_mode) && - memcmp(sum,flist->files[i].sum,SUM_LENGTH) == 0))) { + memcmp(sum,flist->files[i].sum,csum_length) == 0))) { set_perms(fname,&flist->files[i],&st,1); return; } @@ -364,11 +368,6 @@ void recv_generator(char *fname,struct file_list *flist,int i,int f_out) if (st.st_size > 0) { buf = map_file(fd,st.st_size); - if (!buf) { - fprintf(stderr,"mmap : %s\n",strerror(errno)); - close(fd); - return; - } } else { buf = NULL; } @@ -407,7 +406,7 @@ static void receive_data(int f_in,char *buf,int fd,char *fname) if (read_write(f_in,fd,i) != i) { fprintf(stderr,"write failed on %s : %s\n",fname,strerror(errno)); - exit(1); + exit_cleanup(1); } offset += i; } else { @@ -421,13 +420,18 @@ static void receive_data(int f_in,char *buf,int fd,char *fname) fprintf(stderr,"chunk[%d] of size %d at %d offset=%d\n", i,len,(int)offset2,(int)offset); - if (write(fd,buf+offset2,len) != len) { + if (write_sparse(fd,map_ptr(buf,offset2,len),len) != len) { fprintf(stderr,"write failed on %s : %s\n",fname,strerror(errno)); - exit(1); + exit_cleanup(1); } offset += len; } } + + if (offset > 0 && sparse_end(fd) != 0) { + fprintf(stderr,"write failed on %s : %s\n",fname,strerror(errno)); + exit_cleanup(1); + } } @@ -456,6 +460,9 @@ static void delete_files(struct file_list *flist) char *dot="."; int i; + if (cvs_exclude) + add_cvs_excludes(); + if (!(local_file_list = send_file_list(-1,recurse,1,&dot))) return; @@ -469,11 +476,16 @@ static void delete_files(struct file_list *flist) static char *cleanup_fname = NULL; -void sig_int(void) +void exit_cleanup(int code) { if (cleanup_fname) unlink(cleanup_fname); - exit(1); + exit(code); +} + +void sig_int(void) +{ + exit_cleanup(1); } @@ -530,10 +542,6 @@ int recv_files(int f_in,struct file_list *flist,char *local_name) if (fd1 != -1 && st.st_size > 0) { buf = map_file(fd1,st.st_size); - if (!buf) { - fprintf(stderr,"map_file failed\n"); - return -1; - } } else { buf = NULL; } @@ -547,7 +555,7 @@ int recv_files(int f_in,struct file_list *flist,char *local_name) fprintf(stderr,"mktemp %s failed\n",fnametmp); return -1; } - fd2 = open(fnametmp,O_WRONLY|O_CREAT,st.st_mode); + fd2 = open(fnametmp,O_WRONLY|O_CREAT,flist->files[i].mode); if (fd2 == -1) { fprintf(stderr,"open %s : %s\n",fnametmp,strerror(errno)); return -1; @@ -575,7 +583,7 @@ int recv_files(int f_in,struct file_list *flist,char *local_name) sprintf(fnamebak,"%s%s",fname,backup_suffix); if (rename(fname,fnamebak) != 0 && errno != ENOENT) { fprintf(stderr,"rename %s %s : %s\n",fname,fnamebak,strerror(errno)); - exit(1); + exit_cleanup(1); } } @@ -611,6 +619,8 @@ off_t send_files(struct file_list *flist,int f_out,int f_in) if (verbose > 2) fprintf(stderr,"send_files starting\n"); + setup_nonblocking(f_in,f_out); + while (1) { i = read_int(f_in); @@ -654,10 +664,6 @@ off_t send_files(struct file_list *flist,int f_out,int f_in) if (st.st_size > 0) { buf = map_file(fd,st.st_size); - if (!buf) { - fprintf(stderr,"map_file failed : %s\n",strerror(errno)); - return -1; - } } else { buf = NULL; }