cp: change --attributes-only to not truncate existing files

* src/copy.c (copy_reg): Don't truncate an existing file,
to support copying attributes between existing files.
The original use case only considered creating new files,
and it would be a very unusual use case to be relying
on the truncating behavior.
* doc/coreutils.texi (cp invocation): Mention the non
truncating behavior.
* tests/cp/attr-existing: A new test to ensure O_TRUNC skipped.
* tests/Makefile.am: Reference the new test.
* NEWS: Mention the change in behavior.
This commit is contained in:
Pádraig Brady committed 2012-04-12 18:35:17 +01:00
1 parent 7e0ef7c035
commit 3d53e7fe1c
5 files changed
+41 -4

No files matched your search

+3 -1
View File
@@ -826,7 +826,9 @@ copy_reg (char const *src_name, char const *dst_name,
by the specs for both cp and mv. */
if (! *new_dst)
{
dest_desc = open (dst_name, O_WRONLY | O_TRUNC | O_BINARY);
int open_flags =
O_WRONLY | O_BINARY | (x->data_copy_required ? O_TRUNC : 0);
dest_desc = open (dst_name, open_flags);
dest_errno = errno;
/* When using cp --preserve=context to copy to an existing destination,