]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
(copy_reg): Preserve time stamps if
authorPaul Eggert <eggert@cs.ucla.edu>
Fri, 23 Sep 2005 20:38:34 +0000 (20:38 +0000)
committerPaul Eggert <eggert@cs.ucla.edu>
Fri, 23 Sep 2005 20:38:34 +0000 (20:38 +0000)
x->preserve_timestamps is set, using futimens so that
we needn't resolve the path again.
(copy_internal): Don't preserve time stamps if copy_reg did it
already.

src/copy.c

index ba6ce48600e68de293516c7e557543e521c9155e..026a18d3a52aad03d4fc40fd3456bd714cce1bda 100644 (file)
@@ -403,6 +403,20 @@ copy_reg (char const *src_name, char const *dst_name,
        }
     }
 
+  if (x->preserve_timestamps)
+    {
+      struct timespec timespec[2];
+      timespec[0] = get_stat_atime (src_sb);
+      timespec[1] = get_stat_mtime (src_sb);
+
+      if (futimens (dest_desc, dst_name, timespec) != 0)
+       {
+         error (0, errno, _("preserving times for %s"), quote (dst_name));
+         if (x->require_preserve)
+           return_val = false;
+       }
+    }
+
 close_src_and_dst_desc:
   if (close (dest_desc) < 0)
     {
@@ -1564,10 +1578,9 @@ copy_internal (char const *src_name, char const *dst_name,
      chown turns off set[ug]id bits for non-root,
      so do the chmod last.  */
 
-  if (x->preserve_timestamps)
+  if (!copied_as_regular && x->preserve_timestamps)
     {
       struct timespec timespec[2];
-
       timespec[0] = get_stat_atime (&src_sb);
       timespec[1] = get_stat_mtime (&src_sb);