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

Merge pull request #14249 from NixOS/more-to-real-path-cleanups

More toRealPath cleanups
This commit is contained in:
John Ericson 2025-10-14 22:46:15 +00:00 committed by GitHub
commit 6dcc468253
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 47 additions and 38 deletions

View file

@ -529,15 +529,9 @@ bool Worker::pathContentsGood(const StorePath & path)
return i->second;
printInfo("checking path '%s'...", store.printStorePath(path));
auto info = store.queryPathInfo(path);
bool res;
if (!pathExists(store.printStorePath(path)))
res = false;
else {
auto current = hashPath(
{store.getFSAccessor(), CanonPath(path.to_string())},
FileIngestionMethod::NixArchive,
info->narHash.algo)
.first;
bool res = false;
if (auto accessor = store.getFSAccessor(path, /*requireValidPath=*/false)) {
auto current = hashPath({ref{accessor}}, FileIngestionMethod::NixArchive, info->narHash.algo).first;
Hash nullHash(HashAlgorithm::SHA256);
res = info->narHash == nullHash || info->narHash == current;
}

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) {