Preserve the compressed time on decompression where suitable.

This commit is contained in:
Con Kolivas 2012-03-08 00:15:58 +11:00
parent cea59cd568
commit 30bfe06f1a

21
lrzip.c
View file

@ -46,6 +46,7 @@
# include <arpa/inet.h> # include <arpa/inet.h>
#endif #endif
#include <math.h> #include <math.h>
#include <utime.h>
#include "md5.h" #include "md5.h"
#include "rzip.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 */ /* 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; struct stat st;
@ -280,6 +281,21 @@ bool preserve_perms(rzip_control *control, int fd_in, int fd_out)
return true; 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, &times)))
print_verbose("Warning, unable to set time on %s\n", control->outfile);
return true;
}
/* Open a temporary outputfile to emulate stdout */ /* Open a temporary outputfile to emulate stdout */
int open_tmpoutfile(rzip_control *control) int open_tmpoutfile(rzip_control *control)
{ {
@ -789,6 +805,9 @@ bool decompress_file(rzip_control *control)
if (unlikely(close(fd_hist) || close(fd_out))) if (unlikely(close(fd_hist) || close(fd_out)))
fatal_return(("Failed to close files\n"), false); fatal_return(("Failed to close files\n"), false);
if (unlikely(!STDIN && !STDOUT && !TEST_ONLY && !preserve_times(control, fd_in)))
return false;
close(fd_in); close(fd_in);
if (!KEEP_FILES) { if (!KEEP_FILES) {