Skip to content
This repository has been archived by the owner on Feb 5, 2025. It is now read-only.

Commit

Permalink
Merge pull request lz4#442 from terrelln/441
Browse files Browse the repository at this point in the history
[lz4io] Fix decompression file stat with --rm
  • Loading branch information
Cyan4973 authored Jan 10, 2018
2 parents 58199f1 + 00eac87 commit d89fd51
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
20 changes: 12 additions & 8 deletions programs/lz4io.c
Original file line number Diff line number Diff line change
Expand Up @@ -1073,23 +1073,27 @@ static int LZ4IO_decompressSrcFile(dRess_t ress, const char* input_filename, con

static int LZ4IO_decompressDstFile(dRess_t ress, const char* input_filename, const char* output_filename)
{
stat_t statbuf;
int stat_result = 0;
FILE* const foutput = LZ4IO_openDstFile(output_filename);
if (foutput==NULL) return 1; /* failure */

if ( strcmp(input_filename, stdinmark)
&& UTIL_getFileStat(input_filename, &statbuf))
stat_result = 1;

ress.dstFile = foutput;
LZ4IO_decompressSrcFile(ress, input_filename, output_filename);

fclose(foutput);

/* Copy owner, file permissions and modification time */
{ stat_t statbuf;
if ( strcmp (input_filename, stdinmark)
&& strcmp (output_filename, stdoutmark)
&& strcmp (output_filename, nulmark)
&& UTIL_getFileStat(input_filename, &statbuf) ) {
UTIL_setFileStat(output_filename, &statbuf);
/* should return value be read ? or is silent fail good enough ? */
} }
if ( stat_result != 0
&& strcmp (output_filename, stdoutmark)
&& strcmp (output_filename, nulmark)) {
UTIL_setFileStat(output_filename, &statbuf);
/* should return value be read ? or is silent fail good enough ? */
}

return 0;
}
Expand Down
6 changes: 6 additions & 0 deletions programs/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -265,11 +265,17 @@ UTIL_STATIC void UTIL_waitForNextTick(void)
#endif


UTIL_STATIC int UTIL_isRegFile(const char* infilename);


UTIL_STATIC int UTIL_setFileStat(const char *filename, stat_t *statbuf)
{
int res = 0;
struct utimbuf timebuf;

if (!UTIL_isRegFile(filename))
return -1;

timebuf.actime = time(NULL);
timebuf.modtime = statbuf->st_mtime;
res += utime(filename, &timebuf); /* set access and modification times */
Expand Down

0 comments on commit d89fd51

Please sign in to comment.