-
-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);
-
- see_token(map, len);
- sum_update(map,len);
-
- if (fd != -1 && write_sparse(fd,map,len) != len) {
- fprintf(FERROR,"write failed on %s : %s\n",fname,strerror(errno));
- exit_cleanup(1);
- }
- offset += len;
- }
- }
-
- if (fd != -1 && 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,MD4_SUM_LENGTH);
- if (verbose > 2)
- fprintf(FERROR,"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 (!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);
- }
- }
-}
-
-
-/* this deletes any files on the receiving side that are not present
- on the sending side. For version 1.6.4 I have changed the behaviour
- to match more closely what most people seem to expect of this option */
-static void delete_files(struct file_list *flist)
-{
- struct file_list *local_file_list;
- int i, j;
- char *last_name=NULL;
-
- if (cvs_exclude)
- add_cvs_excludes();
-
- for (j=0;j<flist->count;j++) {
- if (!S_ISDIR(flist->files[j].mode)) continue;
- if (strcmp(flist->files[j].name,".")==0) continue;
- if (last_name &&
- flist->files[j].name[strlen(last_name)] == '/' &&
- strncmp(flist->files[j].name,last_name, strlen(last_name))==0)
- continue;
- last_name = flist->files[j].name;
- if (!(local_file_list = send_file_list(-1,1,&last_name)))
- continue;
- if (verbose > 1)
- fprintf(FINFO,"deleting in %s\n", last_name);
-
- for (i=local_file_list->count-1;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]);
- }
- }
- }
-}
-
-static char *cleanup_fname = NULL;
-
-void exit_cleanup(int code)
-{
- if (cleanup_fname)
- unlink(cleanup_fname);
- signal(SIGUSR1, SIG_IGN);
- if (code) {
-#ifdef GETPGRP_VOID
- kill(-getpgrp(), SIGUSR1);
-#else
- kill(-getpgrp(getpid()), SIGUSR1);
-#endif
- }
- exit(code);
-}
-