Blame SOURCES/cpio-2.11-retain-symlink-times.patch

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