- }
- }
- if (!dry_run) unlink(fname);
- if (!dry_run && symlink(file->link,fname) != 0) {
- fprintf(FERROR,"link %s -> %s : %s\n",
- fname,file->link,strerror(errno));
- } else {
- set_perms(fname,file,NULL,0);
- if (verbose)
- fprintf(FINFO,"%s -> %s\n",
- fname,file->link);
- }
-#endif
- return;
- }
-
-#ifdef HAVE_MKNOD
- if (am_root && 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)) {
- /* its not a regular file on the receiving end, but it is on the
- sending end. If its a directory then skip it (too dangerous to
- do a recursive deletion??) otherwise try to unlink it */
- if (S_ISDIR(st.st_mode)) {
- fprintf(FERROR,"ERROR: %s is a directory\n",fname);
- return;
- }
- if (unlink(fname) != 0) {
- fprintf(FERROR,"%s : not a regular file (generator)\n",fname);
- return;
- }
-
- /* now pretend the file didn't exist */
- write_int(f_out,i);
- if (!dry_run) send_sums(NULL,f_out);
- return;
- }
-
- if (update_only && st.st_mtime >= file->modtime) {
- if (verbose > 1)
- fprintf(FERROR,"%s is newer\n",fname);
- return;
- }
-
- if (skip_file(fname, file, &st)) {
- set_perms(fname,file,&st,1);
- return;
- }
-
- if (dry_run) {
- write_int(f_out,i);
- return;
- }
-
- if (whole_file) {
- write_int(f_out,i);
- send_sums(NULL,f_out);
- return;
- }
-
- /* open the file */
- fd = open(fname,O_RDONLY);
-
- if (fd == -1) {
- fprintf(FERROR,"failed to open %s : %s\n",fname,strerror(errno));
- fprintf(FERROR,"skipping %s\n",fname);
- 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);
- if (buf) 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[MD4_SUM_LENGTH];
- static char file_sum2[MD4_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 (fd != -1 && 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);