In case of an error, the output file is deleted only if it's a regular file

This commit is contained in:
Alex Dolski 2018-02-12 15:27:25 -06:00
parent 07d526e4cb
commit 0fd9fa8c8a
1 changed files with 11 additions and 1 deletions

View File

@ -69,6 +69,8 @@
#ifdef OPJ_HAVE_LIBLCMS2
#include <lcms2.h>
#include <sys/stat.h>
#endif
#ifdef OPJ_HAVE_LIBLCMS1
#include <lcms.h>
@ -1785,7 +1787,15 @@ int main(int argc, char **argv)
/* destroy the codestream index */
opj_destroy_cstr_index(&cstr_index);
if (failed) {
/* delete the destination file, if it's a regular file */
struct stat info;
int retval = lstat(parameters.outfile, &info);
int file = 1;
if (retval >= 0) {
file = S_ISREG(info.st_mode);
}
if (failed && file != 0) {
(void)remove(parameters.outfile); /* ignore return value */
}
}