From: Sylvestre Ledru Date: Sat, 7 Feb 2026 15:20:46 +0000 (+0100) Subject: tests: cp: ensure read-only dir perms preserved X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5901e4425af621f04ded54d6c5a639414719ce4d;p=thirdparty%2Fcoreutils.git tests: cp: ensure read-only dir perms preserved * tests/cp/readonly-dir.sh: Add new test. * tests/local.mk: Reference new test. Identified here https://github.com/uutils/coreutils/issues/7961 --- diff --git a/tests/cp/readonly-dir.sh b/tests/cp/readonly-dir.sh new file mode 100755 index 0000000000..a9b5379ebc --- /dev/null +++ b/tests/cp/readonly-dir.sh @@ -0,0 +1,65 @@ +#!/bin/sh +# Test cp behavior with readonly directories + +# 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 . + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ cp +skip_if_setgid_ + +umask 022 + +# Test case for readonly directory permission preservation +# This addresses the specific case where 'cp -r' and 'cp -a' should +# preserve readonly directory permissions (555) instead of changing +# them to writable permissions (755). + +# Create test directory structure +mkdir -p a/b/c/d || framework_failure_ +touch a/b/c/d/bar.txt || framework_failure_ +echo "test content" > a/b/c/d/bar.txt || framework_failure_ + +# Make directories readonly (remove write permissions) +chmod -R -w a || framework_failure_ + +# Test 1: cp -r should preserve readonly directory permissions +cp -r a b || fail=1 + +# Check that the root copied directory has readonly permissions +mode_b=$(stat --format=%a b) || fail=1 +test "$mode_b" = "555" || fail=1 + +# Check subdirectories too +mode_bb=$(stat --format=%a b/b) || fail=1 +test "$mode_bb" = "555" || fail=1 + +mode_bbc=$(stat --format=%a b/b/c) || fail=1 +test "$mode_bbc" = "555" || fail=1 + +mode_bbcd=$(stat --format=%a b/b/c/d) || fail=1 +test "$mode_bbcd" = "555" || fail=1 + +# Test 2: cp -a should preserve readonly directory permissions and not fail +cp -a a c || fail=1 + +# Check that cp -a also preserved readonly permissions +mode_c=$(stat --format=%a c) || fail=1 +test "$mode_c" = "555" || fail=1 + +mode_cb=$(stat --format=%a c/b) || fail=1 +test "$mode_cb" = "555" || fail=1 + +Exit $fail diff --git a/tests/local.mk b/tests/local.mk index 60e651b947..c7435d9af2 100644 --- a/tests/local.mk +++ b/tests/local.mk @@ -571,6 +571,7 @@ all_tests = \ tests/cp/proc-short-read.sh \ tests/cp/proc-zero-len.sh \ tests/cp/r-vs-symlink.sh \ + tests/cp/readonly-dir.sh \ tests/cp/reflink-auto.sh \ tests/cp/reflink-perm.sh \ tests/cp/same-file.sh \