-extern int do_progress;
-extern char *backup_dir;
-extern char *backup_suffix;
-extern int backup_suffix_len;
-
-static struct delete_list {
- DEV64_T dev;
- INO64_T inode;
-} *delete_list;
-static int dlist_len, dlist_alloc_len;
-
-/* 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;
-
- if (link_stat(f_name(flist->files[j]), &st)) return 1;
-
- for (i=0;i<dlist_len;i++) {
- if (st.st_ino == delete_list[i].inode &&
- st.st_dev == delete_list[i].dev)
- return 1;
- }
-
- return 0;
-}
-
-static void add_delete_entry(struct file_struct *file)
-{
- if (dlist_len == dlist_alloc_len) {
- dlist_alloc_len += 1024;
- delete_list = (struct delete_list *)Realloc(delete_list, sizeof(delete_list[0])*dlist_alloc_len);
- if (!delete_list) out_of_memory("add_delete_entry");
- }
-
- delete_list[dlist_len].dev = file->dev;
- delete_list[dlist_len].inode = file->inode;
- dlist_len++;
-
- if (verbose > 3)
- rprintf(FINFO,"added %s to delete list\n", f_name(file));
-}
-
-static void delete_one(char *fn, int is_dir)
-{
- if (!is_dir) {
- if (robust_unlink(fn) != 0) {
- rprintf(FERROR, "delete_one: unlink %s: %s\n",
- fn, strerror(errno));
- } else if (verbose) {
- rprintf(FINFO, "deleting %s\n", fn);
- }
- } else {
- if (do_rmdir(fn) != 0) {
- if (errno != ENOTEMPTY && errno != EEXIST) {
- rprintf(FERROR, "delete_one: rmdir %s: %s\n",
- fn, strerror(errno));
- }
- } else if (verbose) {
- rprintf(FINFO, "deleting directory %s\n", fn);
- }
- }
-}
-
-
-static int is_backup_file(char *fn)
-{
- int k = strlen(fn) - backup_suffix_len;
- return k > 0 && strcmp(fn+k, backup_suffix) == 0;
-}
-
-
-/* this deletes any files on the receiving side that are not present
- on the sending side. For version 1.6.4 I have changed the behaviour
- to match more closely what most people seem to expect of this option */
-void delete_files(struct file_list *flist)
-{
- struct file_list *local_file_list;
- int i, j;
- char *name;
- extern int module_id;
- extern int ignore_errors;
- extern int max_delete;
- static int deletion_count;
-
- if (cvs_exclude)
- add_cvs_excludes();
-
- if (io_error && !(lp_ignore_errors(module_id) || ignore_errors)) {
- rprintf(FINFO,"IO error encountered - skipping file deletion\n");
- return;
- }
-
- for (j=0;j<flist->count;j++) {
- if (!S_ISDIR(flist->files[j]->mode) ||
- !(flist->files[j]->flags & FLAG_DELETE)) continue;
-
- if (remote_version < 19 &&
- delete_already_done(flist, j)) continue;
-
- name = strdup(f_name(flist->files[j]));
-
- if (!(local_file_list = send_file_list(-1,1,&name))) {
- free(name);
- continue;
- }
-
- if (verbose > 1)
- rprintf(FINFO,"deleting in %s\n", name);
-
- for (i=local_file_list->count-1;i>=0;i--) {
- if (max_delete && deletion_count > max_delete) break;
- if (!local_file_list->files[i]->basename) continue;
- if (remote_version < 19 &&
- 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])) {
- char *f = f_name(local_file_list->files[i]);
- if (make_backups && (backup_dir || !is_backup_file(f))) {
- (void) make_backup(f);
- if (verbose)
- rprintf(FINFO, "deleting %s\n", f);
- } else {
- int mode = local_file_list->files[i]->mode;
- delete_one(f, S_ISDIR(mode) != 0);
- }
- deletion_count++;
- }
- }
- flist_free(local_file_list);
- free(name);
- }
-}