summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYann Collet <Cyan4973@users.noreply.github.com>2018-01-10 18:09:13 (GMT)
committerGitHub <noreply@github.com>2018-01-10 18:09:13 (GMT)
commitd89fd51ce8142f8fc30d56c519bc6f555a708dc9 (patch)
treed2a7aaa6d69f2721fb6100e1e5d795b8185f62bd
parent58199f131190af0b7542a9d662387f32ccb78ff3 (diff)
parent00eac87ddaae7cef6ae05e25ff417e092ceab509 (diff)
downloadlz4-d89fd51ce8142f8fc30d56c519bc6f555a708dc9.zip
lz4-d89fd51ce8142f8fc30d56c519bc6f555a708dc9.tar.gz
lz4-d89fd51ce8142f8fc30d56c519bc6f555a708dc9.tar.bz2
Merge pull request #442 from terrelln/441
[lz4io] Fix decompression file stat with --rm
-rw-r--r--programs/lz4io.c20
-rw-r--r--programs/util.h6
2 files changed, 18 insertions, 8 deletions
diff --git a/programs/lz4io.c b/programs/lz4io.c
index 9bf4e93..2cf0c1c 100644
--- a/programs/lz4io.c
+++ b/programs/lz4io.c
@@ -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;
}
diff --git a/programs/util.h b/programs/util.h
index 1382cab..fc7f63e 100644
--- a/programs/util.h
+++ b/programs/util.h
@@ -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 */