Unlink files in safe places.

This commit is contained in:
Con Kolivas 2011-03-07 13:40:43 +11:00
parent f9046e6756
commit 06fd0a3528

10
main.c
View file

@ -182,10 +182,6 @@ static int open_tmpoutfile(void)
fd_out = mkstemp(control.outfile);
if (unlikely(fd_out == -1))
fatal("Failed to create out tmpfile: %s\n", control.outfile);
/* Unlink temporary file immediately to minimise chance of files left
* lying around in cases of failure. */
if (unlikely(unlink(control.outfile)))
fatal("Failed to unlink tmpfile: %s\n", control.outfile);
return fd_out;
}
@ -230,6 +226,8 @@ static int open_tmpinfile(void)
fd_in = mkstemp(control.infile);
if (unlikely(fd_in == -1))
fatal("Failed to create in tmpfile: %s\n", control.infile);
/* Unlink temporary file immediately to minimise chance of files left
* lying around in cases of failure. */
if (unlikely(unlink(control.infile)))
fatal("Failed to unlink tmpfile: %s\n", control.infile);
return fd_in;
@ -364,6 +362,10 @@ static void decompress_file(void)
if (unlikely(fd_hist == -1))
fatal("Failed to open history file %s\n", control.outfile);
/* Unlink temporary file as soon as possible */
if (unlikely(STDOUT && unlink(control.outfile)))
fatal("Failed to unlink tmpfile: %s\n", control.outfile);
if (NO_MD5)
print_verbose("Not performing MD5 hash check\n");
if (HAS_MD5)