X-Git-Url: https://mattmccutchen.net/rsync/rsync.git/blobdiff_plain/6ba9279fb2c52280cedaaca94783caf44ae9d324..ddddf27b281eac49139e78f77225f0ce5b2ab0a9:/rsync.c diff --git a/rsync.c b/rsync.c index 82035f5d..5f0cef6c 100644 --- a/rsync.c +++ b/rsync.c @@ -93,7 +93,7 @@ static int delete_file(char *fname) } if (do_rmdir(fname) == 0 || errno == ENOENT) return 0; - if (!force_delete || errno != ENOTEMPTY) { + if (!force_delete || (errno != ENOTEMPTY && errno != EEXIST)) { fprintf(FERROR,"rmdir(%s) : %s\n", fname, strerror(errno)); return -1; } @@ -384,10 +384,10 @@ void recv_generator(char *fname,struct file_list *flist,int i,int f_out) } statret = -1; } - if (statret != 0 && mkdir(fname,file->mode) != 0 && errno != EEXIST) { + if (statret != 0 && do_mkdir(fname,file->mode) != 0 && errno != EEXIST) { if (!(relative_paths && errno==ENOENT && create_directory_path(fname)==0 && - mkdir(fname,file->mode)==0)) { + do_mkdir(fname,file->mode)==0)) { fprintf(FERROR,"mkdir %s : %s (2)\n", fname,strerror(errno)); } @@ -561,7 +561,7 @@ static int receive_data(int f_in,struct map_struct *buf,int fd,char *fname) sum_update(data,i); - if (fd != -1 && write_sparse(fd,data,i) != i) { + if (fd != -1 && write_file(fd,data,i) != i) { fprintf(FERROR,"write failed on %s : %s\n",fname,strerror(errno)); exit_cleanup(1); } @@ -582,7 +582,7 @@ static int receive_data(int f_in,struct map_struct *buf,int fd,char *fname) see_token(map, len); sum_update(map,len); - if (fd != -1 && write_sparse(fd,map,len) != len) { + if (fd != -1 && write_file(fd,map,len) != len) { fprintf(FERROR,"write failed on %s : %s\n",fname,strerror(errno)); exit_cleanup(1); } @@ -618,7 +618,7 @@ static void delete_one(struct file_struct *f) } } else { if (do_rmdir(f_name(f)) != 0) { - if (errno != ENOTEMPTY) + if (errno != ENOTEMPTY && errno != EEXIST) fprintf(FERROR,"rmdir %s : %s\n",f_name(f),strerror(errno)); } else if (verbose) { fprintf(FINFO,"deleting directory %s\n",f_name(f)); @@ -627,57 +627,50 @@ static void delete_one(struct file_struct *f) } -/* yuck! This function wouldn't have been necessary if I had the sorting - algorithm right. Unfortunately fixing the sorting algorithm would introduce - a backward incompatibility as file list indexes are sent over the link. - The aim is to see if a directory has already had the deletion algorithm applied - to it (due to recursion), and if so to skip it. The bisection is to - prevent this being an n^2 algorithm */ -static int delete_already_done(struct file_list *flist,int j) +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) { - int low=0,high=j-1; - char *name; - char *p; + 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); + } + if (!delete_list) out_of_memory("add_delete_entry"); + } - if (j == 0) return 0; + delete_list[dlist_len].dev = file->dev; + delete_list[dlist_len].inode = file->inode; + dlist_len++; - name = strdup(f_name(flist->files[j])); + if (verbose > 3) + fprintf(FINFO,"added %s to delete list\n", f_name(file)); +} - if (!name) { - fprintf(FERROR,"out of memory in delete_already_done"); - exit_cleanup(1); - } +/* yuck! This function wouldn't have been necessary if I had the sorting + algorithm right. Unfortunately fixing the sorting algorithm would introduce + a backward incompatibility as file list indexes are sent over the link. +*/ +static int delete_already_done(struct file_list *flist,int j) +{ + int i; + struct stat st; - p = strrchr(name,'/'); - if (!p) { - free(name); - return 0; - } - *p = 0; + if (link_stat(f_name(flist->files[j]), &st)) return 1; - while (low != high) { - int mid = (low+high)/2; - int ret = strcmp(f_name(flist->files[flist_up(flist, mid)]),name); - if (ret == 0) { - free(name); + for (i=0;i 0) { - high=mid; - } else { - low=mid+1; - } } - low = flist_up(flist, low); - - if (strcmp(f_name(flist->files[low]),name) == 0) { - free(name); - return 1; - } - - free(name); return 0; } @@ -687,38 +680,45 @@ static int delete_already_done(struct file_list *flist,int j) 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; + struct file_list *local_file_list; + int i, j; + char *name; - if (cvs_exclude) - add_cvs_excludes(); + if (cvs_exclude) + add_cvs_excludes(); - if (io_error) { - fprintf(FINFO,"IO error encountered - skipping file deletion\n"); - return; - } + if (io_error) { + fprintf(FINFO,"IO error encountered - skipping file deletion\n"); + return; + } - for (j=0;jcount;j++) { - char *name = f_name(flist->files[j]); + for (j=0;jcount;j++) { + if (!S_ISDIR(flist->files[j]->mode) || + !(flist->files[j]->flags & FLAG_DELETE)) continue; - if (!S_ISDIR(flist->files[j]->mode)) continue; + if (delete_already_done(flist, j)) continue; - if (delete_already_done(flist, j)) continue; + name = strdup(f_name(flist->files[j])); - if (!(local_file_list = send_file_list(-1,1,&name))) - continue; + if (!(local_file_list = send_file_list(-1,1,&name))) { + free(name); + continue; + } - if (verbose > 1) - fprintf(FINFO,"deleting in %s\n", name); + if (verbose > 1) + fprintf(FINFO,"deleting in %s\n", name); - for (i=local_file_list->count-1;i>=0;i--) { - if (!local_file_list->files[i]->basename) continue; - if (-1 == flist_find(flist,local_file_list->files[i])) { - delete_one(local_file_list->files[i]); - } - } - flist_free(local_file_list); - } + for (i=local_file_list->count-1;i>=0;i--) { + if (!local_file_list->files[i]->basename) continue; + if (S_ISDIR(local_file_list->files[i]->mode)) + add_delete_entry(local_file_list->files[i]); + if (-1 == flist_find(flist,local_file_list->files[i])) { + delete_one(local_file_list->files[i]); + } + } + flist_free(local_file_list); + free(name); + } } static char *cleanup_fname; @@ -834,7 +834,7 @@ int recv_files(int f_in,struct file_list *flist,char *local_name,int f_gen) } else { sprintf(fnametmp,"%s.XXXXXX",fname); } - if (NULL == mktemp(fnametmp)) { + if (NULL == do_mktemp(fnametmp)) { fprintf(FERROR,"mktemp %s failed\n",fnametmp); receive_data(f_in,buf,-1,NULL); if (buf) unmap_file(buf); @@ -878,14 +878,14 @@ int recv_files(int f_in,struct file_list *flist,char *local_name,int f_gen) continue; } sprintf(fnamebak,"%s%s",fname,backup_suffix); - if (rename(fname,fnamebak) != 0 && errno != ENOENT) { + if (do_rename(fname,fnamebak) != 0 && errno != ENOENT) { fprintf(FERROR,"rename %s %s : %s\n",fname,fnamebak,strerror(errno)); continue; } } /* move tmp file over real file */ - if (rename(fnametmp,fname) != 0) { + if (do_rename(fnametmp,fname) != 0) { if (errno == EXDEV) { /* rename failed on cross-filesystem link. Copy the file instead. */