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
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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().
|
||||
|
||||
Reference in New Issue
Block a user