about summary refs log tree commit diff
path: root/src/libstore/download.cc
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2019-02-25T15·20+0800
committerEelco Dolstra <edolstra@gmail.com>2019-06-24T19·58+0200
commitdc29e9fb47f9f98a851dc88b2bd3cae4b5c1fe6b (patch)
tree987610c21a2bf0796dc9e2d6b92daca215fd9d6c /src/libstore/download.cc
parent94f11d0a61bba15ff8a93f2de8d1883783c8c508 (diff)
downloadCached: Return ETag
(cherry picked from commit 529add316c5356a8060c35f987643b7bf5c796dc)
Diffstat (limited to 'src/libstore/download.cc')
-rw-r--r--src/libstore/download.cc17
1 files changed, 13 insertions, 4 deletions
diff --git a/src/libstore/download.cc b/src/libstore/download.cc
index 22382ab1d6e8..cb77cdc77df6 100644
--- a/src/libstore/download.cc
+++ b/src/libstore/download.cc
@@ -790,7 +790,7 @@ void Downloader::download(DownloadRequest && request, Sink & sink)
     }
 }
 
-Path Downloader::downloadCached(ref<Store> store, const string & url_, bool unpack, string name, const Hash & expectedHash, string * effectiveUrl, int ttl)
+CachedDownloadResult Downloader::downloadCached(ref<Store> store, const string & url_, bool unpack, string name, const Hash & expectedHash, string * effectiveUrl, int ttl)
 {
     auto url = resolveUri(url_);
 
@@ -802,8 +802,11 @@ Path Downloader::downloadCached(ref<Store> store, const string & url_, bool unpa
     Path expectedStorePath;
     if (expectedHash) {
         expectedStorePath = store->makeFixedOutputPath(unpack, expectedHash, name);
-        if (store->isValidPath(expectedStorePath))
-            return store->toRealPath(expectedStorePath);
+        if (store->isValidPath(expectedStorePath)) {
+            CachedDownloadResult result;
+            result.path = store->toRealPath(expectedStorePath);
+            return result;
+        }
     }
 
     Path cacheDir = getCacheDir() + "/nix/tarballs";
@@ -822,6 +825,8 @@ Path Downloader::downloadCached(ref<Store> store, const string & url_, bool unpa
 
     bool skip = false;
 
+    CachedDownloadResult result;
+
     if (pathExists(fileLink) && pathExists(dataFile)) {
         storePath = readLink(fileLink);
         store->addTempRoot(storePath);
@@ -833,6 +838,7 @@ Path Downloader::downloadCached(ref<Store> store, const string & url_, bool unpa
                     skip = true;
                     if (effectiveUrl)
                         *effectiveUrl = url_;
+                    result.etag = ss[1];
                 } else if (!ss[1].empty()) {
                     debug(format("verifying previous ETag '%1%'") % ss[1]);
                     expectedETag = ss[1];
@@ -850,6 +856,7 @@ Path Downloader::downloadCached(ref<Store> store, const string & url_, bool unpa
             auto res = download(request);
             if (effectiveUrl)
                 *effectiveUrl = res.effectiveUrl;
+            result.etag = res.etag;
 
             if (!res.cached) {
                 ValidPathInfo info;
@@ -871,6 +878,7 @@ Path Downloader::downloadCached(ref<Store> store, const string & url_, bool unpa
         } catch (DownloadError & e) {
             if (storePath.empty()) throw;
             printError(format("warning: %1%; using cached result") % e.msg());
+            result.etag = expectedETag;
         }
     }
 
@@ -904,7 +912,8 @@ Path Downloader::downloadCached(ref<Store> store, const string & url_, bool unpa
             url, expectedHash.to_string(), gotHash.to_string());
     }
 
-    return store->toRealPath(storePath);
+    result.path = store->toRealPath(storePath);
+    return result;
 }