diff options
author | Vincent Ambo <mail@tazj.in> | 2020-08-21T03·00+0100 |
---|---|---|
committer | tazjin <mail@tazj.in> | 2020-08-23T11·58+0000 |
commit | 1cf11317cac2c11d20b2324d4283814f1351c1a3 (patch) | |
tree | 5a77610f94b0b8fd60bf64c1ca765b05ab8a6fd6 /third_party/nix/src/libstore/store-api.cc | |
parent | 1443298657156107704b5d9fcfa7356ee8fa8789 (diff) |
refactor(tvix/libutil): Mark single-argument constructors explicit r/1704
This is the clang-tidy lint 'google-explicit-constructor'. There's a whole bunch of breakage that was introduced by this, and we had to opt out a few types of this (esp. the string formatting crap). In some cases minor other changes have been done to keep the code working, instead of converting between types (e.g. an explicit comparison operator implementation for nix::Pid). Change-Id: I12e1ca51a6bc2c882dba81a2526b9729d26988e7 Reviewed-on: https://cl.tvl.fyi/c/depot/+/1832 Tested-by: BuildkiteCI Reviewed-by: kanepyork <rikingcoding@gmail.com> Reviewed-by: glittershark <grfn@gws.fyi>
Diffstat (limited to 'third_party/nix/src/libstore/store-api.cc')
-rw-r--r-- | third_party/nix/src/libstore/store-api.cc | 96 |
1 files changed, 52 insertions, 44 deletions
diff --git a/third_party/nix/src/libstore/store-api.cc b/third_party/nix/src/libstore/store-api.cc index 0ea6b1d62c34..d7ca54fa9a77 100644 --- a/third_party/nix/src/libstore/store-api.cc +++ b/third_party/nix/src/libstore/store-api.cc @@ -392,7 +392,10 @@ Path Store::computeStorePathForText(const std::string& name, } Store::Store(const Params& params) - : Config(params), state({(size_t)pathInfoCacheSize}) {} + : Config(params), + state(Sync<State>{ + State{LRUCache<std::string, std::shared_ptr<ValidPathInfo>>( + (size_t)pathInfoCacheSize)}}) {} std::string Store::getUri() { return ""; } @@ -446,13 +449,15 @@ bool Store::isValidPathUncached(const Path& path) { ref<const ValidPathInfo> Store::queryPathInfo(const Path& storePath) { std::promise<ref<ValidPathInfo>> promise; - queryPathInfo(storePath, {[&](std::future<ref<ValidPathInfo>> result) { - try { - promise.set_value(result.get()); - } catch (...) { - promise.set_exception(std::current_exception()); - } - }}); + queryPathInfo( + storePath, + Callback<ref<ValidPathInfo>>([&](std::future<ref<ValidPathInfo>> result) { + try { + promise.set_value(result.get()); + } catch (...) { + promise.set_exception(std::current_exception()); + } + })); return promise.get_future().get(); } @@ -503,31 +508,33 @@ void Store::queryPathInfo(const Path& storePath, auto callbackPtr = std::make_shared<decltype(callback)>(std::move(callback)); queryPathInfoUncached( - storePath, {[this, storePath, hashPart, callbackPtr]( - std::future<std::shared_ptr<ValidPathInfo>> fut) { - try { - auto info = fut.get(); + storePath, + Callback<std::shared_ptr<ValidPathInfo>>{ + [this, storePath, hashPart, + callbackPtr](std::future<std::shared_ptr<ValidPathInfo>> fut) { + try { + auto info = fut.get(); - if (diskCache) { - diskCache->upsertNarInfo(getUri(), hashPart, info); - } + if (diskCache) { + diskCache->upsertNarInfo(getUri(), hashPart, info); + } - { - auto state_(state.lock()); - state_->pathInfoCache.upsert(hashPart, info); - } + { + auto state_(state.lock()); + state_->pathInfoCache.upsert(hashPart, info); + } - if (!info || (info->path != storePath && - !storePathToName(storePath).empty())) { - stats.narInfoMissing++; - throw InvalidPath("path '%s' is not valid", storePath); - } + if (!info || (info->path != storePath && + !storePathToName(storePath).empty())) { + stats.narInfoMissing++; + throw InvalidPath("path '%s' is not valid", storePath); + } - (*callbackPtr)(ref<ValidPathInfo>(info)); - } catch (...) { - callbackPtr->rethrow(); - } - }}); + (*callbackPtr)(ref<ValidPathInfo>(info)); + } catch (...) { + callbackPtr->rethrow(); + } + }}); } PathSet Store::queryValidPaths(const PathSet& paths, @@ -545,21 +552,22 @@ PathSet Store::queryValidPaths(const PathSet& paths, auto doQuery = [&](const Path& path) { checkInterrupt(); - queryPathInfo( - path, {[path, &state_, &wakeup](std::future<ref<ValidPathInfo>> fut) { - auto state(state_.lock()); - try { - auto info = fut.get(); - state->valid.insert(path); - } catch (InvalidPath&) { - } catch (...) { - state->exc = std::current_exception(); - } - assert(state->left); - if (--state->left == 0u) { - wakeup.notify_one(); - } - }}); + queryPathInfo(path, Callback<ref<ValidPathInfo>>( + [path, &state_, + &wakeup](std::future<ref<ValidPathInfo>> fut) { + auto state(state_.lock()); + try { + auto info = fut.get(); + state->valid.insert(path); + } catch (InvalidPath&) { + } catch (...) { + state->exc = std::current_exception(); + } + assert(state->left); + if (--state->left == 0u) { + wakeup.notify_one(); + } + })); }; for (auto& path : paths) { |