forked from lix-project/lix
refactor: Un-callback transform Store::queryPathInfoFromClientCache
This part of the code was not necessarily callback based. Removing CPS is always nice; particularly if there's no loss of functionality, like here.
This commit is contained in:
parent
d0a284284b
commit
8983ee8b2e
|
@ -685,8 +685,7 @@ static bool goodStorePath(const StorePath & expected, const StorePath & actual)
|
||||||
&& (expected.name() == Store::MissingName || expected.name() == actual.name());
|
&& (expected.name() == Store::MissingName || expected.name() == actual.name());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Store::queryPathInfoFromClientCache(const StorePath & storePath,
|
std::optional<ref<const ValidPathInfo>> Store::queryPathInfoFromClientCache(const StorePath & storePath)
|
||||||
Callback<ref<const ValidPathInfo>> & callback)
|
|
||||||
{
|
{
|
||||||
auto hashPart = std::string(storePath.hashPart());
|
auto hashPart = std::string(storePath.hashPart());
|
||||||
|
|
||||||
|
@ -696,8 +695,7 @@ bool Store::queryPathInfoFromClientCache(const StorePath & storePath,
|
||||||
stats.narInfoReadAverted++;
|
stats.narInfoReadAverted++;
|
||||||
if (!res->didExist())
|
if (!res->didExist())
|
||||||
throw InvalidPath("path '%s' is not valid", printStorePath(storePath));
|
throw InvalidPath("path '%s' is not valid", printStorePath(storePath));
|
||||||
callback(ref<const ValidPathInfo>(res->value));
|
return ref(res->value);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -713,12 +711,11 @@ bool Store::queryPathInfoFromClientCache(const StorePath & storePath,
|
||||||
!goodStorePath(storePath, res.second->path))
|
!goodStorePath(storePath, res.second->path))
|
||||||
throw InvalidPath("path '%s' is not valid", printStorePath(storePath));
|
throw InvalidPath("path '%s' is not valid", printStorePath(storePath));
|
||||||
}
|
}
|
||||||
callback(ref<const ValidPathInfo>(res.second));
|
return ref(res.second);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -728,8 +725,11 @@ void Store::queryPathInfo(const StorePath & storePath,
|
||||||
auto hashPart = std::string(storePath.hashPart());
|
auto hashPart = std::string(storePath.hashPart());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (queryPathInfoFromClientCache(storePath, callback))
|
auto r = queryPathInfoFromClientCache(storePath);
|
||||||
return;
|
if (r.has_value()) {
|
||||||
|
ref<const ValidPathInfo> & info = *r;
|
||||||
|
return callback(ref(info));
|
||||||
|
}
|
||||||
} catch (...) { return callback.rethrow(); }
|
} catch (...) { return callback.rethrow(); }
|
||||||
|
|
||||||
auto callbackPtr = std::make_shared<decltype(callback)>(std::move(callback));
|
auto callbackPtr = std::make_shared<decltype(callback)>(std::move(callback));
|
||||||
|
|
|
@ -285,14 +285,14 @@ public:
|
||||||
/**
|
/**
|
||||||
* NOTE: this is not the final interface - to be modified in next commit.
|
* NOTE: this is not the final interface - to be modified in next commit.
|
||||||
*
|
*
|
||||||
* Asynchronous version that only queries the local narinfo cache and not
|
* Version of queryPathInfo() that only queries the local narinfo cache and not
|
||||||
* the actual store.
|
* the actual store.
|
||||||
*
|
*
|
||||||
* @return true if the path was known and the callback invoked
|
* @return `std::make_optional(vpi)` if the path is known
|
||||||
* @return false if the path was not known and the callback not invoked
|
* @return `std::null_opt` if the path was not known to be valid or invalid
|
||||||
* @throw InvalidPathError if the path is known to be invalid
|
* @throw InvalidPathError if the path is known to be invalid
|
||||||
*/
|
*/
|
||||||
bool queryPathInfoFromClientCache(const StorePath & path, Callback<ref<const ValidPathInfo>> & callback);
|
std::optional<ref<const ValidPathInfo>> queryPathInfoFromClientCache(const StorePath & path);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Query the information about a realisation.
|
* Query the information about a realisation.
|
||||||
|
|
Loading…
Reference in a new issue