1#!/bin/sh 2# Check whether cp generates files with correct modes. 3 4# Copyright (C) 2002-2023 Free Software Foundation, Inc. 5 6# This program is free software: you can redistribute it and/or modify 7# it under the terms of the GNU General Public License as published by 8# the Free Software Foundation, either version 3 of the License, or 9# (at your option) any later version. 10 11# This program is distributed in the hope that it will be useful, 12# but WITHOUT ANY WARRANTY; without even the implied warranty of 13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14# GNU General Public License for more details. 15 16# You should have received a copy of the GNU General Public License 17# along with this program. If not, see <https://www.gnu.org/licenses/>. 18 19. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src 20print_ver_ cp 21 22get_mode() { stat -c%f "$1"; } 23 24umask 0022 || framework_failure_ 25 26#regular file test 27touch a b || framework_failure_ 28chmod 600 b || framework_failure_ 29cp --no-preserve=mode b c || fail=1 30test "$(get_mode a)" = "$(get_mode c)" || fail=1 31 32#existing destination test 33chmod 600 c || framework_failure_ 34cp --no-preserve=mode a b || fail=1 35test "$(get_mode b)" = "$(get_mode c)" || fail=1 36 37#directory test 38mkdir d1 d2 || framework_failure_ 39chmod 705 d2 || framework_failure_ 40cp --no-preserve=mode -r d2 d3 || fail=1 41test "$(get_mode d1)" = "$(get_mode d3)" || fail=1 42 43#contradicting options test 44rm -f a b || framework_failure_ 45touch a || framework_failure_ 46chmod 600 a || framework_failure_ 47cp --no-preserve=mode --preserve=all a b || fail=1 48test "$(get_mode a)" = "$(get_mode b)" || fail=1 49 50#fifo test 51if mkfifo fifo; then 52 cp -a --no-preserve=mode fifo fifo_copy || fail=1 53 #ensure default perms set appropriate for non regular files 54 #which wasn't done between v8.20 and 8.29 inclusive 55 test "$(get_mode fifo)" = "$(get_mode fifo_copy)" || fail=1 56fi 57 58# Test that plain --preserve=ownership does not affect destination mode. 59rm -f a b c || framework_failure_ 60touch a || framework_failure_ 61chmod 660 a || framework_failure_ 62cp a b || fail=1 63cp --preserve=ownership a c || fail=1 64test "$(get_mode b)" = "$(get_mode c)" || fail=1 65 66Exit $fail 67