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,