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