[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug-tar] Preserve timestamp of symlinks when extracting (if utimensat a

From: Carl Worth
Subject: [Bug-tar] Preserve timestamp of symlinks when extracting (if utimensat available)
Date: Tue, 04 Aug 2009 17:08:15 -0700

On Sun, 12 Jun 2005 14:22:53 -0400, D Goel wrote:
> Let's try the tar-trick to copy the contents of dir1 to dir2: 
> (cd dir1 && tar -clpsf- *) | (cd dir2 & tar -xpsf -)
> This copies the contents, including correct timestamps and ownership,
> except that if there is a symlink (named, say s) in dir1.  Then the
> copied file dir2/s fails to get the same timestamp as dir1/s. 

Hi DG,

Thank you for the bug report. I've confirmed that this bug still exists
in the latest version of tar packaged in Debian (1.22-1.1). And I almost
replied saying that Linux doesn't provide the necessary functionality to
do what you want, (I noticed that "cp -a" also exhibits the same
bug---see bug #26766).

But rsync does not have the bug, so I looked a little closer and
found... the necessary magic is in the flags argument to the POSIX
utimensat function call:

       The flags field is a bit mask that may be 0, or include  the  following
       constant, defined in <fcntl.h>:

              If  pathname  specifies  a  symbolic link, then update the time‐
              stamps of the link, rather than the file to which it refers.

The tar program already prefers to call utimensat if available, but
currently always passes 0 for the flags argument. It also avoids ever
calling this function for symlinks, (which would update the timestamp of
the target to the archived time stamp of the link which is certainly not

I've attached a patch that fixes the bug when utimensat is available,
and should have no effect when the function is not available, (though I
didn't test on any such system). I also didn't write a new test case for
this behavior, (I'm not sure how to make a test case that would not be
expected to pass on some systems.)

Any feedback would be appreciated,


Attachment: 0001-Preserve-timestamp-of-symlinks-when-extracting-if-ut.patch
Description: Text Data

Attachment: signature.asc
Description: This is a digitally signed message part

reply via email to

[Prev in Thread] Current Thread [Next in Thread]