-#ifdef HAVE_MKNOD
- if (preserve_devices && IS_DEVICE(file->mode)) {
- if (statret != 0 ||
- st.st_mode != file->mode ||
- st.st_rdev != file->rdev) {
- if (!dry_run) unlink(fname);
- if (verbose > 2)
- fprintf(FERROR,"mknod(%s,0%o,0x%x)\n",
- fname,(int)file->mode,(int)file->rdev);
- if (!dry_run &&
- mknod(fname,file->mode,file->rdev) != 0) {
- fprintf(FERROR,"mknod %s : %s\n",fname,strerror(errno));
- } else {
- set_perms(fname,file,NULL,0);
- if (verbose)
- fprintf(FINFO,"%s\n",fname);
- }
- } else {
- set_perms(fname,file,&st,1);
- }
- return;
- }
-#endif
-
- if (preserve_hard_links && check_hard_link(file)) {
- if (verbose > 1)
- fprintf(FINFO,"%s is a hard link\n",file->name);
- return;
- }
-
- if (!S_ISREG(file->mode)) {
- fprintf(FERROR,"skipping non-regular file %s\n",fname);
- return;
- }
-
- if (statret == -1) {
- if (errno == ENOENT) {
- write_int(f_out,i);
- if (!dry_run) send_sums(NULL,f_out);
- } else {
- if (verbose > 1)
- fprintf(FERROR,"recv_generator failed to open %s\n",fname);
- }
- return;
- }
-
- if (!S_ISREG(st.st_mode)) {
- fprintf(FERROR,"%s : not a regular file\n",fname);
- return;
- }
-
- if (update_only && st.st_mtime >= file->modtime) {
- if (verbose > 1)
- fprintf(FERROR,"%s is newer\n",fname);
- return;
- }
-
- if (always_checksum && S_ISREG(st.st_mode)) {
- file_checksum(fname,sum,st.st_size);
- }
-
- if (st.st_size == file->length &&
- ((!ignore_times && st.st_mtime == file->modtime) ||
- (always_checksum && S_ISREG(st.st_mode) &&
- memcmp(sum,file->sum,csum_length) == 0))) {
- set_perms(fname,file,&st,1);
- return;
- }
-
- if (dry_run) {
- write_int(f_out,i);
- return;
- }
-
- /* open the file */
- fd = open(fname,O_RDONLY);
-
- if (fd == -1) {
- fprintf(FERROR,"failed to open %s : %s\n",fname,strerror(errno));
- return;
- }
-
- if (st.st_size > 0) {
- buf = map_file(fd,st.st_size);
- } else {
- buf = NULL;
- }
-
- if (verbose > 3)
- fprintf(FERROR,"gen mapped %s of size %d\n",fname,(int)st.st_size);
-
- s = generate_sums(buf,st.st_size,block_size);
-
- if (verbose > 2)
- fprintf(FERROR,"sending sums for %d\n",i);
-
- write_int(f_out,i);
- send_sums(s,f_out);
- write_flush(f_out);
-
- close(fd);
- unmap_file(buf);
-
- free_sums(s);
-}
-
-
-
-static int receive_data(int f_in,struct map_struct *buf,int fd,char *fname)
-{
- int i,n,remainder,len,count;
- off_t offset = 0;
- off_t offset2;
- char *data;
- static char file_sum1[SUM_LENGTH];
- static char file_sum2[SUM_LENGTH];
- char *map=NULL;
-
- count = read_int(f_in);
- n = read_int(f_in);
- remainder = read_int(f_in);
-
- sum_init();
-
- for (i=recv_token(f_in,&data); i != 0; i=recv_token(f_in,&data)) {
- if (i > 0) {
- if (verbose > 3)
- fprintf(FERROR,"data recv %d at %d\n",i,(int)offset);
-
- sum_update(data,i);
-
- if (write_sparse(fd,data,i) != i) {
- fprintf(FERROR,"write failed on %s : %s\n",fname,strerror(errno));
- exit_cleanup(1);
- }
- offset += i;
- } else {
- i = -(i+1);
- offset2 = i*n;
- len = n;
- if (i == count-1 && remainder != 0)
- len = remainder;
-
- if (verbose > 3)
- fprintf(FERROR,"chunk[%d] of size %d at %d offset=%d\n",
- i,len,(int)offset2,(int)offset);
-
- map = map_ptr(buf,offset2,len);
-
- sum_update(map,len);
-
- if (write_sparse(fd,map,len) != len) {
- fprintf(FERROR,"write failed on %s : %s\n",fname,strerror(errno));
- exit_cleanup(1);
- }
- offset += len;
- }
- }
-
- if (offset > 0 && sparse_end(fd) != 0) {
- fprintf(FERROR,"write failed on %s : %s\n",fname,strerror(errno));
- exit_cleanup(1);
- }
-
- sum_end(file_sum1);
-
- if (remote_version >= 14) {
- read_buf(f_in,file_sum2,SUM_LENGTH);
- if (verbose > 2)
- fprintf(FERROR,"got file_sum\n");
- if (memcmp(file_sum1,file_sum2,SUM_LENGTH) != 0)
- return 0;
- }
- return 1;
-}
-
-
-static void delete_one(struct file_struct *f)
-{
- if (!S_ISDIR(f->mode)) {
- if (!dry_run && unlink(f->name) != 0) {
- fprintf(FERROR,"unlink %s : %s\n",f->name,strerror(errno));
- } else if (verbose) {
- fprintf(FERROR,"deleting %s\n",f->name);
- }
- } else {
- if (!dry_run && rmdir(f->name) != 0) {
- if (errno != ENOTEMPTY)
- fprintf(FERROR,"rmdir %s : %s\n",f->name,strerror(errno));
- } else if (verbose) {
- fprintf(FERROR,"deleting directory %s\n",f->name);
- }
- }
-}
-
-
-static void delete_files(struct file_list *flist)
-{
- struct file_list *local_file_list;
- char *dot=".";
- int i;
-
- if (cvs_exclude)
- add_cvs_excludes();
-
- if (!(local_file_list = send_file_list(-1,recurse,1,&dot)))
- return;
-
- for (i=local_file_list->count;i>=0;i--) {
- if (!local_file_list->files[i].name) continue;
- if (-1 == flist_find(flist,&local_file_list->files[i])) {
- delete_one(&local_file_list->files[i]);
- }
- }