summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPádraig Brady <P@draigBrady.com>2009-08-13 10:39:10 +0100
committerJim Meyering <meyering@redhat.com>2009-08-14 17:10:53 +0200
commitf0a1f0df2295aaed418f201bbec67df120e1ac17 (patch)
tree2ec21ea8d4ebfc3bf231baf3fccc2f7a91ce4a1a /src
parent8574c7432596abd185e94c92068d23eb2591ae64 (diff)
downloadcoreutils-f0a1f0df2295aaed418f201bbec67df120e1ac17.tar.xz
cp,mv: fix issues with preserving timestamps of copied symlinks
* src/copy.c (copy_internal): On systems without utimensat don't use utimens on a symlink, as that would dereference the symlink. * tests/cp/abuse: To work around possible attribute preservation failures breaking the test, use cp -dR rather than cp -a.
Diffstat (limited to 'src')
-rw-r--r--src/copy.c19
1 files changed, 11 insertions, 8 deletions
diff --git a/src/copy.c b/src/copy.c
index bed90c459..bf9230bb0 100644
--- a/src/copy.c
+++ b/src/copy.c
@@ -118,18 +118,18 @@ static bool owner_failure_ok (struct cp_options const *x);
static char const *top_level_src_name;
static char const *top_level_dst_name;
-/* Wrap utimensat-with-AT_FDCWD and utimens, to keep these
- cpp directives out of the main code. */
+/* Set the timestamp of symlink, FILE, to TIMESPEC.
+ If this system lacks support for that, simply return 0. */
static inline int
-utimensat_if_possible (char const *file, struct timespec const *timespec)
+utimens_symlink (char const *file, struct timespec const *timespec)
{
- return
#if HAVE_UTIMENSAT
- utimensat (AT_FDCWD, file, timespec, AT_SYMLINK_NOFOLLOW)
+ return utimensat (AT_FDCWD, file, timespec, AT_SYMLINK_NOFOLLOW);
#else
- utimens (file, timespec)
+ /* Don't set errno=ENOTSUP here as we don't want
+ to output an error message for this case. */
+ return 0;
#endif
- ;
}
/* Perform the O(1) btrfs clone operation, if possible.
@@ -2117,7 +2117,10 @@ copy_internal (char const *src_name, char const *dst_name,
timespec[0] = get_stat_atime (&src_sb);
timespec[1] = get_stat_mtime (&src_sb);
- if (utimensat_if_possible (dst_name, timespec) != 0)
+ if ((dest_is_symlink
+ ? utimens_symlink (dst_name, timespec)
+ : utimens (dst_name, timespec))
+ != 0)
{
error (0, errno, _("preserving times for %s"), quote (dst_name));
if (x->require_preserve)