|
|
ca6c51 |
From 7a4094d382e74aaed0a0b8356dc24d64952852f9 Mon Sep 17 00:00:00 2001
|
|
|
ca6c51 |
From: Pavel Raiskup <praiskup@redhat.com>
|
|
|
ca6c51 |
Date: Fri, 3 Jul 2020 12:32:58 +0200
|
|
|
ca6c51 |
Subject: [PATCH] Extract: retain times for symlinks
|
|
|
ca6c51 |
|
|
|
ca6c51 |
Original report by Pat Riehecky at
|
|
|
ca6c51 |
https://bugzilla.redhat.com/1486364
|
|
|
ca6c51 |
|
|
|
ca6c51 |
* src/copyin.c (copyin_device): Don't check for retain_time_flag
|
|
|
ca6c51 |
global, it's done by set_file_times.
|
|
|
ca6c51 |
(copyin_link): Call set_file_times to restore symlink times.
|
|
|
ca6c51 |
* src/util.c (set_perms): Don't check for retain_time_flag global,
|
|
|
ca6c51 |
done by set_file_times call.
|
|
|
ca6c51 |
(set_file_times): Do nothing if retain_time_flag global is false.
|
|
|
ca6c51 |
* src/copypass.c (process_copy_pass): Call set_file_times for
|
|
|
ca6c51 |
symlinks.
|
|
|
ca6c51 |
---
|
|
|
ca6c51 |
src/copyin.c | 5 ++---
|
|
|
ca6c51 |
src/copypass.c | 2 ++
|
|
|
ca6c51 |
src/util.c | 6 ++++--
|
|
|
ca6c51 |
3 files changed, 8 insertions(+), 5 deletions(-)
|
|
|
ca6c51 |
|
|
|
ca6c51 |
diff --git a/src/copyin.c b/src/copyin.c
|
|
|
ca6c51 |
index 183b5b5..267ed4b 100644
|
|
|
ca6c51 |
--- a/src/copyin.c
|
|
|
ca6c51 |
+++ b/src/copyin.c
|
|
|
ca6c51 |
@@ -639,9 +639,7 @@ copyin_device (struct cpio_file_stat* file_hdr)
|
|
|
ca6c51 |
/* chown may have turned off some permissions we wanted. */
|
|
|
ca6c51 |
if (chmod (file_hdr->c_name, file_hdr->c_mode) < 0)
|
|
|
ca6c51 |
chmod_error_details (file_hdr->c_name, file_hdr->c_mode);
|
|
|
ca6c51 |
- if (retain_time_flag)
|
|
|
ca6c51 |
- set_file_times (-1, file_hdr->c_name, file_hdr->c_mtime,
|
|
|
ca6c51 |
- file_hdr->c_mtime);
|
|
|
ca6c51 |
+ set_file_times (-1, file_hdr->c_name, file_hdr->c_mtime, file_hdr->c_mtime);
|
|
|
ca6c51 |
}
|
|
|
ca6c51 |
|
|
|
ca6c51 |
static void
|
|
|
ca6c51 |
@@ -692,6 +690,7 @@ copyin_link (struct cpio_file_stat *file_hdr, int in_file_des)
|
|
|
ca6c51 |
&& errno != EPERM)
|
|
|
ca6c51 |
chown_error_details (file_hdr->c_name, uid, gid);
|
|
|
ca6c51 |
}
|
|
|
ca6c51 |
+ set_file_times (-1, file_hdr->c_name, file_hdr->c_mtime, file_hdr->c_mtime);
|
|
|
ca6c51 |
free (link_name);
|
|
|
ca6c51 |
}
|
|
|
ca6c51 |
|
|
|
ca6c51 |
diff --git a/src/copypass.c b/src/copypass.c
|
|
|
ca6c51 |
index c5a9899..b4e7169 100644
|
|
|
ca6c51 |
--- a/src/copypass.c
|
|
|
ca6c51 |
+++ b/src/copypass.c
|
|
|
ca6c51 |
@@ -317,6 +317,8 @@ process_copy_pass ()
|
|
|
ca6c51 |
&& errno != EPERM)
|
|
|
ca6c51 |
chown_error_details (output_name.ds_string, uid, gid);
|
|
|
ca6c51 |
}
|
|
|
ca6c51 |
+ set_file_times (-1, output_name.ds_string,
|
|
|
ca6c51 |
+ in_file_stat.st_atime, in_file_stat.st_mtime);
|
|
|
ca6c51 |
free (link_name);
|
|
|
ca6c51 |
}
|
|
|
ca6c51 |
#endif
|
|
|
ca6c51 |
diff --git a/src/util.c b/src/util.c
|
|
|
ca6c51 |
index 6ff6032..11f9c30 100644
|
|
|
ca6c51 |
--- a/src/util.c
|
|
|
ca6c51 |
+++ b/src/util.c
|
|
|
ca6c51 |
@@ -1389,7 +1389,6 @@ set_perms (int fd, struct cpio_file_stat *header)
|
|
|
ca6c51 |
we have to refer to it using name+ instead of name. */
|
|
|
ca6c51 |
file_hdr->c_name [cdf_char] = '+';
|
|
|
ca6c51 |
#endif
|
|
|
ca6c51 |
- if (retain_time_flag)
|
|
|
ca6c51 |
set_file_times (fd, header->c_name, header->c_mtime, header->c_mtime);
|
|
|
ca6c51 |
}
|
|
|
ca6c51 |
|
|
|
ca6c51 |
@@ -1398,6 +1397,8 @@ set_file_times (int fd,
|
|
|
ca6c51 |
const char *name, unsigned long atime, unsigned long mtime)
|
|
|
ca6c51 |
{
|
|
|
ca6c51 |
struct timespec ts[2];
|
|
|
ca6c51 |
+ if (!retain_time_flag)
|
|
|
ca6c51 |
+ return;
|
|
|
ca6c51 |
|
|
|
ca6c51 |
memset (&ts, 0, sizeof ts);
|
|
|
ca6c51 |
|
|
|
ca6c51 |
@@ -1406,7 +1407,8 @@ set_file_times (int fd,
|
|
|
ca6c51 |
|
|
|
ca6c51 |
/* Silently ignore EROFS because reading the file won't have upset its
|
|
|
ca6c51 |
timestamp if it's on a read-only filesystem. */
|
|
|
ca6c51 |
- if (fdutimens (fd, name, ts) < 0 && errno != EROFS)
|
|
|
ca6c51 |
+ if ((fd >= 0 ? fdutimens (fd, NULL, ts) : lutimens (name, ts)) < 0
|
|
|
ca6c51 |
+ && errno != EROFS)
|
|
|
ca6c51 |
utime_error (name);
|
|
|
ca6c51 |
}
|
|
|
ca6c51 |
|
|
|
ca6c51 |
--
|
|
|
ca6c51 |
2.24.1
|
|
|
ca6c51 |
|