Blame SOURCES/coreutils-8.32-rm-stray-skip.patch

8cf838
From 11b37b65d08c2a8b6d967fd866ebbdbe7e864949 Mon Sep 17 00:00:00 2001
8cf838
From: Nishant Nayan <nishant.nayan@oracle.com>
8cf838
Date: Thu, 26 Nov 2020 14:35:17 +0000
8cf838
Subject: [PATCH] rm: do not skip files upon failure to remove an empty dir
8cf838
8cf838
When removing a directory fails for some reason, and that directory
8cf838
is empty, the rm_fts code gets the return value of the excise call
8cf838
confused with the return value of its earlier call to prompt,
8cf838
causing fts_skip_tree to be called again and the next file
8cf838
that rm would otherwise have deleted to survive.
8cf838
8cf838
* src/remove.c (rm_fts): Ensure we only skip a single fts entry,
8cf838
when processing empty dirs.  I.e. only skip the entry
8cf838
having successfully removed it.
8cf838
* tests/rm/empty-immutable-skip.sh: New root-only test.
8cf838
* tests/local.mk: Add it.
8cf838
* NEWS: Mention the bug fix.
8cf838
Fixes https://bugs.gnu.org/44883
8cf838
8cf838
Upstream-commit: 6bf108358a6104ec1c694c9530b3cd56b95f4b57
8cf838
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
8cf838
---
8cf838
 src/remove.c                     |  3 ++-
8cf838
 tests/local.mk                   |  1 +
8cf838
 tests/rm/empty-immutable-skip.sh | 46 ++++++++++++++++++++++++++++++++
8cf838
 3 files changed, 49 insertions(+), 1 deletion(-)
8cf838
 create mode 100755 tests/rm/empty-immutable-skip.sh
8cf838
8cf838
diff --git a/src/remove.c b/src/remove.c
8cf838
index 2d40c55..adf9489 100644
8cf838
--- a/src/remove.c
8cf838
+++ b/src/remove.c
8cf838
@@ -506,7 +506,8 @@ rm_fts (FTS *fts, FTSENT *ent, struct rm_options const *x)
8cf838
             /* When we know (from prompt when in interactive mode)
8cf838
                that this is an empty directory, don't prompt twice.  */
8cf838
             s = excise (fts, ent, x, true);
8cf838
-            fts_skip_tree (fts, ent);
8cf838
+            if (s == RM_OK)
8cf838
+              fts_skip_tree (fts, ent);
8cf838
           }
8cf838
 
8cf838
         if (s != RM_OK)
8cf838
diff --git a/tests/local.mk b/tests/local.mk
8cf838
index 5f7f775..2aeff2b 100644
8cf838
--- a/tests/local.mk
8cf838
+++ b/tests/local.mk
8cf838
@@ -136,6 +136,7 @@ all_root_tests =				\
8cf838
   tests/rm/no-give-up.sh			\
8cf838
   tests/rm/one-file-system.sh			\
8cf838
   tests/rm/read-only.sh				\
8cf838
+  tests/rm/empty-immutable-skip.sh		\
8cf838
   tests/tail-2/append-only.sh			\
8cf838
   tests/tail-2/end-of-device.sh			\
8cf838
   tests/touch/now-owned-by-other.sh
8cf838
diff --git a/tests/rm/empty-immutable-skip.sh b/tests/rm/empty-immutable-skip.sh
8cf838
new file mode 100755
8cf838
index 0000000..c91d8d4
8cf838
--- /dev/null
8cf838
+++ b/tests/rm/empty-immutable-skip.sh
8cf838
@@ -0,0 +1,46 @@
8cf838
+#!/bin/sh
8cf838
+# Ensure that rm does not skip extra files after hitting an empty immutable dir.
8cf838
+# Requires root access to do chattr +i, as well as an ext[23] or xfs file system
8cf838
+
8cf838
+# Copyright (C) 2020 Free Software Foundation, Inc.
8cf838
+
8cf838
+# This program is free software: you can redistribute it and/or modify
8cf838
+# it under the terms of the GNU General Public License as published by
8cf838
+# the Free Software Foundation, either version 3 of the License, or
8cf838
+# (at your option) any later version.
8cf838
+
8cf838
+# This program is distributed in the hope that it will be useful,
8cf838
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
8cf838
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
8cf838
+# GNU General Public License for more details.
8cf838
+
8cf838
+# You should have received a copy of the GNU General Public License
8cf838
+# along with this program.  If not, see <https://www.gnu.org/licenses/>.
8cf838
+
8cf838
+. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
8cf838
+print_ver_ rm
8cf838
+require_root_
8cf838
+
8cf838
+# These simple one-file operations are expected to work even in the
8cf838
+# presence of this bug, and we need them to set up the rest of the test.
8cf838
+chattr_i_works=1
8cf838
+touch f
8cf838
+chattr +i f 2>/dev/null || chattr_i_works=0
8cf838
+rm f 2>/dev/null
8cf838
+test -f f || chattr_i_works=0
8cf838
+chattr -i f 2>/dev/null || chattr_i_works=0
8cf838
+rm f 2>/dev/null || chattr_i_works=0
8cf838
+test -f f && chattr_i_works=0
8cf838
+
8cf838
+if test $chattr_i_works = 0; then
8cf838
+  skip_ "chattr +i doesn't work on this file system"
8cf838
+fi
8cf838
+
8cf838
+mkdir empty || framework_failure_
8cf838
+touch x y || framework_failure_
8cf838
+chattr +i empty || framework_failure_
8cf838
+rm -rf empty x y
8cf838
+{ test -f x || test -f y; } && fail=1
8cf838
+chattr -i empty
8cf838
+
8cf838
+Exit $fail
8cf838
-- 
8cf838
2.26.2
8cf838