From: Michael Tremer Date: Tue, 6 Dec 2016 23:57:29 +0000 (+0100) Subject: http: Exclusively lock download files X-Git-Tag: 0.9.28~1285^2~1398 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ac88bb812a6d505d07b1347aa6c5910ff71ffd18;p=pakfire.git http: Exclusively lock download files Signed-off-by: Michael Tremer --- diff --git a/src/pakfire/http.py b/src/pakfire/http.py index 2a2fe03ef..dd34285a8 100644 --- a/src/pakfire/http.py +++ b/src/pakfire/http.py @@ -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)