From 94dcbf8367e98354b51435c8223dbf9ef170ec99 Mon Sep 17 00:00:00 2001 From: Wayne Davison Date: Tue, 22 Feb 2005 03:16:41 +0000 Subject: [PATCH] - Iterate through the deletion list in reverse order so that we can't delete a backup file that we just created. - The rename-directory-for-backup heuristic now checks the DEL_FORCE_RECURSE flag, not the zap_dir variable. We also set the flag when we recurse so that only the root dir of a deleted hierarchy can be missing the flag (and thus be a call from the generator). --- flist.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/flist.c b/flist.c index 0f2f9d08..6f94e8c5 100644 --- a/flist.c +++ b/flist.c @@ -1816,7 +1816,7 @@ int delete_file(char *fname, int mode, int flags) ok = 0; errno = ENOTEMPTY; } else if (make_backups && !backup_dir && !is_backup_file(fname) - && !zap_dir) + && !(flags & DEL_FORCE_RECURSE)) ok = make_backup(fname); else ok = do_rmdir(fname) == 0; @@ -1833,9 +1833,10 @@ int delete_file(char *fname, int mode, int flags) full_fname(fname)); return -1; } + flags |= DEL_FORCE_RECURSE; dirlist = get_dirlist(fname, 0); - for (j = 0; j < dirlist->count; j++) { + for (j = dirlist->count; j-- > 0; ) { struct file_struct *fp = dirlist->files[j]; f_name_to(fp, buf); if (delete_file(buf, fp->mode, flags & ~DEL_TERSE) != 0) { @@ -1882,8 +1883,7 @@ static void delete_missing(struct file_list *full_list, if (flist_find(full_list, dir_list->files[i]) < 0) { char *fn = f_name_to(dir_list->files[i], fbuf); int mode = dir_list->files[i]->mode; - int dflag = S_ISDIR(mode) ? DEL_FORCE_RECURSE : 0; - if (delete_file(fn, mode, dflag) < 0) + if (delete_file(fn, mode, DEL_FORCE_RECURSE) < 0) break; } } -- 2.34.1