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

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