Skip to content

Commit

Permalink
Preserve the compressed time on decompression where suitable.
Browse files Browse the repository at this point in the history
  • Loading branch information
ckolivas committed Mar 7, 2012
1 parent cea59cd commit 30bfe06
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion lrzip.c
Expand Up @@ -46,6 +46,7 @@
# include <arpa/inet.h>
#endif
#include <math.h>
#include <utime.h>

#include "md5.h"
#include "rzip.h"
Expand Down Expand Up @@ -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;

Expand All @@ -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, &times)))
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)
{
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 30bfe06

Please sign in to comment.