From 1cd21434fb3e82ce6d1ddb290dac6ac39cd9a8fa Mon Sep 17 00:00:00 2001 From: Nils Philippsen Date: Wed, 24 Aug 2016 14:58:45 +0200 Subject: [PATCH] catch exceptions when removing temporary directory Additionally, don't try to remove it when it wasn't created in the first place. --- rida/views.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/rida/views.py b/rida/views.py index f629def6..cb18e69b 100644 --- a/rida/views.py +++ b/rida/views.py @@ -71,6 +71,7 @@ def submit_build(): return "The submitted scmurl isn't allowed", 403 yaml = str() + td = None try: td = tempfile.mkdtemp() scm = rida.scm.SCM(url, conf.scmurls) @@ -88,7 +89,13 @@ def submit_build(): rc = 500 return str(e), rc finally: - shutil.rmtree(td) + 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))) mmd = modulemd.ModuleMetadata() try: