From 66ddbef7547a2b5430c6d87e2d8d52977f7bf6f0 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 30 Oct 2017 10:16:19 +0100 Subject: fetchurl/fetchTarball: Respect name changes The computation of urlHash didn't take the name into account, so subsequent fetchurl calls with the same URL but a different name would resolve to the same cached store path. --- src/libexpr/primops.cc | 2 +- src/libstore/download.cc | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc index 6a50c9934..43dc20080 100644 --- a/src/libexpr/primops.cc +++ b/src/libexpr/primops.cc @@ -1911,7 +1911,7 @@ void fetch(EvalState & state, const Pos & pos, Value * * args, Value & v, { string url; Hash expectedHash; - string name; + string name = ""; state.forceValue(*args[0]); diff --git a/src/libstore/download.cc b/src/libstore/download.cc index 608b8fd39..579a5e8c1 100644 --- a/src/libstore/download.cc +++ b/src/libstore/download.cc @@ -23,6 +23,8 @@ #include #include +using namespace std::string_literals; + namespace nix { double getTime() @@ -604,7 +606,7 @@ Path Downloader::downloadCached(ref store, const string & url_, bool unpa Path cacheDir = getCacheDir() + "/nix/tarballs"; createDirs(cacheDir); - string urlHash = hashString(htSHA256, url).to_string(Base32, false); + string urlHash = hashString(htSHA256, name + std::string("\0"s) + url).to_string(Base32, false); Path dataFile = cacheDir + "/" + urlHash + ".info"; Path fileLink = cacheDir + "/" + urlHash + "-file"; -- cgit v1.2.3