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

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