- 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,"mapped %s of size %d\n",fname,(int)st.st_size);
-
- s = generate_sums(buf,st.st_size,block_size);
-
- write_int(f_out,i);
- send_sums(s,f_out);
- write_flush(f_out);
-
- close(fd);
- unmap_file(buf,st.st_size);
-
- free_sums(s);
-}
-
-
-
-static void receive_data(int f_in,char *buf,int fd,char *fname)
-{
- int i,n,remainder,len,count;
- off_t offset = 0;
- off_t offset2;
- char *data;
-
- count = read_int(f_in);
- n = read_int(f_in);
- remainder = read_int(f_in);
-
- 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);
-
- 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);
-
- if (write_sparse(fd,map_ptr(buf,offset2,len),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);
- }
-}
-