Fix a temporary-file crash

This commit is contained in:
Andrew R. M 2019-04-06 10:19:10 -04:00 committed by Kodi Arfer
parent a3962ad19c
commit da823d2cad
2 changed files with 10 additions and 3 deletions

View File

@ -12,6 +12,11 @@ New Features
* Format strings with embedded Hy code (e.g., `f"The sum is {(+ x y)}"`)
are now supported, even on Pythons earlier than 3.6.
Bug Fixes
------------------------------
* Fixed a crash caused by errors creating temp files during bytecode
compilation
0.16.0
==============================

View File

@ -467,9 +467,10 @@ else:
if cfile is None:
cfile = cache_from_source(filename)
f = None
try:
f = tempfile.NamedTemporaryFile('wb', dir=os.path.split(cfile)[0],
delete=False)
try:
f.write('\0\0\0\0')
f.write(struct.pack('<I', timestamp))
f.write(marshal.dumps(codeobject))
@ -489,6 +490,7 @@ else:
os.rename(f.name, cfile)
except OSError:
try:
if f is not None:
os.unlink(f.name)
except OSError:
pass