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 --- src/cp.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src/cp.c') diff --git a/src/cp.c b/src/cp.c index 035526922..5b14f3a7b 100644 --- a/src/cp.c +++ b/src/cp.c @@ -72,7 +72,8 @@ struct dir_attr non-character as a pseudo short option, starting with CHAR_MAX + 1. */ enum { - COPY_CONTENTS_OPTION = CHAR_MAX + 1, + ATTRIBUTES_ONLY_OPTION = CHAR_MAX + 1, + COPY_CONTENTS_OPTION, NO_PRESERVE_ATTRIBUTES_OPTION, PARENTS_OPTION, PRESERVE_ATTRIBUTES_OPTION, @@ -115,6 +116,7 @@ ARGMATCH_VERIFY (reflink_type_string, reflink_type); static struct option const long_opts[] = { {"archive", no_argument, NULL, 'a'}, + {"attributes-only", no_argument, NULL, ATTRIBUTES_ONLY_OPTION}, {"backup", optional_argument, NULL, 'b'}, {"copy-contents", no_argument, NULL, COPY_CONTENTS_OPTION}, {"dereference", no_argument, NULL, 'L'}, @@ -167,6 +169,7 @@ Mandatory arguments to long options are mandatory for short options too.\n\ "), stdout); fputs (_("\ -a, --archive same as -dR --preserve=all\n\ + --attributes-only don't copy the file data, just the attributes\n\ --backup[=CONTROL] make a backup of each existing destination file\n\ -b like --backup but does not accept an argument\n\ --copy-contents copy contents of special files when recursive\n\ @@ -781,6 +784,7 @@ cp_option_init (struct cp_options *x) x->reduce_diagnostics = false; x->require_preserve_xattr = false; + x->data_copy_required = true; x->require_preserve = false; x->recursive = false; x->sparse_mode = SPARSE_AUTO; @@ -962,6 +966,10 @@ main (int argc, char **argv) version_control_string = optarg; break; + case ATTRIBUTES_ONLY_OPTION: + x.data_copy_required = false; + break; + case COPY_CONTENTS_OPTION: copy_contents = true; break; -- cgit v1.2.3-54-g00ecf