From f1ecfbdd4881959ea2b718e16ead8260358e3412 Mon Sep 17 00:00:00 2001 From: eldritch horrors Date: Sat, 1 Mar 2025 23:55:42 +0100 Subject: [PATCH] libstore: split Store::computeStorePathForPath the two variants compute their store path hashes very differently, and the flat version ignores the filter passed in by the user entirely. in a future change we want to move filters out of store methods entirely, splitting them now will make that task a lot easier when we are ready. Change-Id: I5f23a26ca08e81923f33adf687056d0d464c2cb8 --- lix/libfetchers/fetch-to-store.cc | 17 +++++++++++++---- lix/libstore/store-api.cc | 21 ++++++++++++++------- lix/libstore/store-api.hh | 7 ++++--- 3 files changed, 31 insertions(+), 14 deletions(-) diff --git a/lix/libfetchers/fetch-to-store.cc b/lix/libfetchers/fetch-to-store.cc index ca098f330..da9857fe0 100644 --- a/lix/libfetchers/fetch-to-store.cc +++ b/lix/libfetchers/fetch-to-store.cc @@ -15,11 +15,20 @@ try { Activity act(*logger, lvlChatty, actUnknown, fmt("copying '%s' to the store", path)); auto filter2 = filter ? *filter : defaultPathFilter; + auto physicalPath = path.canonical().abs(); - co_return - settings.readOnlyMode - ? store.computeStorePathForPath(name, path.canonical().abs(), method, filter2) - : TRY_AWAIT(store.addToStore(name, path.canonical().abs(), method, HashType::SHA256, filter2, repair)); + if (settings.readOnlyMode) { + switch (method) { + case FileIngestionMethod::Recursive: + co_return store.computeStorePathForPathRecursive(name, physicalPath, filter2); + case FileIngestionMethod::Flat: + co_return store.computeStorePathForPathFlat(name, physicalPath); + } + } else { + co_return TRY_AWAIT( + store.addToStore(name, physicalPath, method, HashType::SHA256, filter2, repair) + ); + } } catch (...) { co_return result::current_exception(); } diff --git a/lix/libstore/store-api.cc b/lix/libstore/store-api.cc index e3f9ae76b..07d7a240d 100644 --- a/lix/libstore/store-api.cc +++ b/lix/libstore/store-api.cc @@ -246,15 +246,22 @@ StorePath Store::makeFixedOutputPathFromCA(std::string_view name, const ContentA } -StorePath Store::computeStorePathForPath(std::string_view name, - const Path & srcPath, FileIngestionMethod method, PathFilter & filter) const +StorePath Store::computeStorePathForPathRecursive(std::string_view name, + const Path & srcPath, PathFilter & filter) const { - Hash h = method == FileIngestionMethod::Recursive - ? hashPath(HashType::SHA256, srcPath, filter).first - : hashFile(HashType::SHA256, srcPath); FixedOutputInfo caInfo { - .method = method, - .hash = h, + .method = FileIngestionMethod::Recursive, + .hash = hashPath(HashType::SHA256, srcPath, filter).first, + .references = {}, + }; + return makeFixedOutputPath(name, caInfo); +} + +StorePath Store::computeStorePathForPathFlat(std::string_view name, const Path & srcPath) const +{ + FixedOutputInfo caInfo { + .method = FileIngestionMethod::Flat, + .hash = hashFile(HashType::SHA256, srcPath), .references = {}, }; return makeFixedOutputPath(name, caInfo); diff --git a/lix/libstore/store-api.hh b/lix/libstore/store-api.hh index e06d8f862..8ccec21e6 100644 --- a/lix/libstore/store-api.hh +++ b/lix/libstore/store-api.hh @@ -315,9 +315,10 @@ public: * * @return the store path to which srcPath is to be copied. */ - StorePath computeStorePathForPath(std::string_view name, - const Path & srcPath, FileIngestionMethod method = FileIngestionMethod::Recursive, - PathFilter & filter = defaultPathFilter) const; + StorePath computeStorePathForPathRecursive( + std::string_view name, const Path & srcPath, PathFilter & filter = defaultPathFilter + ) const; + StorePath computeStorePathForPathFlat(std::string_view name, const Path & srcPath) const; /** * Preparatory part of addTextToStore().