From 1af81dfb4d24d104777b8917544d81097db0deab Mon Sep 17 00:00:00 2001 From: Pádraig Brady
Date: Mon, 21 Sep 2009 08:43:03 +0100 Subject: cp: add an option to only copy the file attributes * src/copy.c (copy_attr): A new function which merges copy_attr_by_fd and copy_attr_by_name. Also display all errors when --attributes-only * src/copy.c (copy_reg): Skip copying the file contents if specified. Refactor the SELinux error handling code a little and display all SELinux errors when only copying attributes. * src/copy.h (struct cp_options): Add a data_copy_required boolean * src/cp.c (main): Default to copying data but don't if specified * src/install.c: Default to copying data * src/mv.c: Likewise tests/cp/reflink-perm: Add a test to check that --attributes-only does not copy data * tests/cp/acl: Likewise. Also refactor to remove redundant acl manipulation * doc/coreutils.texi (cp invocation): Describe the new option * NEWS: Mention the new feature --- tests/cp/acl | 22 +++++++++++++--------- tests/cp/reflink-perm | 4 ++++ 2 files changed, 17 insertions(+), 9 deletions(-) (limited to 'tests/cp') diff --git a/tests/cp/acl b/tests/cp/acl index 010348a9d..c19eb4e93 100755 --- a/tests/cp/acl +++ b/tests/cp/acl @@ -36,28 +36,32 @@ grep '^#define USE_ACL 1' $CONFIG_HEADER > /dev/null || mkdir -p a b || framework_failure touch a/file || framework_failure -skip=no # Ensure that setfacl and getfacl work on this file system. +skip=no +acl1=`cd a && getfacl file` || skip=yes setfacl -m user:bin:rw a/file 2> /dev/null || skip=yes -acl1=`cd a && getfacl file | grep -v ':bin:' | grep -v 'mask::'` \ - || skip=yes - test $skip = yes && skip_test_ "'.' is not on a suitable file system for this test" # copy a file without preserving permissions cp a/file b/ || fail=1 - acl2=`cd b && getfacl file` || framework_failure test "$acl1" = "$acl2" || fail=1 -rm a/file || framework_failure -# copy a file, preserving permissions -touch a/file || framework_failure -setfacl -m user:bin:rw a/file || framework_failure +# Update with acl set above acl1=`cd a && getfacl file` || framework_failure + +# copy a file, preserving permissions cp -p a/file b/ || fail=1 acl2=`cd b && getfacl file` || framework_failure test "$acl1" = "$acl2" || fail=1 +# copy a file, preserving permissions, with --attributes-only +echo > a/file || framework_failure # add some data +test -s a/file || framework_failure +cp -p --attributes-only a/file b/ || fail=1 +test -s b/file && fail=1 +acl2=`cd b && getfacl file` || framework_failure +test "$acl1" = "$acl2" || fail=1 + Exit $fail diff --git a/tests/cp/reflink-perm b/tests/cp/reflink-perm index 92cb7ae8f..77f119f4a 100755 --- a/tests/cp/reflink-perm +++ b/tests/cp/reflink-perm @@ -39,4 +39,8 @@ test "$mode" = "-rwxrwxrwx" || fail=1 test copy -nt file && fail=1 +echo > file2 # file with data +cp --reflink=auto --preserve --attributes-only file2 empty_copy || fail=1 +test -s empty_copy && fail=1 + Exit $fail -- cgit v1.2.3-70-g09d2