- if (ret) {
- fprintf(FERROR,"stat(%s) : %s\n", fname, strerror(errno));
- return -1;
- }
-
- if (!S_ISDIR(st.st_mode)) {
- fprintf(FERROR,"unlink(%s) : %s\n", fname, strerror(errno));
- return -1;
- }
-
- if (do_rmdir(fname) == 0 || errno == ENOENT) return 0;
- if (!force_delete || errno != ENOTEMPTY) {
- fprintf(FERROR,"rmdir(%s) : %s\n", fname, strerror(errno));
- return -1;
- }
-
- /* now we do a recsursive delete on the directory ... */
- d = opendir(fname);
- if (!d) {
- fprintf(FERROR,"opendir(%s): %s\n",
- fname,strerror(errno));
- return -1;
- }
-
- for (di=readdir(d); di; di=readdir(d)) {
- if (strcmp(di->d_name,".")==0 ||
- strcmp(di->d_name,"..")==0)
- continue;
- strncpy(buf, fname, (MAXPATHLEN-strlen(di->d_name))-2);
- strcat(buf, "/");
- strcat(buf, di->d_name);
- buf[MAXPATHLEN-1] = 0;
- if (verbose > 0)
- fprintf(FINFO,"deleting %s\n", buf);
- if (delete_file(buf) != 0) {
- closedir(d);
- return -1;
- }
- }
-
- closedir(d);
-
- if (do_rmdir(fname) != 0) {
- fprintf(FERROR,"rmdir(%s) : %s\n", fname, strerror(errno));
- return -1;
- }
-
- return 0;
-}
-
-/*
- send a sums struct down a fd
- */
-static void send_sums(struct sum_struct *s,int f_out)
-{
- int i;
-
- /* tell the other guy how many we are going to be doing and how many
- bytes there are in the last chunk */
- write_int(f_out,s?s->count:0);
- write_int(f_out,s?s->n:block_size);
- write_int(f_out,s?s->remainder:0);
- if (s)
- for (i=0;i<s->count;i++) {
- write_int(f_out,s->sums[i].sum1);
- write_buf(f_out,s->sums[i].sum2,csum_length);
- }
- write_flush(f_out);
-}
-
-
-/*
- generate a stream of signatures/checksums that describe a buffer
-
- generate approximately one checksum every n bytes
- */
-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;
-
- count = (len+(block_len-1))/block_len;
-
- s = (struct sum_struct *)malloc(sizeof(*s));
- if (!s) out_of_memory("generate_sums");
-
- s->count = count;
- s->remainder = remainder;
- s->n = n;
- s->flength = len;
-
- if (count==0) {
- s->sums = NULL;
- return s;
- }
-
- if (verbose > 3)
- fprintf(FERROR,"count=%d rem=%d n=%d flength=%d\n",
- s->count,s->remainder,s->n,(int)s->flength);
-
- s->sums = (struct sum_buf *)malloc(sizeof(s->sums[0])*s->count);
- if (!s->sums) out_of_memory("generate_sums");
-
- for (i=0;i<count;i++) {
- int n1 = MIN(len,n);
- char *map = map_ptr(buf,offset,n1);
-
- s->sums[i].sum1 = get_checksum1(map,n1);
- get_checksum2(map,n1,s->sums[i].sum2);
-
- s->sums[i].offset = offset;
- s->sums[i].len = n1;
- s->sums[i].i = i;
-
- if (verbose > 3)
- fprintf(FERROR,"chunk[%d] offset=%d len=%d sum1=%08x\n",
- i,(int)s->sums[i].offset,s->sums[i].len,s->sums[i].sum1);
-
- len -= n1;
- offset += n1;
- }
-
- return s;