1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-21 09:49:36 +01:00

treewide: Add Store::requireStoreObjectAccessor, simplify uses of getFSAccessor

This is a simple wrapper around getFSAccessor that throws an InvalidPath
error. This simplifies usage in callsites that only care about getting
a non-null accessor.
This commit is contained in:
Sergei Zimmerman 2025-10-14 23:58:18 +03:00
parent 959c244a12
commit 0c32fb3fa2
No known key found for this signature in database
10 changed files with 33 additions and 22 deletions

View file

@ -724,10 +724,28 @@ public:
* the Nix store.
*
* @return nullptr if the store doesn't contain an object at the
* givine path.
* given path.
*/
virtual std::shared_ptr<SourceAccessor> getFSAccessor(const StorePath & path, bool requireValidPath = true) = 0;
/**
* Get an accessor for the store object or throw an Error if it's invalid or
* doesn't exist.
*
* @throws InvalidPath if the store object doesn't exist or (if requireValidPath = true) is
* invalid.
*/
[[nodiscard]] ref<SourceAccessor> requireStoreObjectAccessor(const StorePath & path, bool requireValidPath = true)
{
auto accessor = getFSAccessor(path, requireValidPath);
if (!accessor) {
throw InvalidPath(
requireValidPath ? "path '%1%' is not a valid store path" : "store path '%1%' does not exist",
printStorePath(path));
}
return ref<SourceAccessor>{accessor};
}
/**
* Repair the contents of the given path by redownloading it using
* a substituter (if available).

View file

@ -1130,7 +1130,7 @@ Derivation Store::derivationFromPath(const StorePath & drvPath)
static Derivation readDerivationCommon(Store & store, const StorePath & drvPath, bool requireValidPath)
{
auto accessor = store.getFSAccessor(drvPath, requireValidPath);
auto accessor = store.requireStoreObjectAccessor(drvPath, requireValidPath);
try {
return parseDerivation(store, accessor->readFile(CanonPath::root), Derivation::nameFromPath(drvPath));
} catch (FormatError & e) {