Check that a file exists before trying to delete it. Rare errors can cause code paths leading to attempted double deletion.

This commit is contained in:
Solderpunk 2020-06-08 21:52:28 +02:00
parent 9526c384db
commit 44ee42ba8a
1 changed files with 3 additions and 3 deletions

View File

@ -535,7 +535,7 @@ Slow internet connection? Use 'set timeout' to be more patient.""")
# Save the result in a temporary file
## Delete old file
if self.tmp_filename:
if self.tmp_filename and os.path.exists(self.tmp_filename):
os.unlink(self.tmp_filename)
## Set file mode
if mime.startswith("text/"):
@ -1491,9 +1491,9 @@ current gemini browsing session."""
self.db_conn.commit()
self.db_conn.close()
# Clean up after ourself
if self.tmp_filename:
if self.tmp_filename and os.path.exists(self.tmp_filename):
os.unlink(self.tmp_filename)
if self.idx_filename:
if self.idx_filename and os.path.exists(self.idx_filename):
os.unlink(self.idx_filename)
for cert in self.transient_certs_created:
for ext in (".crt", ".key"):