808377
From 8bce60df53f93c9cbfb18274c6700c143a0092c6 Mon Sep 17 00:00:00 2001
808377
From: Pavel Raiskup <praiskup@redhat.com>
808377
Date: Fri, 3 Jul 2020 13:00:18 +0200
808377
Subject: [PATCH] Extract: retain times for symlinks
808377
808377
Original report by Pat Riehecky at
808377
https://bugzilla.redhat.com/1486364
808377
808377
* src/copyin.c (copyin_device): Don't check for retain_time_flag
808377
global, it's done by set_file_times.
808377
(copyin_link): Call set_file_times to restore symlink times.
808377
* src/util.c (set_perms): Don't check for retain_time_flag global,
808377
done by set_file_times call.
808377
(set_file_times): Do nothing if retain_time_flag global is false.
808377
* src/copypass.c (process_copy_pass): Call set_file_times for
808377
symlinks.
808377
---
808377
 src/copyin.c   | 5 ++---
808377
 src/copypass.c | 2 ++
808377
 src/util.c     | 8 +++++---
808377
 3 files changed, 9 insertions(+), 6 deletions(-)
808377
808377
diff --git a/src/copyin.c b/src/copyin.c
808377
index bf3b0a8..93b006a 100644
808377
--- a/src/copyin.c
808377
+++ b/src/copyin.c
808377
@@ -615,9 +615,7 @@ copyin_device (struct cpio_file_stat* file_hdr)
808377
   /* chown may have turned off some permissions we wanted. */
808377
   if (chmod (file_hdr->c_name, file_hdr->c_mode) < 0)
808377
     chmod_error_details (file_hdr->c_name, file_hdr->c_mode);
808377
-  if (retain_time_flag)
808377
-    set_file_times (-1, file_hdr->c_name, file_hdr->c_mtime,
808377
-		    file_hdr->c_mtime);
808377
+  set_file_times (-1, file_hdr->c_name, file_hdr->c_mtime, file_hdr->c_mtime);
808377
 }
808377
 
808377
 static void
808377
@@ -668,6 +666,7 @@ copyin_link (struct cpio_file_stat *file_hdr, int in_file_des)
808377
   	  && errno != EPERM)
808377
 	chown_error_details (file_hdr->c_name, uid, gid);
808377
     }
808377
+  set_file_times (-1, file_hdr->c_name, file_hdr->c_mtime, file_hdr->c_mtime);
808377
   free (link_name);
808377
 }
808377
 
808377
diff --git a/src/copypass.c b/src/copypass.c
808377
index dc13b5b..a5f9b7b 100644
808377
--- a/src/copypass.c
808377
+++ b/src/copypass.c
808377
@@ -306,6 +306,8 @@ process_copy_pass ()
808377
 		  && errno != EPERM)
808377
 	        chown_error_details (output_name.ds_string, uid, gid);
808377
             }
808377
+		  set_file_times (-1, output_name.ds_string,
808377
+        				  in_file_stat.st_atime, in_file_stat.st_mtime);
808377
 	  free (link_name);
808377
 	}
808377
 #endif
808377
diff --git a/src/util.c b/src/util.c
808377
index 4421b20..0e8d88c 100644
808377
--- a/src/util.c
808377
+++ b/src/util.c
808377
@@ -1230,8 +1230,7 @@ set_perms (int fd, struct cpio_file_stat *header)
808377
   /* chown may have turned off some permissions we wanted. */
808377
   if (fchmod_or_chmod (fd, header->c_name, header->c_mode) < 0)
808377
     chmod_error_details (header->c_name, header->c_mode);
808377
-  if (retain_time_flag)
808377
-    set_file_times (fd, header->c_name, header->c_mtime, header->c_mtime);
808377
+  set_file_times (fd, header->c_name, header->c_mtime, header->c_mtime);
808377
 }
808377
 
808377
 void
808377
@@ -1239,6 +1238,8 @@ set_file_times (int fd,
808377
 		const char *name, unsigned long atime, unsigned long mtime)
808377
 {
808377
   struct timespec ts[2];
808377
+  if (!retain_time_flag)
808377
+    return;
808377
   
808377
   memset (&ts, 0, sizeof ts);
808377
 
808377
@@ -1247,7 +1248,8 @@ set_file_times (int fd,
808377
 
808377
   /* Silently ignore EROFS because reading the file won't have upset its 
808377
      timestamp if it's on a read-only filesystem. */
808377
-  if (fdutimens (fd, name, ts) < 0 && errno != EROFS)
808377
+  if ((fd >= 0 ? fdutimens (fd, NULL, ts) : lutimens (name, ts)) < 0
808377
+      && errno != EROFS)
808377
     utime_error (name);
808377
 }
808377
 
808377
-- 
808377
2.24.1
808377