From 8ae356f803888f7fb3851532bba44df4fbbfebed Mon Sep 17 00:00:00 2001 From: Alex Jaramillo Date: Fri, 17 Aug 2018 18:49:24 +0000 Subject: [PATCH] Checking return code after download Function really_download in tarball.py does not handle http server codes that can be interpreted as errors i.e. 404 501. When there is no failure returned in a 404 response the 404 page contents are saved as the tarball. This change adds code to test that the response from the server is 200. Any redirection is handled by pycurl internaly and the code that is checked is the code that the server with the response returns to autospec. Signed-off-by: Alex Jaramillo --- autospec/tarball.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/autospec/tarball.py b/autospec/tarball.py index 37c07a0..47cf0e4 100644 --- a/autospec/tarball.py +++ b/autospec/tarball.py @@ -63,6 +63,11 @@ def really_download(upstream_url, destination): c.setopt(c.FOLLOWLOCATION, True) try: c.perform() + code = c.getinfo(pycurl.HTTP_CODE) + if code != 200: + print_fatal("get request to {} returned {}".format(upstream_url, code)) + os.remove(destination) + exit(1) except pycurl.error as excep: print_fatal("unable to download {}: {}".format(upstream_url, excep)) os.remove(destination)