]> git.ipfire.org Git - pakfire.git/commitdiff
http: Exclusively lock download files
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 6 Dec 2016 23:57:29 +0000 (00:57 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 6 Dec 2016 23:57:29 +0000 (00:57 +0100)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/pakfire/http.py

index 2a2fe03ef1731f8800166248539bdeab42d89dfd..dd34285a8fdbe0fd851c26432ed80c060da480c5 100644 (file)
@@ -20,6 +20,7 @@
 ###############################################################################
 
 import base64
+import fcntl
 import json
 import logging
 import ssl
@@ -286,6 +287,12 @@ class Client(object):
                        while True:
                                with self._make_progressbar(message) as p:
                                        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
+
                                                # Prepare HTTP request
                                                r = self._make_request(url, mirror=self.mirror, **kwargs)