]> git.ipfire.org Git - pakfire.git/commitdiff
http: Truncate the downloaded file instead re-opening it
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 7 Dec 2016 20:27:37 +0000 (21:27 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 7 Dec 2016 20:27:37 +0000 (21:27 +0100)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/pakfire/http.py

index 39ea1f7e8295bd391c4fe47156483c2217c71f64..8aae2492cbadc95e63b8777131356022b9f0c657 100644 (file)
@@ -289,16 +289,19 @@ class Client(object):
 
                try:
                        with self._make_progressbar(message) as p:
-                               # Reset the progressbar in case the download restarts
-                               p.reset()
-
-                               while True:
-                                       with open(filename, "wb") as f:
-                                               # Exclusively lock the file for download
-                                               try:
-                                                       fcntl.flock(f, fcntl.LOCK_EX)
-                                               except OSError as e:
-                                                       raise DownloadError(_("Could not lock target file")) from e
+                               with open(filename, "wb") as f:
+                                       # Exclusively lock the file for download
+                                       try:
+                                               fcntl.flock(f, fcntl.LOCK_EX)
+                                       except OSError as e:
+                                               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)