[elbe-devel] [PATCH] debinstall/hashes: improve error handling
Manuel Traut
manut at linutronix.de
Fri Nov 16 17:28:24 CET 2018
preinit file variable that close doesn't use uninitialized variable.
print info about IOError that is raised if urlopen fails.
Signed-off-by: Manuel Traut <manut at linutronix.de>
---
elbepack/debinstaller.py | 11 ++++++++++-
elbepack/hashes.py | 7 +++++++
2 files changed, 17 insertions(+), 1 deletion(-)
diff --git a/elbepack/debinstaller.py b/elbepack/debinstaller.py
index d251f202..9d838188 100644
--- a/elbepack/debinstaller.py
+++ b/elbepack/debinstaller.py
@@ -115,10 +115,14 @@ def setup_apt_keyring(gpg_home, keyring_fname):
def download(url, local_fname):
+ rf = None
try:
rf = urlopen(url, None, 10)
with open(local_fname, "w") as wf:
copyfileobj(rf, wf)
+ except IOError as e:
+ print("download: %s FAILED" % url, file=sys.stderr)
+ raise e
finally:
rf.close()
@@ -138,8 +142,10 @@ def download_release(tmp, base_url):
# open downloaded plaintext file, and
# use the urlopen object of the Release.gpg
# directtly.
+ sig = None
try:
- sig = urlopen(base_url + 'Release.gpg', None, 10)
+ url = base_url + 'Release.gpg'
+ sig = urlopen(url, None, 10)
with tmp.open("Release", "r") as signed:
overall_status = OverallStatus()
@@ -153,6 +159,9 @@ def download_release(tmp, base_url):
if overall_status.to_exitcode():
raise InvalidSignature('Failed to verify Release file')
+ except IOError as e:
+ print("download: %s FAILED" % url, file=sys.stderr)
+ raise e
finally:
sig.close()
diff --git a/elbepack/hashes.py b/elbepack/hashes.py
index d2dfe053..f27d7811 100644
--- a/elbepack/hashes.py
+++ b/elbepack/hashes.py
@@ -3,7 +3,11 @@
#
# SPDX-License-Identifier: GPL-3.0-or-later
+from __future__ import print_function
+
import hashlib
+import sys
+
from shutil import copyfileobj
# different module names in python 2 and 3
@@ -62,6 +66,9 @@ class HashValidator(object):
rf = urlopen(url, None, 10)
with open(local_fname, "w") as wf:
copyfileobj(rf, wf)
+ except IOError as e:
+ print("download: %s FAILED" % url, file=sys.stderr)
+ raise e
finally:
if rf is not None:
rf.close()
--
2.19.1
More information about the elbe-devel
mailing list