diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/remove.c | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/src/remove.c b/src/remove.c index c4972ace2..69faae6de 100644 --- a/src/remove.c +++ b/src/remove.c @@ -190,6 +190,13 @@ prompt (FTS const *fts, FTSENT const *ent, bool is_dir, int dirent_type = is_dir ? DT_DIR : DT_UNKNOWN; int write_protected = 0; + bool is_empty = false; + if (is_empty_p) + { + is_empty = is_empty_dir (fd_cwd, filename); + *is_empty_p = is_empty ? T_YES : T_NO; + } + /* When nonzero, this indicates that we failed to remove a child entry, either because the user declined an interactive prompt, or due to some other failure, like permissions. */ @@ -238,7 +245,10 @@ prompt (FTS const *fts, FTSENT const *ent, bool is_dir, break; case DT_DIR: - if (!x->recursive) + /* Unless we're either deleting directories or deleting + recursively, we want to raise an EISDIR error rather than + prompting the user */ + if ( ! (x->recursive || (x->remove_empty_directories && is_empty))) { write_protected = -1; wp_errno = EISDIR; @@ -254,15 +264,6 @@ prompt (FTS const *fts, FTSENT const *ent, bool is_dir, return RM_ERROR; } - bool is_empty; - if (is_empty_p) - { - is_empty = is_empty_dir (fd_cwd, filename); - *is_empty_p = is_empty ? T_YES : T_NO; - } - else - is_empty = false; - /* Issue the prompt. */ if (dirent_type == DT_DIR && mode == PA_DESCEND_INTO_DIR @@ -420,7 +421,8 @@ rm_fts (FTS *fts, FTSENT *ent, struct rm_options const *x) { /* This is the first (pre-order) encounter with a directory that we cannot delete. - Not recursive, so arrange to skip contents. */ + Not recursive, and it's not an empty directory (if we're removing + them) so arrange to skip contents. */ int err = x->remove_empty_directories ? ENOTEMPTY : EISDIR; error (0, err, _("cannot remove %s"), quote (ent->fts_path)); mark_ancestor_dirs (ent); |