From 24ebca61a3a0f10d6cd2800b188b3c034d1c4755 Mon Sep 17 00:00:00 2001 From: Ondrej Oprala Date: Tue, 7 Aug 2012 16:56:52 +0200 Subject: cp: fix the --no-preserve=mode option The --no-preserve=mode option did not do what its name implies: it would mistakenly preserve permission mode bits. * NEWS: Mention the fix. * TODO: Remove an entry. * src/copy.c (copy_reg): Add a condition to properly handle the --no-preserve=mode option for files (copy_internal): Add a condition to properly handle the --no-preserve=mode option for directories. * src/copy.h (struct cp_options): Add a new boolean. * src/cp.c (cp_option_init,decode_preserve_arg): Set the new boolean value according to specified options. * src/install.c (struct cp_options): Initialize the new boolean. * src/mv.c (struct cp_options): Initialize the new boolean. * tests/cp/preserve-mode.sh: Add a new test. * tests/cp/link-preserve.sh (-a --no-preserve=mode): Adjust the expected perms: now, --no-preserve=mode overrides the --preserve=mode that is inherent in -a, as it should. * tests/local.mk: Add the new test to the list. --- tests/cp/link-preserve.sh | 2 +- tests/cp/preserve-mode.sh | 54 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 1 deletion(-) create mode 100755 tests/cp/preserve-mode.sh (limited to 'tests/cp') diff --git a/tests/cp/link-preserve.sh b/tests/cp/link-preserve.sh index 0c75d305e..bb3b2447e 100755 --- a/tests/cp/link-preserve.sh +++ b/tests/cp/link-preserve.sh @@ -84,7 +84,7 @@ touch a; chmod 731 a umask 077 cp -a --no-preserve=mode a b mode=$(ls -l b|cut -b-10) -test "$mode" = "-rwx------" || fail=1 +test "$mode" = "-rw-------" || fail=1 umask 022 # -------------------------------------- diff --git a/tests/cp/preserve-mode.sh b/tests/cp/preserve-mode.sh new file mode 100755 index 000000000..dc97cbaa0 --- /dev/null +++ b/tests/cp/preserve-mode.sh @@ -0,0 +1,54 @@ +#!/bin/sh +# ensure that cp's --no-preserve=mode works correctly + +# Copyright (C) 2002-2012 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 + +rm -f a b c +umask 0022 +touch a +touch b +chmod 600 b + +#regular file test +cp --no-preserve=mode b c +mode_a=$(ls -l a | gawk '{print $1}') +mode_c=$(ls -l c | gawk '{print $1}') +test "$mode_a" = "$mode_c" || fail=1 + +rm -rf d1 d2 d3 +mkdir d1 d2 +chmod 705 d2 + +#directory test +cp --no-preserve=mode -r d2 d3 +mode_d1=$(ls -l d1 | gawk '{print $1}') +mode_d3=$(ls -l d3 | gawk '{print $1}') +test "$mode_d1" = "$mode_d3" || fail=1 + +rm -f a b c +touch a +chmod 600 a + +#contradicting options test +cp --no-preserve=mode --preserve=all a b +mode_a=$(ls -l a | gawk '{print $1}') +mode_b=$(ls -l b | gawk '{print $1}') +test "$mode_a" = "$mode_b" || fail=1 + +Exit $fail -- cgit v1.2.3-54-g00ecf