X-Git-Url: https://mattmccutchen.net/rsync/rsync.git/blobdiff_plain/2b6b4d539b0aab98b1cbb9d8c639cb12473aae94..4b957c22381cf1848ff6a5e59249bb71ba79e9fa:/flist.c diff --git a/flist.c b/flist.c index 7b2c985c..78b2c859 100644 --- a/flist.c +++ b/flist.c @@ -21,12 +21,13 @@ #include "rsync.h" +extern struct stats stats; + extern int csum_length; extern int verbose; extern int am_server; extern int always_checksum; -extern int64 total_size; extern int cvs_exclude; @@ -90,49 +91,6 @@ static void send_directory(int f,struct file_list *flist,char *dir); static char *flist_dir; -static void clean_fname(char *name) -{ - char *p; - int l; - int modified = 1; - - if (!name) return; - - while (modified) { - modified = 0; - - if ((p=strstr(name,"/./"))) { - modified = 1; - while (*p) { - p[0] = p[2]; - p++; - } - } - - if ((p=strstr(name,"//"))) { - modified = 1; - while (*p) { - p[0] = p[1]; - p++; - } - } - - if (strncmp(p=name,"./",2) == 0) { - modified = 1; - do { - p[0] = p[2]; - } while (*p++); - } - - l = strlen(p=name); - if (l > 1 && p[l-1] == '/') { - modified = 1; - p[l-1] = 0; - } - } -} - - void send_file_entry(struct file_struct *file,int f,unsigned base_flags) { @@ -169,6 +127,11 @@ void send_file_entry(struct file_struct *file,int f,unsigned base_flags) if (l1 > 0) flags |= SAME_NAME; if (l2 > 255) flags |= LONG_NAME; + /* we must make sure we don't send a zero flags byte or the other + end will terminate the flist transfer */ + if (flags == 0 && !S_ISDIR(file->mode)) flags |= FLAG_DELETE; + if (flags == 0) flags |= LONG_NAME; + write_byte(f,flags); if (flags & SAME_NAME) write_byte(f,l1); @@ -248,7 +211,7 @@ static void receive_file_entry(struct file_struct **fptr, file = (struct file_struct *)malloc(sizeof(*file)); if (!file) out_of_memory("receive_file_entry"); - bzero((char *)file,sizeof(*file)); + memset((char *)file, 0, sizeof(*file)); (*fptr) = file; if (l2 >= MAXPATHLEN-l1) overflow("receive_file_entry"); @@ -362,7 +325,7 @@ static struct file_struct *make_file(char *fname) clean_fname(cleaned_name); fname = cleaned_name; - bzero(sum,SUM_LENGTH); + memset(sum,0,SUM_LENGTH); if (link_stat(fname,&st) != 0) { io_error = 1; @@ -389,7 +352,7 @@ static struct file_struct *make_file(char *fname) file = (struct file_struct *)malloc(sizeof(*file)); if (!file) out_of_memory("make_file"); - bzero((char *)file,sizeof(*file)); + memset((char *)file,0,sizeof(*file)); if ((p = strrchr(fname,'/'))) { static char *lastdir; @@ -459,7 +422,7 @@ static struct file_struct *make_file(char *fname) } if (!S_ISDIR(st.st_mode)) - total_size += st.st_size; + stats.total_size += st.st_size; return file; } @@ -561,15 +524,17 @@ struct file_list *send_file_list(int f,int argc,char *argv[]) int i,l; STRUCT_STAT st; char *p,*dir; - char dbuf[MAXPATHLEN]; char lastpath[MAXPATHLEN]=""; struct file_list *flist; + int64 start_write; if (verbose && recurse && !am_server && f != -1) { rprintf(FINFO,"building file list ... "); rflush(FINFO); } + start_write = stats.total_written; + flist = (struct file_list *)malloc(sizeof(flist[0])); if (!flist) out_of_memory("send_file_list"); @@ -641,24 +606,23 @@ struct file_list *send_file_list(int f,int argc,char *argv[]) fname = "."; if (dir && *dir) { - if (getcwd(dbuf,MAXPATHLEN-1) == NULL) { - rprintf(FERROR,"getwd : %s\n",strerror(errno)); - exit_cleanup(1); - } - if (chdir(dir) != 0) { + char *olddir = push_dir(dir, 1); + + if (!olddir) { io_error=1; - rprintf(FERROR,"chdir %s : %s\n", + rprintf(FERROR,"push_dir %s : %s\n", dir,strerror(errno)); continue; } + flist_dir = dir; if (one_file_system) set_filesystem(fname); send_file_name(f,flist,fname,recurse,FLAG_DELETE); flist_dir = NULL; - if (chdir(dbuf) != 0) { - rprintf(FERROR,"chdir %s : %s\n", - dbuf,strerror(errno)); + if (pop_dir(olddir) != 0) { + rprintf(FERROR,"pop_dir %s : %s\n", + dir,strerror(errno)); exit_cleanup(1); } continue; @@ -691,7 +655,8 @@ struct file_list *send_file_list(int f,int argc,char *argv[]) if (f != -1) { io_end_buffering(f); - write_flush(f); + stats.flist_size = stats.total_written - start_write; + stats.num_files = flist->count; } if (verbose > 2) @@ -705,12 +670,15 @@ struct file_list *recv_file_list(int f) { struct file_list *flist; unsigned char flags; + int64 start_read; if (verbose && recurse && !am_server) { rprintf(FINFO,"receiving file list ... "); rflush(FINFO); } + start_read = stats.total_read; + flist = (struct file_list *)malloc(sizeof(flist[0])); if (!flist) goto oom; @@ -741,7 +709,7 @@ struct file_list *recv_file_list(int f) receive_file_entry(&flist->files[i],flags,f); if (S_ISREG(flist->files[i]->mode)) - total_size += flist->files[i]->length; + stats.total_size += flist->files[i]->length; flist->count++; @@ -772,6 +740,9 @@ struct file_list *recv_file_list(int f) if (verbose > 2) rprintf(FINFO,"recv_file_list done\n"); + stats.flist_size = stats.total_read - start_read; + stats.num_files = flist->count; + return flist; oom: @@ -786,8 +757,8 @@ int file_compare(struct file_struct **f1,struct file_struct **f2) if (!(*f1)->basename) return -1; if (!(*f2)->basename) return 1; if ((*f1)->dirname == (*f2)->dirname) - return strcmp((*f1)->basename, (*f2)->basename); - return strcmp(f_name(*f1),f_name(*f2)); + return u_strcmp((*f1)->basename, (*f2)->basename); + return u_strcmp(f_name(*f1),f_name(*f2)); } @@ -823,7 +794,7 @@ static void free_file(struct file_struct *file) if (file->basename) free(file->basename); if (file->link) free(file->link); if (file->sum) free(file->sum); - bzero((char *)file, sizeof(*file)); + memset((char *)file, 0, sizeof(*file)); } @@ -837,9 +808,9 @@ void flist_free(struct file_list *flist) free_file(flist->files[i]); free(flist->files[i]); } - bzero((char *)flist->files, sizeof(flist->files[0])*flist->count); + memset((char *)flist->files, 0, sizeof(flist->files[0])*flist->count); free(flist->files); - bzero((char *)flist, sizeof(*flist)); + memset((char *)flist, 0, sizeof(*flist)); free(flist); }