X-Git-Url: https://mattmccutchen.net/rsync/rsync.git/blobdiff_plain/0a25de67e99a5eee1b35b0e5ddb359f9a3500ce4..d6e6ecbdbf0452ec95afc98c2700076e39b4692f:/rsync.c diff --git a/rsync.c b/rsync.c index c1ce0b5c..16a7a31b 100644 --- a/rsync.c +++ b/rsync.c @@ -72,15 +72,15 @@ static int delete_file(char *fname) struct dirent *di; char buf[MAXPATHLEN]; extern int force_delete; - struct stat st; + STRUCT_STAT st; int ret; if (do_unlink(fname) == 0 || errno == ENOENT) return 0; #if SUPPORT_LINKS - ret = lstat(fname, &st); + ret = do_lstat(fname, &st); #else - ret = stat(fname, &st); + ret = do_stat(fname, &st); #endif if (ret) { fprintf(FERROR,"stat(%s) : %s\n", fname, strerror(errno)); @@ -107,12 +107,13 @@ static int delete_file(char *fname) } for (di=readdir(d); di; di=readdir(d)) { - if (strcmp(di->d_name,".")==0 || - strcmp(di->d_name,"..")==0) + char *dname = d_name(di); + if (strcmp(dname,".")==0 || + strcmp(dname,"..")==0) continue; - strncpy(buf, fname, (MAXPATHLEN-strlen(di->d_name))-2); + strncpy(buf, fname, (MAXPATHLEN-strlen(dname))-2); strcat(buf, "/"); - strcat(buf, di->d_name); + strcat(buf, dname); buf[MAXPATHLEN-1] = 0; if (verbose > 0) fprintf(FINFO,"deleting %s\n", buf); @@ -158,14 +159,14 @@ static void send_sums(struct sum_struct *s,int f_out) generate approximately one checksum every n bytes */ -static struct sum_struct *generate_sums(struct map_struct *buf,off_t len,int n) +static struct sum_struct *generate_sums(struct map_struct *buf,OFF_T len,int n) { int i; struct sum_struct *s; int count; int block_len = n; int remainder = (len%block_len); - off_t offset = 0; + OFF_T offset = 0; count = (len+(block_len-1))/block_len; @@ -219,7 +220,7 @@ static struct sum_struct *receive_sums(int f) { struct sum_struct *s; int i; - off_t offset = 0; + OFF_T offset = 0; s = (struct sum_struct *)malloc(sizeof(*s)); if (!s) out_of_memory("receive_sums"); @@ -264,11 +265,11 @@ static struct sum_struct *receive_sums(int f) } -static int set_perms(char *fname,struct file_struct *file,struct stat *st, +static int set_perms(char *fname,struct file_struct *file,STRUCT_STAT *st, int report) { int updated = 0; - struct stat st2; + STRUCT_STAT st2; if (dry_run) return 0; @@ -329,7 +330,7 @@ static int set_perms(char *fname,struct file_struct *file,struct stat *st, /* choose whether to skip a particular file */ static int skip_file(char *fname, - struct file_struct *file, struct stat *st) + struct file_struct *file, STRUCT_STAT *st) { if (st->st_size != file->length) { return 0; @@ -364,7 +365,7 @@ int adapt_block_size(struct file_struct *file, int bsize) void recv_generator(char *fname,struct file_list *flist,int i,int f_out) { int fd; - struct stat st; + STRUCT_STAT st; struct map_struct *buf; struct sum_struct *s; int statret; @@ -541,8 +542,8 @@ void recv_generator(char *fname,struct file_list *flist,int i,int f_out) 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; + OFF_T offset = 0; + OFF_T offset2; char *data; static char file_sum1[MD4_SUM_LENGTH]; static char file_sum2[MD4_SUM_LENGTH]; @@ -627,61 +628,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) -{ - int low=0,high=j-1; - char *name; - char *p; +static struct delete_list { + dev_t dev; + ino_t inode; +} *delete_list; +static int dlist_len, dlist_alloc_len; - if (j == 0) return 0; - - name = strdup(f_name(flist->files[j])); - - if (!name) { - fprintf(FERROR,"out of memory in delete_already_done"); - exit_cleanup(1); +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); + } + if (!delete_list) out_of_memory("add_delete_entry"); } - name[strlen(name)-2] = 0; + delete_list[dlist_len].dev = file->dev; + delete_list[dlist_len].inode = file->inode; + dlist_len++; - p = strrchr(name,'/'); - if (!p) { - free(name); - return 0; - } - *p = 0; - - strcat(name,"/."); + if (verbose > 3) + fprintf(FINFO,"added %s to delete list\n", f_name(file)); +} - 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); - return 1; - } - if (ret > 0) { - high=mid; - } else { - low=mid+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; - low = flist_up(flist, low); + if (link_stat(f_name(flist->files[j]), &st)) return 1; - if (strcmp(f_name(flist->files[low]),name) == 0) { - free(name); - return 1; + for (i=0;icount;j++) { - char *name = f_name(flist->files[j]); + if (io_error) { + fprintf(FINFO,"IO error encountered - skipping file deletion\n"); + return; + } - if (!S_ISDIR(flist->files[j]->mode)) continue; + for (j=0;jcount;j++) { + if (!S_ISDIR(flist->files[j]->mode) || + !(flist->files[j]->flags & FLAG_DELETE)) continue; - if (strlen(name)<2 || strcmp(name+strlen(name)-2,"/.")!=0) 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; @@ -749,7 +744,7 @@ void sig_int(void) int recv_files(int f_in,struct file_list *flist,char *local_name,int f_gen) { int fd1,fd2; - struct stat st; + STRUCT_STAT st; char *fname; char fnametmp[MAXPATHLEN]; struct map_struct *buf; @@ -800,7 +795,7 @@ int recv_files(int f_in,struct file_list *flist,char *local_name,int f_gen) /* open the file */ fd1 = open(fname,O_RDONLY); - if (fd1 != -1 && fstat(fd1,&st) != 0) { + if (fd1 != -1 && do_fstat(fd1,&st) != 0) { fprintf(FERROR,"fstat %s : %s\n",fname,strerror(errno)); receive_data(f_in,NULL,-1,NULL); close(fd1); @@ -950,7 +945,7 @@ void send_files(struct file_list *flist,int f_out,int f_in) int fd; struct sum_struct *s; struct map_struct *buf; - struct stat st; + STRUCT_STAT st; char fname[MAXPATHLEN]; int i; struct file_struct *file; @@ -1021,7 +1016,7 @@ void send_files(struct file_list *flist,int f_out,int f_in) } /* map the local file */ - if (fstat(fd,&st) != 0) { + if (do_fstat(fd,&st) != 0) { io_error = 1; fprintf(FERROR,"fstat failed : %s\n",strerror(errno)); free_sums(s);