Ensure temporary directories are cleaned up always.

Previously, if SCM.checkout() raised an exception, the created temporary
directory would be left over.
This commit is contained in:
Nils Philippsen
2016-08-24 14:11:44 +02:00
parent 7d487b64fc
commit ef4caa3455

View File

@@ -167,13 +167,21 @@ class SCM(object):
hc.close()
return True if rc == 200 else False
else:
td = None
try:
td = tempfile.mkdtemp()
self.checkout(td)
shutil.rmtree(td)
return True
except:
return False
finally:
try:
if td is not None:
shutil.rmtree(td)
except Exception as e:
log.warning(
"Failed to remove temporary directory {!r}: {}".format(
td, str(e)))
@property
def url(self):