avbroot/util.py: open_output_file: Close file before unlinking on Windows

This fixes temporary files being left behind when interrupted on
Windows.

Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
This commit is contained in:
Andrew Gunnerson
2023-02-16 20:17:51 -05:00
parent 8a01ada343
commit d797623acd
+4
View File
@@ -34,6 +34,10 @@ def open_output_file(path):
os.rename(f.name, path)
except BaseException:
if os.name == 'nt':
# Windows does not allow deleting a file with handles open
f.close()
os.unlink(f.name)
raise