From b59788fc481f9a5aebaea9f7e780624e19b1accc Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 11 Jul 2017 23:11:35 +0200 Subject: [PATCH] fetchTarball: Prevent concurrent downloads of the same file Fixes #849. (cherry picked from commit 8e8caf7f3e535d4e397f422f6c0effd81f497305) --- src/libstore/download.cc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/libstore/download.cc b/src/libstore/download.cc index d9797ff48..1541ca2f3 100644 --- a/src/libstore/download.cc +++ b/src/libstore/download.cc @@ -3,6 +3,7 @@ #include "globals.hh" #include "hash.hh" #include "store-api.hh" +#include "pathlocks.hh" #include @@ -203,6 +204,8 @@ Path downloadFileCached(const string & url, bool unpack, string name) Path dataFile = cacheDir + "/" + urlHash + ".info"; Path fileLink = cacheDir + "/" + urlHash + "-file"; + PathLocks lock({fileLink}, fmt("waiting for lock on ‘%1%’...", fileLink)); + Path storePath; string expectedETag; @@ -255,6 +258,7 @@ Path downloadFileCached(const string & url, bool unpack, string name) if (unpack) { Path unpackedLink = cacheDir + "/" + baseNameOf(storePath) + "-unpacked"; + PathLocks lock2({unpackedLink}, fmt("waiting for lock on ‘%1%’...", unpackedLink)); Path unpackedStorePath; if (pathExists(unpackedLink)) { unpackedStorePath = readLink(unpackedLink);