diff options
author | Eelco Dolstra <edolstra@gmail.com> | 2022-01-17 22:20:05 +0100 |
---|---|---|
committer | Eelco Dolstra <edolstra@gmail.com> | 2022-01-18 11:12:30 +0100 |
commit | d62a9390fcdc0f9e4971e5fab2f667567237b252 (patch) | |
tree | cdbf6aef8b15b2ba5f02f7426ec2e5cd1f595e39 /src/libstore/binary-cache-store.cc | |
parent | 52ee7ec0028263f04e15c05256ca90fa62a0da66 (diff) |
Get rid of std::shared_ptr<std::string> and ref<std::string>
These were needed back in the pre-C++11 era because we didn't have
move semantics. But now we do.
Diffstat (limited to 'src/libstore/binary-cache-store.cc')
-rw-r--r-- | src/libstore/binary-cache-store.cc | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/src/libstore/binary-cache-store.cc b/src/libstore/binary-cache-store.cc index 13c086a46..8aec632e8 100644 --- a/src/libstore/binary-cache-store.cc +++ b/src/libstore/binary-cache-store.cc @@ -31,7 +31,7 @@ BinaryCacheStore::BinaryCacheStore(const Params & params) StringSink sink; sink << narVersionMagic1; - narMagic = *sink.s; + narMagic = sink.s; } void BinaryCacheStore::init() @@ -68,7 +68,7 @@ void BinaryCacheStore::upsertFile(const std::string & path, } void BinaryCacheStore::getFile(const std::string & path, - Callback<std::shared_ptr<std::string>> callback) noexcept + Callback<std::optional<std::string>> callback) noexcept { try { callback(getFile(path)); @@ -77,9 +77,9 @@ void BinaryCacheStore::getFile(const std::string & path, void BinaryCacheStore::getFile(const std::string & path, Sink & sink) { - std::promise<std::shared_ptr<std::string>> promise; + std::promise<std::optional<std::string>> promise; getFile(path, - {[&](std::future<std::shared_ptr<std::string>> result) { + {[&](std::future<std::optional<std::string>> result) { try { promise.set_value(result.get()); } catch (...) { @@ -89,15 +89,15 @@ void BinaryCacheStore::getFile(const std::string & path, Sink & sink) sink(*promise.get_future().get()); } -std::shared_ptr<std::string> BinaryCacheStore::getFile(const std::string & path) +std::optional<std::string> BinaryCacheStore::getFile(const std::string & path) { StringSink sink; try { getFile(path, sink); } catch (NoSuchBinaryCacheFile &) { - return nullptr; + return std::nullopt; } - return sink.s; + return std::move(sink.s); } std::string BinaryCacheStore::narInfoFileFor(const StorePath & storePath) @@ -367,7 +367,7 @@ void BinaryCacheStore::queryPathInfoUncached(const StorePath & storePath, auto callbackPtr = std::make_shared<decltype(callback)>(std::move(callback)); getFile(narInfoFile, - {[=](std::future<std::shared_ptr<std::string>> fut) { + {[=](std::future<std::optional<std::string>> fut) { try { auto data = fut.get(); @@ -429,7 +429,7 @@ StorePath BinaryCacheStore::addTextToStore(const string & name, const string & s StringSink sink; dumpString(s, sink); - auto source = StringSource { *sink.s }; + StringSource source(sink.s); return addToStoreCommon(source, repair, CheckSigs, [&](HashResult nar) { ValidPathInfo info { path, nar.first }; info.narSize = nar.second; @@ -446,8 +446,8 @@ void BinaryCacheStore::queryRealisationUncached(const DrvOutput & id, auto callbackPtr = std::make_shared<decltype(callback)>(std::move(callback)); - Callback<std::shared_ptr<std::string>> newCallback = { - [=](std::future<std::shared_ptr<std::string>> fut) { + Callback<std::optional<std::string>> newCallback = { + [=](std::future<std::optional<std::string>> fut) { try { auto data = fut.get(); if (!data) return (*callbackPtr)(nullptr); @@ -490,7 +490,7 @@ void BinaryCacheStore::addSignatures(const StorePath & storePath, const StringSe writeNarInfo(narInfo); } -std::shared_ptr<std::string> BinaryCacheStore::getBuildLog(const StorePath & path) +std::optional<std::string> BinaryCacheStore::getBuildLog(const StorePath & path) { auto drvPath = path; |