From 58cb8adf9630d24b0bb83eba47debc45c1fdd3ed Mon Sep 17 00:00:00 2001 From: Fabio Erculiani Date: Tue, 7 Aug 2012 21:59:51 +0200 Subject: [PATCH] [entropy.client.package] _generate_content_safety_file: do not catch Exception Move the os.remove() call to the finally block and detect failures via a status boolean. This way, warnings won't be raised as exceptions. --- lib/entropy/client/interfaces/package.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/entropy/client/interfaces/package.py b/lib/entropy/client/interfaces/package.py index 6033d89b2..06d3bcf16 100644 --- a/lib/entropy/client/interfaces/package.py +++ b/lib/entropy/client/interfaces/package.py @@ -4173,6 +4173,7 @@ class Package: raise tmp_fd, tmp_path = None, None + generated = False try: tmp_fd, tmp_path = tempfile.mkstemp( prefix="PackageContentSafety", @@ -4181,20 +4182,19 @@ class Package: for path, sha256, mtime in content_safety: tmp_f.write(path, sha256, mtime) + generated = True return tmp_path - except Exception as exc: - if tmp_path is not None: - try: - os.remove(tmp_path) - except (OSError, IOError): - pass - raise exc finally: if tmp_fd is not None: try: os.close(tmp_fd) except OSError: pass + if tmp_path is not None and not generated: + try: + os.remove(tmp_path) + except (OSError, IOError): + pass @staticmethod def _generate_content_file(content, package_id = None):