···11+From e8b56ebd536e82b15542a00c888109471936bfda Mon Sep 17 00:00:00 2001
22+From: =?UTF-8?q?P=C3=A1draig=20Brady?= <P@draigBrady.com>
33+Date: Fri, 24 Sep 2021 20:57:41 +0100
44+Subject: [PATCH] chmod: fix exit status when ignoring symlinks
55+66+* src/chmod.c: Reorder enum so CH_NOT_APPLIED
77+can be treated as a non error.
88+* tests/chmod/ignore-symlink.sh: A new test.
99+* tests/local.mk: Reference the new test.
1010+* NEWS: Mention the bug fix.
1111+Fixes https://bugs.gnu.org/50784
1212+---
1313+ NEWS | 6 ++++++
1414+ src/chmod.c | 4 ++--
1515+ tests/chmod/ignore-symlink.sh | 31 +++++++++++++++++++++++++++++++
1616+ tests/local.mk | 1 +
1717+ 4 files changed, 40 insertions(+), 2 deletions(-)
1818+ create mode 100755 tests/chmod/ignore-symlink.sh
1919+2020+diff --git a/NEWS b/NEWS
2121+index a1470a7d7..1cb3c28a1 100644
2222+--- a/NEWS
2323++++ b/NEWS
2424+@@ -2,6 +2,12 @@ GNU coreutils NEWS -*- outline -*-
2525+2626+ * Noteworthy changes in release ?.? (????-??-??) [?]
2727+2828++** Bug fixes
2929++
3030++ chmod -R no longer exits with error status when encountering symlinks.
3131++ All files would be processed correctly, but the exit status was incorrect.
3232++ [bug introduced in coreutils-9.0]
3333++
3434+3535+ * Noteworthy changes in release 9.0 (2021-09-24) [stable]
3636+3737+diff --git a/src/chmod.c b/src/chmod.c
3838+index 37b04f500..57ac47f33 100644
3939+--- a/src/chmod.c
4040++++ b/src/chmod.c
4141+@@ -44,8 +44,8 @@ struct change_status
4242+ enum
4343+ {
4444+ CH_NO_STAT,
4545+- CH_NOT_APPLIED,
4646+ CH_FAILED,
4747++ CH_NOT_APPLIED,
4848+ CH_NO_CHANGE_REQUESTED,
4949+ CH_SUCCEEDED
5050+ }
5151+@@ -322,7 +322,7 @@ process_file (FTS *fts, FTSENT *ent)
5252+ if ( ! recurse)
5353+ fts_set (fts, ent, FTS_SKIP);
5454+5555+- return CH_NO_CHANGE_REQUESTED <= ch.status;
5656++ return CH_NOT_APPLIED <= ch.status;
5757+ }
5858+5959+ /* Recursively change the modes of the specified FILES (the last entry
6060+diff --git a/tests/chmod/ignore-symlink.sh b/tests/chmod/ignore-symlink.sh
6161+new file mode 100755
6262+index 000000000..5ce3de816
6363+--- /dev/null
6464++++ b/tests/chmod/ignore-symlink.sh
6565+@@ -0,0 +1,31 @@
6666++#!/bin/sh
6767++# Test for proper exit code of chmod on a processed symlink.
6868++
6969++# Copyright (C) 2021 Free Software Foundation, Inc.
7070++
7171++# This program is free software: you can redistribute it and/or modify
7272++# it under the terms of the GNU General Public License as published by
7373++# the Free Software Foundation, either version 3 of the License, or
7474++# (at your option) any later version.
7575++
7676++# This program is distributed in the hope that it will be useful,
7777++# but WITHOUT ANY WARRANTY; without even the implied warranty of
7878++# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7979++# GNU General Public License for more details.
8080++
8181++# You should have received a copy of the GNU General Public License
8282++# along with this program. If not, see <https://www.gnu.org/licenses/>.
8383++
8484++. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
8585++print_ver_ chmod
8686++
8787++mkdir dir || framework_failure_
8888++touch dir/f || framework_failure_
8989++ln -s f dir/l || framework_failure_
9090++
9191++# This operation ignores symlinks but should succeed.
9292++chmod u+w -R dir 2> out || fail=1
9393++
9494++compare /dev/null out || fail=1
9595++
9696++Exit $fail
9797+diff --git a/tests/local.mk b/tests/local.mk
9898+index 228d0e368..b5b893fb7 100644
9999+--- a/tests/local.mk
100100++++ b/tests/local.mk
101101+@@ -456,6 +456,7 @@ all_tests = \
102102+ tests/chmod/c-option.sh \
103103+ tests/chmod/equal-x.sh \
104104+ tests/chmod/equals.sh \
105105++ tests/chmod/ignore-symlink.sh \
106106+ tests/chmod/inaccessible.sh \
107107+ tests/chmod/octal.sh \
108108+ tests/chmod/setgid.sh \