blob: d69ee95e4a8cb1ecde5e421307dd5266e8e3fbb1 [file] [log] [blame]
Andrew Geisslereff27472021-10-29 15:35:00 -05001From e8b56ebd536e82b15542a00c888109471936bfda Mon Sep 17 00:00:00 2001
2From: =?UTF-8?q?P=C3=A1draig=20Brady?= <P@draigBrady.com>
3Date: Fri, 24 Sep 2021 20:57:41 +0100
4Subject: [PATCH] chmod: fix exit status when ignoring symlinks
5
6* src/chmod.c: Reorder enum so CH_NOT_APPLIED
7can be treated as a non error.
8* tests/chmod/ignore-symlink.sh: A new test.
9* tests/local.mk: Reference the new test.
10* NEWS: Mention the bug fix.
11Fixes https://bugs.gnu.org/50784
12
13Upstream-Status: Backport
14Signed-off-by: Alexander Kanavin <alex.kanavin@gmail.com>
15---
16 src/chmod.c | 4 ++--
17 tests/chmod/ignore-symlink.sh | 31 +++++++++++++++++++++++++++++++
18 tests/local.mk | 1 +
19 4 files changed, 40 insertions(+), 2 deletions(-)
20 create mode 100755 tests/chmod/ignore-symlink.sh
21
22diff --git a/src/chmod.c b/src/chmod.c
23index 37b04f500..57ac47f33 100644
24--- a/src/chmod.c
25+++ b/src/chmod.c
26@@ -44,8 +44,8 @@ struct change_status
27 enum
28 {
29 CH_NO_STAT,
30- CH_NOT_APPLIED,
31 CH_FAILED,
32+ CH_NOT_APPLIED,
33 CH_NO_CHANGE_REQUESTED,
34 CH_SUCCEEDED
35 }
36@@ -322,7 +322,7 @@ process_file (FTS *fts, FTSENT *ent)
37 if ( ! recurse)
38 fts_set (fts, ent, FTS_SKIP);
39
40- return CH_NO_CHANGE_REQUESTED <= ch.status;
41+ return CH_NOT_APPLIED <= ch.status;
42 }
43
44 /* Recursively change the modes of the specified FILES (the last entry
45diff --git a/tests/chmod/ignore-symlink.sh b/tests/chmod/ignore-symlink.sh
46new file mode 100755
47index 000000000..5ce3de816
48--- /dev/null
49+++ b/tests/chmod/ignore-symlink.sh
50@@ -0,0 +1,31 @@
51+#!/bin/sh
52+# Test for proper exit code of chmod on a processed symlink.
53+
54+# Copyright (C) 2021 Free Software Foundation, Inc.
55+
56+# This program is free software: you can redistribute it and/or modify
57+# it under the terms of the GNU General Public License as published by
58+# the Free Software Foundation, either version 3 of the License, or
59+# (at your option) any later version.
60+
61+# This program is distributed in the hope that it will be useful,
62+# but WITHOUT ANY WARRANTY; without even the implied warranty of
63+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
64+# GNU General Public License for more details.
65+
66+# You should have received a copy of the GNU General Public License
67+# along with this program. If not, see <https://www.gnu.org/licenses/>.
68+
69+. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
70+print_ver_ chmod
71+
72+mkdir dir || framework_failure_
73+touch dir/f || framework_failure_
74+ln -s f dir/l || framework_failure_
75+
76+# This operation ignores symlinks but should succeed.
77+chmod u+w -R dir 2> out || fail=1
78+
79+compare /dev/null out || fail=1
80+
81+Exit $fail
82diff --git a/tests/local.mk b/tests/local.mk
83index 228d0e368..b5b893fb7 100644
84--- a/tests/local.mk
85+++ b/tests/local.mk
86@@ -456,6 +456,7 @@ all_tests = \
87 tests/chmod/c-option.sh \
88 tests/chmod/equal-x.sh \
89 tests/chmod/equals.sh \
90+ tests/chmod/ignore-symlink.sh \
91 tests/chmod/inaccessible.sh \
92 tests/chmod/octal.sh \
93 tests/chmod/setgid.sh \