From 30bfe06f1af3e53052d70e01155b54f97908bfc1 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Thu, 8 Mar 2012 00:15:58 +1100 Subject: [PATCH] Preserve the compressed time on decompression where suitable. --- lrzip.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/lrzip.c b/lrzip.c index ae03665..3a93940 100644 --- a/lrzip.c +++ b/lrzip.c @@ -46,6 +46,7 @@ # include #endif #include +#include #include "md5.h" #include "rzip.h" @@ -265,7 +266,7 @@ bool read_magic(rzip_control *control, int fd_in, i64 *expected_size) } /* preserve ownership and permissions where possible */ -bool preserve_perms(rzip_control *control, int fd_in, int fd_out) +static bool preserve_perms(rzip_control *control, int fd_in, int fd_out) { struct stat st; @@ -280,6 +281,21 @@ bool preserve_perms(rzip_control *control, int fd_in, int fd_out) return true; } +static bool preserve_times(rzip_control *control, int fd_in) +{ + struct utimbuf times; + struct stat st; + + if (unlikely(fstat(fd_in, &st))) + fatal_return(("Failed to fstat input file\n"), false); + times.actime = 0; + times.modtime = st.st_mtime; + if (unlikely(utime(control->outfile, ×))) + print_verbose("Warning, unable to set time on %s\n", control->outfile); + + return true; +} + /* Open a temporary outputfile to emulate stdout */ int open_tmpoutfile(rzip_control *control) { @@ -789,6 +805,9 @@ bool decompress_file(rzip_control *control) if (unlikely(close(fd_hist) || close(fd_out))) fatal_return(("Failed to close files\n"), false); + if (unlikely(!STDIN && !STDOUT && !TEST_ONLY && !preserve_times(control, fd_in))) + return false; + close(fd_in); if (!KEEP_FILES) {