From 3ffbbcb49da735f8a8c55d39cc641183890d0d34 Mon Sep 17 00:00:00 2001 From: Fabio Erculiani Date: Tue, 7 Aug 2012 22:02:37 +0200 Subject: [PATCH] [entropy.client.package] _generate_content_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 06d3bcf16..360e8e1f4 100644 --- a/lib/entropy/client/interfaces/package.py +++ b/lib/entropy/client/interfaces/package.py @@ -4216,6 +4216,7 @@ class Package: raise tmp_fd, tmp_path = None, None + generated = False try: tmp_fd, tmp_path = tempfile.mkstemp( prefix="PackageContent", @@ -4224,20 +4225,19 @@ class Package: for path, ftype in content: tmp_f.write(package_id, path, ftype) + 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 _merge_content_file(content_file, sorted_content,