1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-14 22:42:41 +01:00

fetchTarball: Prevent concurrent downloads of the same file

Fixes #849.

(cherry picked from commit 8e8caf7f3e)
This commit is contained in:
Eelco Dolstra 2017-07-11 23:11:35 +02:00
parent 7577d35895
commit b59788fc48
No known key found for this signature in database
GPG key ID: 8170B4726D7198DE

View file

@ -3,6 +3,7 @@
#include "globals.hh"
#include "hash.hh"
#include "store-api.hh"
#include "pathlocks.hh"
#include <curl/curl.h>
@ -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);