mirror of
git://git.sv.gnu.org/coreutils.git
synced 2026-08-01 13:38:11 +02:00
rm: fix the new --dir (-d) option to work with -i
* src/remove.c (prompt): Hoist the computation of is_empty, since we'll need it slightly earlier. Before, this function would arrange to fail with EISDIR when processing a directory without --recursive (-r). Adjust the condition to exempt an empty directory when --dir has been specified. Improve comments. * tests/rm/d-3: New file, to ensure that rm -d -i dir works. * tests/Makefile.am (TESTS): Add it. * NEWS (Bug fixes): Mention it. * THANKS.in: Update. Reported by Michael Price in http://bugs.gnu.org/12260
This commit is contained in:
@@ -9,6 +9,10 @@ GNU coreutils NEWS -*- outline -*-
|
||||
it detects this precise type of cycle, diagnoses it as such and
|
||||
eventually exits nonzero.
|
||||
|
||||
rm -i -d now prompts the user then removes an empty directory, rather
|
||||
than ignoring the -d option and failing with an 'Is a directory' error.
|
||||
[bug introduced in coreutils-8.19, with the addition of --dir (-d)]
|
||||
|
||||
|
||||
* Noteworthy changes in release 8.19 (2012-08-20) [stable]
|
||||
|
||||
|
||||
@@ -425,6 +425,7 @@ Michael McFarland sidlon@yahoo.com
|
||||
Michael McLagan mmclagan@invlogic.com
|
||||
Michael Mol mikemol@gmail.com
|
||||
Michael Piefel piefel@informatik.hu-berlin.de
|
||||
Michael Price mprice@atl.lmco.com
|
||||
Michael Steffens michael.steffens@s.netic.de
|
||||
Michael Stummvoll michael@stummi.org
|
||||
Michael Stutz stutz@dsl.org
|
||||
|
||||
+13
-11
@@ -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);
|
||||
|
||||
@@ -101,6 +101,7 @@ TESTS = \
|
||||
misc/ls-time \
|
||||
rm/d-1 \
|
||||
rm/d-2 \
|
||||
rm/d-3 \
|
||||
rm/deep-1 \
|
||||
rm/deep-2 \
|
||||
rm/dir-no-w \
|
||||
|
||||
Executable
+37
@@ -0,0 +1,37 @@
|
||||
#!/bin/sh
|
||||
# Ensure that 'rm -d -i dir' (i.e., without --recursive) gives a prompt and
|
||||
# then deletes the directory if it is empty
|
||||
|
||||
# Copyright (C) 2012 Free Software Foundation, Inc.
|
||||
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
. "${srcdir=.}/init.sh"; path_prepend_ ../src
|
||||
print_ver_ rm
|
||||
|
||||
mkdir d || framework_failure_
|
||||
|
||||
echo "y" | rm -i -d --verbose d > out 2> out.err || fail=1
|
||||
printf "%s" \
|
||||
"rm: remove directory 'd'? " \
|
||||
> exp.err || framework_failure_
|
||||
|
||||
printf "%s\n" \
|
||||
"removed directory: 'd'" \
|
||||
> exp || framework_failure_
|
||||
|
||||
compare exp out || fail=1
|
||||
compare exp.err out.err || fail=1
|
||||
|
||||
Exit $fail
|
||||
Reference in New Issue
Block a user