-
- if (preserve_hard_links && check_hard_link(file)) {
- if (verbose > 1)
- rprintf(FINFO,"%s is a hard link\n",f_name(file));
- return;
- }
-
- if (!S_ISREG(file->mode)) {
- rprintf(FINFO,"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)
- rprintf(FERROR,"recv_generator failed to open %s\n",fname);
- }
- return;
- }
-
- if (!S_ISREG(st.st_mode)) {
- if (delete_file(fname) != 0) {
- 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)
- rprintf(FINFO,"%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) {
- rprintf(FERROR,"failed to open %s : %s\n",fname,strerror(errno));
- rprintf(FERROR,"skipping %s\n",fname);
- return;
- }
-
- if (st.st_size > 0) {
- buf = map_file(fd,st.st_size);
- } else {
- buf = NULL;
- }
-
- if (verbose > 3)
- rprintf(FINFO,"gen mapped %s of size %d\n",fname,(int)st.st_size);
-
- s = generate_sums(buf,st.st_size,adapt_block_size(file, block_size));
-
- if (verbose > 2)
- rprintf(FINFO,"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)
- rprintf(FINFO,"data recv %d at %d\n",i,(int)offset);
-
- sum_update(data,i);
-
- if (fd != -1 && write_file(fd,data,i) != i) {
- rprintf(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)
- rprintf(FINFO,"chunk[%d] of size %d at %d offset=%d\n",
- i,len,(int)offset2,(int)offset);
-
- map = map_ptr(buf,offset2,len);
-
- see_token(map, len);
- sum_update(map,len);
-
- if (fd != -1 && write_file(fd,map,len) != len) {
- rprintf(FERROR,"write failed on %s : %s\n",fname,strerror(errno));
- exit_cleanup(1);
- }
- offset += len;
- }
- }
-
- if (fd != -1 && offset > 0 && sparse_end(fd) != 0) {
- rprintf(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,MD4_SUM_LENGTH);
- if (verbose > 2)
- rprintf(FINFO,"got file_sum\n");
- if (fd != -1 && memcmp(file_sum1,file_sum2,MD4_SUM_LENGTH) != 0)
- return 0;
- }
- return 1;
-}
-
-
-static void delete_one(struct file_struct *f)
-{
- if (!S_ISDIR(f->mode)) {
- if (do_unlink(f_name(f)) != 0) {
- rprintf(FERROR,"unlink %s : %s\n",f_name(f),strerror(errno));
- } else if (verbose) {
- rprintf(FINFO,"deleting %s\n",f_name(f));
- }
- } else {
- if (do_rmdir(f_name(f)) != 0) {
- if (errno != ENOTEMPTY && errno != EEXIST)
- rprintf(FERROR,"rmdir %s : %s\n",f_name(f),strerror(errno));
- } else if (verbose) {
- rprintf(FINFO,"deleting directory %s\n",f_name(f));
- }
- }
-}
-
-
-
-static struct delete_list {
- dev_t dev;
- ino_t inode;
-} *delete_list;
-static int dlist_len, dlist_alloc_len;
-
-static void add_delete_entry(struct file_struct *file)
-{
- if (dlist_len == dlist_alloc_len) {
- dlist_alloc_len += 1024;
- if (!delete_list) {
- delete_list = (struct delete_list *)malloc(sizeof(delete_list[0])*dlist_alloc_len);
- } else {
- delete_list = (struct delete_list *)realloc(delete_list, sizeof(delete_list[0])*dlist_alloc_len);