[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.
This commit is contained in:
Fabio Erculiani
2012-08-07 22:02:37 +02:00
parent 58cb8adf96
commit 3ffbbcb49d

View File

@@ -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,