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

Commit d89fd51

Browse files
authored
Merge pull request lz4#442 from terrelln/441
[lz4io] Fix decompression file stat with --rm
2 parents 58199f1 + 00eac87 commit d89fd51

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

programs/lz4io.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,23 +1073,27 @@ static int LZ4IO_decompressSrcFile(dRess_t ress, const char* input_filename, con
10731073

10741074
static int LZ4IO_decompressDstFile(dRess_t ress, const char* input_filename, const char* output_filename)
10751075
{
1076+
stat_t statbuf;
1077+
int stat_result = 0;
10761078
FILE* const foutput = LZ4IO_openDstFile(output_filename);
10771079
if (foutput==NULL) return 1; /* failure */
10781080

1081+
if ( strcmp(input_filename, stdinmark)
1082+
&& UTIL_getFileStat(input_filename, &statbuf))
1083+
stat_result = 1;
1084+
10791085
ress.dstFile = foutput;
10801086
LZ4IO_decompressSrcFile(ress, input_filename, output_filename);
10811087

10821088
fclose(foutput);
10831089

10841090
/* Copy owner, file permissions and modification time */
1085-
{ stat_t statbuf;
1086-
if ( strcmp (input_filename, stdinmark)
1087-
&& strcmp (output_filename, stdoutmark)
1088-
&& strcmp (output_filename, nulmark)
1089-
&& UTIL_getFileStat(input_filename, &statbuf) ) {
1090-
UTIL_setFileStat(output_filename, &statbuf);
1091-
/* should return value be read ? or is silent fail good enough ? */
1092-
} }
1091+
if ( stat_result != 0
1092+
&& strcmp (output_filename, stdoutmark)
1093+
&& strcmp (output_filename, nulmark)) {
1094+
UTIL_setFileStat(output_filename, &statbuf);
1095+
/* should return value be read ? or is silent fail good enough ? */
1096+
}
10931097

10941098
return 0;
10951099
}

programs/util.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,11 +265,17 @@ UTIL_STATIC void UTIL_waitForNextTick(void)
265265
#endif
266266

267267

268+
UTIL_STATIC int UTIL_isRegFile(const char* infilename);
269+
270+
268271
UTIL_STATIC int UTIL_setFileStat(const char *filename, stat_t *statbuf)
269272
{
270273
int res = 0;
271274
struct utimbuf timebuf;
272275

276+
if (!UTIL_isRegFile(filename))
277+
return -1;
278+
273279
timebuf.actime = time(NULL);
274280
timebuf.modtime = statbuf->st_mtime;
275281
res += utime(filename, &timebuf); /* set access and modification times */

0 commit comments

Comments
 (0)