* gnulib: Update to get the fix. * tests/cp/backup-unreadable.sh: Add a new test case. * tests/local.mk: Reference the new test. * NEWS: Mention the bug fix. --- NEWS | 5 +++++ gnulib | 2 +- tests/cp/backup-unreadable.sh | 42 +++++++++++++++++++++++++++++++++++ tests/local.mk | 1 + 4 files changed, 49 insertions(+), 1 deletion(-) create mode 100755 tests/cp/backup-unreadable.sh
diff --git a/NEWS b/NEWS index d87695071..aea66e5c7 100644 --- a/NEWS +++ b/NEWS @@ -69,6 +69,11 @@ GNU coreutils NEWS -*- outline -*- it creates and their sources. [This bug was present in "the beginning".] + 'cp', 'mv', and 'install' no longer loop indefinitely when creating a + numbered backup in an unreadable directory if the guessed backup name + already exists. They now diagnose the failure and leave the files intact. + [bug introduced in coreutils-8.28] + 'cp', 'mv', and 'install' no longer exit successfully when they fail to create a hole in the destination file. [bug introduced in coreutils-9.8] diff --git a/gnulib b/gnulib index a1f2c658c..fe173e954 160000 --- a/gnulib +++ b/gnulib @@ -1 +1 @@ -Subproject commit a1f2c658c64bbc4b8699189da43af9ffc5f77d66 +Subproject commit fe173e95441f6cead594178df45484424ebac504 diff --git a/tests/cp/backup-unreadable.sh b/tests/cp/backup-unreadable.sh new file mode 100755 index 000000000..327910b43 --- /dev/null +++ b/tests/cp/backup-unreadable.sh @@ -0,0 +1,42 @@ +#!/bin/sh +# Ensure no loop when a numbered backup exists in an unreadable directory. + +# Copyright (C) 2026 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ cp +skip_if_root_ +getlimits_ + +mkdir d && +echo original > original && +echo new > new && +cp original d/file && +chmod a-r d || framework_failure_ +test -r d && skip_ 'cannot make directory unreadable' + +# A backup can still be made if the guessed name is unused. +timeout 10 cp --backup=numbered new d/file || fail=1 + +# But rescanning cannot find another name +returns_ 1 timeout 10 cp --backup=numbered original d/file 2>err || fail=1 +chmod u+r d || framework_failure_ +echo "cp: cannot backup 'd/file': $EEXIST" >exp || framework_failure_ +compare exp err || fail=1 +compare new d/file || fail=1 +compare original d/file.~1~ || fail=1 + +Exit $fail diff --git a/tests/local.mk b/tests/local.mk index 859006a4a..33ba834b7 100644 --- a/tests/local.mk +++ b/tests/local.mk @@ -600,6 +600,7 @@ all_tests = \ tests/cp/backup-1.sh \ tests/cp/backup-dir.sh \ tests/cp/backup-is-src.sh \ + tests/cp/backup-unreadable.sh \ tests/cp/cp-HL.sh \ tests/cp/cp-deref.sh \ tests/cp/cp-i.sh \ -- 2.56.0
