libstore: split fetchToStore
only a single caller uses flat fetching at all. it still makes sense to not inline that single caller for now, mostly due to activity reporting Change-Id: I1a6420868443c3a684deafc7a4f567d4d4b1bd53
This commit is contained in:
@@ -48,7 +48,7 @@ std::optional<DerivedPathWithInfo> InstallableValue::trySinglePathToDerivedPaths
|
||||
{
|
||||
if (v.type() == nPath) {
|
||||
auto storePath = state.aio.blockOn(
|
||||
fetchToStore(*evaluator->store, state.ctx.paths.checkSourcePath(v.path()))
|
||||
fetchToStoreRecursive(*evaluator->store, state.ctx.paths.checkSourcePath(v.path()))
|
||||
);
|
||||
return {{
|
||||
.path = DerivedPath::Opaque {
|
||||
|
||||
+1
-2
@@ -2383,11 +2383,10 @@ try {
|
||||
auto dstPath = i != srcToStore.end()
|
||||
? i->second
|
||||
: ({
|
||||
auto dstPath = TRY_AWAIT(fetchToStore(
|
||||
auto dstPath = TRY_AWAIT(fetchToStoreRecursive(
|
||||
*store,
|
||||
checkSourcePath(path),
|
||||
path.baseName(),
|
||||
FileIngestionMethod::Recursive,
|
||||
nullptr,
|
||||
repair
|
||||
));
|
||||
|
||||
@@ -1564,14 +1564,14 @@ static void addPath(
|
||||
});
|
||||
|
||||
if (!expectedHash || !state.ctx.store->isValidPath(*expectedStorePath)) {
|
||||
auto dstPath = state.aio.blockOn(fetchToStore(
|
||||
*state.ctx.store,
|
||||
state.ctx.paths.checkSourcePath(CanonPath(realPath)),
|
||||
name,
|
||||
method,
|
||||
&filter,
|
||||
state.ctx.repair
|
||||
));
|
||||
auto checkedPath = state.ctx.paths.checkSourcePath(CanonPath(realPath));
|
||||
auto dstPath = state.aio.blockOn(
|
||||
method == FileIngestionMethod::Flat
|
||||
? fetchToStoreFlat(*state.ctx.store, checkedPath, name, state.ctx.repair)
|
||||
: fetchToStoreRecursive(
|
||||
*state.ctx.store, checkedPath, name, &filter, state.ctx.repair
|
||||
)
|
||||
);
|
||||
if (expectedHash && expectedStorePath != dstPath)
|
||||
state.ctx.errors.make<EvalError>(
|
||||
"store path mismatch in (possibly filtered) path added from '%s'",
|
||||
|
||||
@@ -4,11 +4,26 @@
|
||||
|
||||
namespace nix {
|
||||
|
||||
kj::Promise<Result<StorePath>> fetchToStore(
|
||||
kj::Promise<Result<StorePath>> fetchToStoreFlat(
|
||||
Store & store,
|
||||
const CheckedSourcePath & path,
|
||||
std::string_view name,
|
||||
RepairFlag repair)
|
||||
try {
|
||||
Activity act(*logger, lvlChatty, actUnknown, fmt("copying '%s' to the store", path));
|
||||
auto physicalPath = path.canonical().abs();
|
||||
|
||||
co_return settings.readOnlyMode
|
||||
? store.computeStorePathForPathFlat(name, physicalPath)
|
||||
: TRY_AWAIT(store.addToStoreFlat(name, physicalPath, HashType::SHA256, repair));
|
||||
} catch (...) {
|
||||
co_return result::current_exception();
|
||||
}
|
||||
|
||||
kj::Promise<Result<StorePath>> fetchToStoreRecursive(
|
||||
Store & store,
|
||||
const CheckedSourcePath & path,
|
||||
std::string_view name,
|
||||
FileIngestionMethod method,
|
||||
PathFilter * filter,
|
||||
RepairFlag repair)
|
||||
try {
|
||||
@@ -17,23 +32,9 @@ try {
|
||||
auto filter2 = filter ? *filter : defaultPathFilter;
|
||||
auto physicalPath = path.canonical().abs();
|
||||
|
||||
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 {
|
||||
switch (method) {
|
||||
case FileIngestionMethod::Recursive:
|
||||
co_return TRY_AWAIT(
|
||||
store.addToStoreRecursive(name, physicalPath, HashType::SHA256, filter2, repair)
|
||||
);
|
||||
case FileIngestionMethod::Flat:
|
||||
co_return TRY_AWAIT(store.addToStoreFlat(name, physicalPath, HashType::SHA256, repair));
|
||||
}
|
||||
}
|
||||
co_return settings.readOnlyMode
|
||||
? store.computeStorePathForPathRecursive(name, physicalPath, filter2)
|
||||
: TRY_AWAIT(store.addToStoreRecursive(name, physicalPath, HashType::SHA256, filter2, repair));
|
||||
} catch (...) {
|
||||
co_return result::current_exception();
|
||||
}
|
||||
|
||||
@@ -11,11 +11,15 @@ namespace nix {
|
||||
/**
|
||||
* Copy the `path` to the Nix store.
|
||||
*/
|
||||
kj::Promise<Result<StorePath>> fetchToStore(
|
||||
kj::Promise<Result<StorePath>> fetchToStoreFlat(
|
||||
Store & store,
|
||||
const CheckedSourcePath & path,
|
||||
std::string_view name = "source",
|
||||
RepairFlag repair = NoRepair);
|
||||
kj::Promise<Result<StorePath>> fetchToStoreRecursive(
|
||||
Store & store,
|
||||
const CheckedSourcePath & path,
|
||||
std::string_view name = "source",
|
||||
FileIngestionMethod method = FileIngestionMethod::Recursive,
|
||||
PathFilter * filter = nullptr,
|
||||
RepairFlag repair = NoRepair);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user