Subject: bug#8419: cp -au : New hard links in source becomes new files at destination when using cp -au

From: Jim Meyering <[email-masked]>
Date: Mon, 25 Jul 2011 16:00:37 +0200

Pádraig Brady wrote:
> On 25/07/11 12:42, Jim Meyering wrote:
>> [email-masked] wrote:
>>> I have tried to use the command cp combining the -a and the -u options.
>>> I had to stop the copying process midways and restarted it again, and to my
>>> suprice the diskusage at the destination was 10 -20 % larger than the
>>> diskusage at the source and my disks ran full even though the destination
>>> disks was the same size as the source disks.
>> ...
>>
>> Thank you for a fine bug report.
>> That is indeed a bug, and it affects the latest release, coreutils-8.12.
>> I confirmed that it afflicts fileutils-3.16 too, so this bug has probably
>> been present since the initial implementation.
>>
>> Here's the fix I expect to push:
>
> That looks good.
> Should we fold the attached patch in too?
> It refactors out a create_hard_link() function,
> so we wouldn't be adding any new labels.

Thanks for the review.
Factoring out that function is definitely worth doing.
However, I'd prefer to keep that clean-up change separate
from the bug-fixing one.  Would you please add a comment for
the new function?  Maybe something as simple as this:

/* Create a hard link DST_NAME to SRC_NAME, honoring the REPLACE and
   VERBOSE settings.  Return true upon success.  Otherwise, diagnose
   the failure and return false.  */

> diff --git a/src/copy.c b/src/copy.c
> index c17b942..95d05f0 100644
> --- a/src/copy.c
> +++ b/src/copy.c
> @@ -1488,6 +1488,37 @@ restore_default_fscreatecon_or_die (void)
>             _("failed to restore the default file creation context"));
>  }
>
> +static bool
> +create_hard_link (char const *src_name, char const *dst_name,
> +                  bool replace, bool verbose)