From 436bc1f39e99d0fe9ce8549933572ec0b1d1f979 Mon Sep 17 00:00:00 2001 From: Sergei Zimmerman Date: Tue, 18 Nov 2025 03:22:27 +0300 Subject: [PATCH] treewide: Reduce usage of PosixSourceAccessor::createAtRoot Replaces the usage of createAtRoot, which goes as far up the directory tree as possible with rooted variant makeFSSourceAccessor. The changes in this patch should be safe wrt to not asserting on relative paths. Arguments passed to makeFSSourceAccessor here should already be using absolute paths. --- src/libstore/local-store.cc | 14 +++++--------- src/libstore/optimise-store.cc | 2 +- src/nix/prefetch.cc | 3 +-- 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/src/libstore/local-store.cc b/src/libstore/local-store.cc index 1f945ecf6..a849576f6 100644 --- a/src/libstore/local-store.cc +++ b/src/libstore/local-store.cc @@ -1246,10 +1246,8 @@ StorePath LocalStore::addToStoreFromDump( auto desc = ContentAddressWithReferences::fromParts( hashMethod, - methodsMatch - ? dumpHash - : hashPath(PosixSourceAccessor::createAtRoot(tempPath), hashMethod.getFileIngestionMethod(), hashAlgo) - .first, + methodsMatch ? dumpHash + : hashPath(makeFSSourceAccessor(tempPath), hashMethod.getFileIngestionMethod(), hashAlgo).first, { .others = references, // caller is not capable of creating a self-reference, because this is content-addressed without modulus @@ -1385,11 +1383,9 @@ bool LocalStore::verifyStore(bool checkContents, RepairFlag repair) checkInterrupt(); auto name = link.path().filename(); printMsg(lvlTalkative, "checking contents of %s", name); - std::string hash = hashPath( - PosixSourceAccessor::createAtRoot(link.path()), - FileIngestionMethod::NixArchive, - HashAlgorithm::SHA256) - .first.to_string(HashFormat::Nix32, false); + std::string hash = + hashPath(makeFSSourceAccessor(link.path()), FileIngestionMethod::NixArchive, HashAlgorithm::SHA256) + .first.to_string(HashFormat::Nix32, false); if (hash != name.string()) { printError("link %s was modified! expected hash %s, got '%s'", link.path(), name, hash); if (repair) { diff --git a/src/libstore/optimise-store.cc b/src/libstore/optimise-store.cc index 3e02fa812..dca093e04 100644 --- a/src/libstore/optimise-store.cc +++ b/src/libstore/optimise-store.cc @@ -172,7 +172,7 @@ void LocalStore::optimisePath_( auto stLink = lstat(linkPath.string()); if (st.st_size != stLink.st_size || (repair && hash != ({ hashPath( - PosixSourceAccessor::createAtRoot(linkPath), + makeFSSourceAccessor(linkPath), FileSerialisationMethod::NixArchive, HashAlgorithm::SHA256) .hash; diff --git a/src/nix/prefetch.cc b/src/nix/prefetch.cc index d875f8e4b..57bc3740c 100644 --- a/src/nix/prefetch.cc +++ b/src/nix/prefetch.cc @@ -138,8 +138,7 @@ std::tuple prefetchFile( Activity act(*logger, lvlChatty, actUnknown, fmt("adding '%s' to the store", url.to_string())); - auto info = store->addToStoreSlow( - *name, PosixSourceAccessor::createAtRoot(tmpFile), method, hashAlgo, {}, expectedHash); + auto info = store->addToStoreSlow(*name, makeFSSourceAccessor(tmpFile), method, hashAlgo, {}, expectedHash); storePath = info.path; assert(info.ca); hash = info.ca->hash;