From a163f8813e90d763e651c0d20239c55630321b73 Mon Sep 17 00:00:00 2001 From: Dan Date: Wed, 15 May 2019 20:50:23 -0400 Subject: [PATCH] Delete partially-written file in the event of an error. --- tools/mkdoc.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/tools/mkdoc.py b/tools/mkdoc.py index 0757c80d..ffe37d28 100644 --- a/tools/mkdoc.py +++ b/tools/mkdoc.py @@ -342,8 +342,17 @@ if __name__ == '__main__': break try: if out_path: - with open(out_path, 'w') as out_file: - mkdoc(args, out_file) + try: + with open(out_path, 'w') as out_file: + mkdoc(args, out_file) + except: + # In the event of an error, don't leave a partially-written + # output file. + try: + os.unlink(out_path) + except: + pass + raise else: mkdoc(args) except NoFilenamesError: