mirror of
https://github.com/NixOS/nix.git
synced 2025-11-15 15:02:42 +01:00
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.
This commit is contained in:
parent
99851c6f06
commit
d1b0909894
11 changed files with 52 additions and 28 deletions
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue