]> git.ipfire.org Git - pakfire.git/commitdiff
http: Actually write downloaded files to the filesystem
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 4 Dec 2016 22:56:51 +0000 (23:56 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 4 Dec 2016 22:56:51 +0000 (23:56 +0100)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/pakfire/http.py

index de8065837f4f06a2fd0839bd846d887bd1f2b903..944110de1a658161e350f6ae1a6bf6ae80a42622 100644 (file)
@@ -227,19 +227,23 @@ class Client(object):
 
                # Send the request
                with self._make_progressbar(message) as p:
-                       with self._send_request(r) as f:
-                               # Try setting progress bar to correct maximum value
-                               # XXX this might need a function in ProgressBar
-                               l = self._get_content_length(f)
-                               p.value_max = l
-
-                               while True:
-                                       buf = f.read(buffer_size)
-                                       if not buf:
-                                               break
-
-                                       l = len(buf)
-                                       p.increment(l)
+                       with open(filename, "wb") as f:
+                               with self._send_request(r) as res:
+                                       # Try setting progress bar to correct maximum value
+                                       # XXX this might need a function in ProgressBar
+                                       l = self._get_content_length(res)
+                                       p.value_max = l
+
+                                       while True:
+                                               buf = res.read(buffer_size)
+                                               if not buf:
+                                                       break
+
+                                               # Write downloaded data to file
+                                               f.write(buf)
+
+                                               l = len(buf)
+                                               p.increment(l)
 
        def _get_content_length(self, response):
                s = response.getheader("Content-Length")