From 6de382cdbb37f06bbf3b06810311ce9e8bc56e30 Mon Sep 17 00:00:00 2001 From: Chip Turner Date: Sun, 13 Mar 2016 22:24:46 -0700 Subject: [PATCH 1/2] propagate errors when decompressing; also unlink dstfile if we create it but fail to successfully compress or decompress --- programs/fileio.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/programs/fileio.c b/programs/fileio.c index 028c7db4..25d75b62 100644 --- a/programs/fileio.c +++ b/programs/fileio.c @@ -428,6 +428,10 @@ static int FIO_compressFilename_extRess(cRess_t ress, result = FIO_compressFilename_internal(ress, dstFileName, srcFileName, cLevel); + if (result != 0) { + unlink(dstFileName); + } + fclose(ress.srcFile); /* no pb to expect : only reading */ if (fclose(ress.dstFile)) EXM_THROW(28, "Write error : cannot properly close %s", dstFileName); return result; @@ -633,13 +637,17 @@ static int FIO_decompressSrcFile(dRess_t ress, const char* srcFileName) static int FIO_decompressFile_extRess(dRess_t ress, const char* dstFileName, const char* srcFileName) { + int result; ress.dstFile = FIO_openDstFile(dstFileName); if (ress.dstFile==0) return 1; - FIO_decompressSrcFile(ress, srcFileName); + result = FIO_decompressSrcFile(ress, srcFileName); + if (result != 0) { + unlink(dstFileName); + } if (fclose(ress.dstFile)) EXM_THROW(38, "Write error : cannot properly close %s", dstFileName); - return 0; + return result; } From 9da7f865913756d5ee413e48d6636073f13b8a99 Mon Sep 17 00:00:00 2001 From: Chip Turner Date: Mon, 14 Mar 2016 07:44:59 -0700 Subject: [PATCH 2/2] use remove instead of unlink --- programs/fileio.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/programs/fileio.c b/programs/fileio.c index 25d75b62..8f26a4c3 100644 --- a/programs/fileio.c +++ b/programs/fileio.c @@ -429,7 +429,7 @@ static int FIO_compressFilename_extRess(cRess_t ress, result = FIO_compressFilename_internal(ress, dstFileName, srcFileName, cLevel); if (result != 0) { - unlink(dstFileName); + remove(dstFileName); } fclose(ress.srcFile); /* no pb to expect : only reading */ @@ -643,7 +643,7 @@ static int FIO_decompressFile_extRess(dRess_t ress, result = FIO_decompressSrcFile(ress, srcFileName); if (result != 0) { - unlink(dstFileName); + remove(dstFileName); } if (fclose(ress.dstFile)) EXM_THROW(38, "Write error : cannot properly close %s", dstFileName);