about summary refs log tree commit diff
path: root/src/libstore/download.cc
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2016-04-15T13·11+0200
committerEelco Dolstra <eelco.dolstra@logicblox.com>2016-04-15T13·39+0200
commitd1b0909894a302540f979d904dd378af1cad620c (patch)
tree691ec2d838e4449897549a537145971d9b12a3d5 /src/libstore/download.cc
parent99851c6f06c80fe2222c5e5fcef963804e907170 (diff)
BinaryCacheStore::readFile(): Return a shared_ptr to a string
This allows readFile() to indicate that a file doesn't exist, and
might eliminate some large string copying.
Diffstat (limited to 'src/libstore/download.cc')
-rw-r--r--src/libstore/download.cc9
1 files changed, 5 insertions, 4 deletions
diff --git a/src/libstore/download.cc b/src/libstore/download.cc
index 7277751b48e7..8cd3ad741e10 100644
--- a/src/libstore/download.cc
+++ b/src/libstore/download.cc
@@ -29,7 +29,7 @@ std::string resolveUri(const std::string & uri)
 struct CurlDownloader : public Downloader
 {
     CURL * curl;
-    string data;
+    ref<std::string> data;
     string etag, status, expectedETag;
 
     struct curl_slist * requestHeaders;
@@ -41,7 +41,7 @@ struct CurlDownloader : public Downloader
     size_t writeCallback(void * contents, size_t size, size_t nmemb)
     {
         size_t realSize = size * nmemb;
-        data.append((char *) contents, realSize);
+        data->append((char *) contents, realSize);
         return realSize;
     }
 
@@ -110,6 +110,7 @@ struct CurlDownloader : public Downloader
     }
 
     CurlDownloader()
+        : data(make_ref<std::string>())
     {
         requestHeaders = 0;
 
@@ -156,7 +157,7 @@ struct CurlDownloader : public Downloader
             curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0);
         }
 
-        data.clear();
+        data->clear();
 
         if (requestHeaders) {
             curl_slist_free_all(requestHeaders);
@@ -269,7 +270,7 @@ Path Downloader::downloadCached(ref<Store> store, const string & url_, bool unpa
             auto res = download(url, options);
 
             if (!res.cached)
-                storePath = store->addTextToStore(name, res.data, PathSet(), false);
+                storePath = store->addTextToStore(name, *res.data, PathSet(), false);
 
             assert(!storePath.empty());
             replaceSymlink(storePath, fileLink);