- if (compare_dest != NULL) {
- if (access(fname, 0) != 0) {
- snprintf(fnamecmpdest,MAXPATHLEN,"%s/%s",
- compare_dest,fname);
- fname = fnamecmpdest;
- }
- }
- file_checksum(fname,sum,st->st_size);
- if (protocol_version < 21) {
- return (memcmp(sum,file->sum,2) == 0);
- } else {
- return (memcmp(sum,file->sum,MD4_SUM_LENGTH) == 0);
+ if (max_delete && ++deletion_count > max_delete)
+ return 0;
+
+ if (do_rmdir(fname) == 0) {
+ if (!(flags & DEL_TERSE))
+ log_delete(fname, mode);
+ } else if (errno != ENOTEMPTY && errno != EEXIST && errno != ENOENT) {
+ rsyserr(FERROR, errno, "delete_file: rmdir %s failed",
+ full_fname(fname));
+ return -1;
+ }
+
+ return 0;
+}
+
+
+/* This function is used to implement per-directory deletion, and is used by
+ * all the --delete-WHEN options. Note that the fbuf pointer must point to a
+ * MAXPATHLEN buffer with the name of the directory in it (the functions we
+ * call will append names onto the end, but the old dir value will be restored
+ * on exit). */
+static void delete_in_dir(struct file_list *flist, char *fbuf,
+ struct file_struct *file)
+{
+ static int min_depth = MAXPATHLEN, cur_depth = -1;
+ static void *filt_array[MAXPATHLEN/2+1];
+ static int already_warned = 0;
+ struct file_list *dirlist;
+ char delbuf[MAXPATHLEN];
+ STRUCT_STAT st;
+ int dlen, i;
+
+ if (!flist) {
+ while (cur_depth >= min_depth)
+ pop_local_filters(filt_array[cur_depth--]);
+ min_depth = MAXPATHLEN;
+ cur_depth = -1;
+ return;
+ }
+
+ if (verbose > 2)
+ rprintf(FINFO, "delete_in_dir(%s)\n", safe_fname(fbuf));
+
+ if (allowed_lull)
+ maybe_send_keepalive();
+
+ if (file->dir.depth >= MAXPATHLEN/2+1)
+ return; /* Impossible... */
+
+ if (io_error && !(lp_ignore_errors(module_id) || ignore_errors)) {
+ if (already_warned)
+ return;
+ rprintf(FINFO,
+ "IO error encountered -- skipping file deletion\n");
+ already_warned = 1;
+ return;
+ }
+
+ while (cur_depth >= file->dir.depth && cur_depth >= min_depth)
+ pop_local_filters(filt_array[cur_depth--]);
+ cur_depth = file->dir.depth;
+ if (min_depth > cur_depth)
+ min_depth = cur_depth;
+ dlen = strlen(fbuf);
+ filt_array[cur_depth] = push_local_filters(fbuf, dlen);
+
+ if (link_stat(fbuf, &st, keep_dirlinks) < 0)
+ return;
+
+ if (one_file_system) {
+ if (file->flags & FLAG_TOP_DIR)
+ filesystem_dev = st.st_dev;
+ else if (filesystem_dev != st.st_dev)
+ return;
+ }
+
+ dirlist = get_dirlist(fbuf, dlen, 0);
+
+ /* If an item in dirlist is not found in flist, delete it
+ * from the filesystem. */
+ for (i = dirlist->count; i--; ) {
+ struct file_struct *fp = dirlist->files[i];
+ if (!fp->basename || fp->flags & FLAG_MOUNT_POINT)
+ continue;
+ if (flist_find(flist, fp) < 0) {
+ int mode = fp->mode;
+ f_name_to(fp, delbuf);
+ delete_item(delbuf, mode, DEL_FORCE_RECURSE);