Extract: retain times for symlinks in copy-in and copy-pass modes

This commit is contained in:
Ondrej Dubaj 2020-07-03 13:02:29 +02:00
parent e7409e640d
commit fbe7850fd1
2 changed files with 103 additions and 1 deletions

View File

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

View File

@ -1,7 +1,7 @@
Summary: A GNU archiving program Summary: A GNU archiving program
Name: cpio Name: cpio
Version: 2.13 Version: 2.13
Release: 5.1%{?dist} Release: 6%{?dist}
License: GPLv3+ License: GPLv3+
URL: http://www.gnu.org/software/cpio/ URL: http://www.gnu.org/software/cpio/
Source: ftp://ftp.gnu.org/gnu/cpio/cpio-%{version}.tar.bz2 Source: ftp://ftp.gnu.org/gnu/cpio/cpio-%{version}.tar.bz2
@ -43,6 +43,11 @@ Patch9: cpio-2.13-mutiple-definition.patch
# reverts upstream commit 45b0ee2b4 # reverts upstream commit 45b0ee2b4
Patch10: cpio-2.13-revert-CVE-2015-1197-fix.patch Patch10: cpio-2.13-revert-CVE-2015-1197-fix.patch
# Extract: retain times for symlinks
# downstream patch (#1486364)
# https://www.mail-archive.com/bug-cpio@gnu.org/msg00605.html
Patch11: cpio-2.11-retain-symlink-times.patch
Provides: bundled(gnulib) Provides: bundled(gnulib)
Provides: bundled(paxutils) Provides: bundled(paxutils)
Provides: /bin/cpio Provides: /bin/cpio
@ -104,6 +109,9 @@ make check || {
%{_infodir}/*.info* %{_infodir}/*.info*
%changelog %changelog
* Mon Jun 15 2020 Ondrej Dubaj <odubaj@redhat.com> - 2.13-6
- Extract: retain times for symlinks (#1486364)
* Tue Apr 07 2020 Ondrej Dubaj <odubaj@redhat.com> - 2.13-5.1 * Tue Apr 07 2020 Ondrej Dubaj <odubaj@redhat.com> - 2.13-5.1
- Release bump due to testing of gating - Release bump due to testing of gating