mirror of
https://github.com/ckolivas/lrzip.git
synced 2025-12-06 07:12:00 +01:00
Preserve the compressed time on decompression where suitable.
This commit is contained in:
parent
cea59cd568
commit
30bfe06f1a
21
lrzip.c
21
lrzip.c
|
|
@ -46,6 +46,7 @@
|
|||
# include <arpa/inet.h>
|
||||
#endif
|
||||
#include <math.h>
|
||||
#include <utime.h>
|
||||
|
||||
#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) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue