bug-coreutils
[Top][All Lists]
Advanced

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

use lutimens


From: Eric Blake
Subject: use lutimens
Date: Thu, 8 Oct 2009 23:19:25 +0000 (UTC)
User-agent: Loom/3.14 (http://gmane.org/)

This patch is pending my utimensat work on gnulib, but looks pretty slick; 
replacing a #if and 12 lines of code with just 1 (modulo the testsuite tweak).


From: Eric Blake <address@hidden>
Date: Thu, 8 Oct 2009 15:57:06 -0600
Subject: [PATCH] copy: allow symlink timestamp preservation on more systems

* src/copy.c (utimens_symlink): Simplify by using lutimens.
* m4/jm-macros.m4 (coreutils_MACROS): Drop utimensat; gnulib does
this for us.
* tests/cp/preserve-slink-time: Recognize lutimes support.
---
 m4/jm-macros.m4              |    3 ---
 src/copy.c                   |   10 +---------
 tests/cp/preserve-slink-time |    2 ++
 3 files changed, 3 insertions(+), 12 deletions(-)

diff --git a/m4/jm-macros.m4 b/m4/jm-macros.m4
index f4d43f1..8339404 100644
--- a/m4/jm-macros.m4
+++ b/m4/jm-macros.m4
@@ -89,9 +89,6 @@ AC_DEFUN([coreutils_MACROS],
     tcgetpgrp \
   )

-  # for cp.c
-  AC_CHECK_FUNCS_ONCE([utimensat])
-
   dnl This can't use AC_REQUIRE; I'm not quite sure why.
   cu_PREREQ_STAT_PROG

diff --git a/src/copy.c b/src/copy.c
index 49e620a..0a8b0e4 100644
--- a/src/copy.c
+++ b/src/copy.c
@@ -123,20 +123,12 @@ static char const *top_level_dst_name;
 static inline int
 utimens_symlink (char const *file, struct timespec const *timespec)
 {
-  int err = 0;
-
-#if HAVE_UTIMENSAT
-  err = utimensat (AT_FDCWD, file, timespec, AT_SYMLINK_NOFOLLOW);
+  int err = lutimens (file, timespec);
   /* When configuring on a system with new headers and libraries, and
      running on one with a kernel that is old enough to lack the syscall,
      utimensat fails with ENOSYS.  Ignore that.  */
   if (err && errno == ENOSYS)
     err = 0;
-#else
-  (void) file;
-  (void) timespec;
-#endif
-
   return err;
 }

diff --git a/tests/cp/preserve-slink-time b/tests/cp/preserve-slink-time
index c5c21a5..407b772 100755
--- a/tests/cp/preserve-slink-time
+++ b/tests/cp/preserve-slink-time
@@ -24,6 +24,7 @@ fi
 . $srcdir/test-lib.sh

 grep '^#define HAVE_UTIMENSAT' "$CONFIG_HEADER" > /dev/null ||
+grep '^#define HAVE_LUTIMES' "$CONFIG_HEADER" > /dev/null ||
   skip_test_ 'this system lacks the utimensat function'

 ln -s no-such dangle || framework_failure
@@ -34,6 +35,7 @@ case $(stat --format=%y dangle) in
   ??:??:??.000000000) sleep 2;;
 esac

+# Can't use --format=%x, as lstat() modifies atime on some platforms.
 cp -Pp dangle d2 || framework_failure
 stat --format=%y dangle > t1 || framework_failure
 stat --format=%y d2 > t2 || framework_failure
-- 
1.6.4.2







reply via email to

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