From: Michael Tremer Date: Wed, 7 Dec 2016 20:58:43 +0000 (+0100) Subject: http: Reset only when necessary X-Git-Tag: 0.9.28~1285^2~1386 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f10b6865f9d523ea8cbb99da993c44c232bfe4fb;p=pakfire.git http: Reset only when necessary This is when an error occoured and it will also remove any partially downloaded content. Signed-off-by: Michael Tremer --- diff --git a/src/pakfire/http.py b/src/pakfire/http.py index 8aae2492c..9c25016be 100644 --- a/src/pakfire/http.py +++ b/src/pakfire/http.py @@ -297,12 +297,6 @@ class Client(object): raise DownloadError(_("Could not lock target file")) from e while True: - # Reset the progressbar in case the download restarts - p.reset() - - # Truncate the target file and drop any downloaded content - f.truncate() - # Prepare HTTP request r = self._make_request(url, mirror=self.mirror, **kwargs) @@ -329,6 +323,16 @@ class Client(object): break except DownloadError as e: + # Reset the progressbar in case the download restarts + p.reset() + + # Truncate the target file and drop any downloaded content + # ignore any errors in case downloading to a non-file + try: + f.truncate() + except OSError: + pass + # If we have mirrors, we will try using the next one if self.mirrors: skipped_mirrors.append(self.mirror)