From 9b8d6e752767e286ccc847f03518dec5af9abbc5 Mon Sep 17 00:00:00 2001
From: Rob Day <robertkday@gmail.com>
Date: Wed, 22 Aug 2012 23:04:19 +0100
Subject: [PATCH 1/2] rm: add test to check that rm -d -i works

---
 tests/Makefile.am |  1 +
 tests/rm/d-3      | 37 +++++++++++++++++++++++++++++++++++++
 2 files changed, 38 insertions(+)
 create mode 100755 tests/rm/d-3

diff --git a/tests/Makefile.am b/tests/Makefile.am
index acd816d..87d6cad 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -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					\
diff --git a/tests/rm/d-3 b/tests/rm/d-3
new file mode 100755
index 0000000..6ec067d
--- /dev/null
+++ b/tests/rm/d-3
@@ -0,0 +1,37 @@
+#!/bin/sh
+# Ensure that 'rm -d dir' (i.e., without --recursive) gives a reasonable
+# diagnostic when failing.
+
+# 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
-- 
1.7.11.2


From 86d479f33bfe49c2fa2b95465012e501e35ae5b1 Mon Sep 17 00:00:00 2001
From: Rob Day <robertkday@gmail.com>
Date: Wed, 22 Aug 2012 23:06:55 +0100
Subject: [PATCH 2/2] rm: fixed bug #12260 (rm -d -i)

---
 src/remove.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/remove.c b/src/remove.c
index c4972ac..2f9e86b 100644
--- a/src/remove.c
+++ b/src/remove.c
@@ -238,7 +238,9 @@ prompt (FTS const *fts, FTSENT const *ent, bool is_dir,
             break;
 
           case DT_DIR:
-            if (!x->recursive)
+            if (!x->recursive
+                && !(x->remove_empty_directories
+                     && is_empty_dir (fts->fts_cwd_fd, ent->fts_accpath)))
               {
                 write_protected = -1;
                 wp_errno = EISDIR;
-- 
1.7.11.2

