Subject: bug#8374: cp -a [-l] sometimes does not preserve timestamps of symlinks

From: Eric Blake <[email-masked]>
Date: Thu, 31 Mar 2011 08:20:16 -0600

[adding bug-gnulib]

On 03/31/2011 08:11 AM, Pádraig Brady wrote:
>> So probably -al is broken since you fixed -a in 7.5.
> 
> Hmm it looks now like we're creating symlinks (with wrong timestamps),
> but in fact we should be creating hardlinks to symlinks.
> 
> This seems to have been changed with:
> http://git.sv.gnu.org/gitweb/?p=coreutils.git;a=commit;h=3346c0af
> 
> Eric do you have any suggestions?
> The following seems to make things work as expected
> 
> diff --git a/src/copy.c b/src/copy.c
> index a672fd3..4f07d2c 100644
> --- a/src/copy.c
> +++ b/src/copy.c
> @@ -2226,8 +2226,7 @@ copy_internal (char const *src_name, char const *dst_name,
>       where link(2) follows the link, gnulib creates a symlink with
>       identical contents, which is good enough for our purposes).  */
>    else if (x->hard_link
> -           && (!S_ISLNK (src_mode)
> -               || x->dereference != DEREF_NEVER))
> +           && !(S_ISLNK (src_mode) && x->dereference != DEREF_NEVER))
>      {
>         if (linkat (AT_FDCWD, src_name, AT_FDCWD, dst_name, 0))
>          {
> 
> Hmm, maybe it's better to skip linkat() for symlinks altogether
> since the gnulib fallback on systems that implicitly dereference,
> will create symlinks, but without the right timestamps.
> Or, perhaps the gnulib fallback should try to update timestamps too?

Sounds to me like the gnulib fallback should be made smarter.  Which
systems lack linkat() but have the capability to set timestamps?  BSD?
But the original report was about opensuse, which is Linux based, and my
recollection is that Linux handles hardlinks to symlinks much longer
than it could set symlink timestamps.

-- 
Eric Blake   [email-masked]    +1-801-349-2682
Libvirt virtualization library http://libvirt.org