]> git.ipfire.org Git - pakfire.git/commitdiff
http: Reset only when necessary
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 7 Dec 2016 20:58:43 +0000 (21:58 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 7 Dec 2016 20:58:43 +0000 (21:58 +0100)
This is when an error occoured and it will also
remove any partially downloaded content.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/pakfire/http.py

index 8aae2492cbadc95e63b8777131356022b9f0c657..9c25016be68b378429d7f49b77473a420e4afa46 100644 (file)
@@ -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)