mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2025-02-18 08:07:17 +02:00
Add InputAccessor::fetchToStore()
This commit is contained in:
parent
c0d33087c8
commit
2e0d63caf6
6 changed files with 59 additions and 27 deletions
|
@ -2257,13 +2257,7 @@ StorePath EvalState::copyPathToStore(PathSet & context, const SourcePath & path)
|
||||||
auto dstPath = i != srcToStore.end()
|
auto dstPath = i != srcToStore.end()
|
||||||
? i->second
|
? i->second
|
||||||
: [&]() {
|
: [&]() {
|
||||||
auto source = sinkToSource([&](Sink & sink) {
|
auto dstPath = path.fetchToStore(store, path.baseName(), nullptr, repair);
|
||||||
path.dumpPath(sink);
|
|
||||||
});
|
|
||||||
auto dstPath =
|
|
||||||
settings.readOnlyMode
|
|
||||||
? store->computeStorePathFromDump(*source, path.baseName()).first
|
|
||||||
: store->addToStoreFromDump(*source, path.baseName(), FileIngestionMethod::Recursive, htSHA256, repair);
|
|
||||||
allowPath(dstPath);
|
allowPath(dstPath);
|
||||||
srcToStore.insert_or_assign(path, dstPath);
|
srcToStore.insert_or_assign(path, dstPath);
|
||||||
printMsg(lvlChatty, "copied source '%1%' -> '%2%'", path, store->printStorePath(dstPath));
|
printMsg(lvlChatty, "copied source '%1%' -> '%2%'", path, store->printStorePath(dstPath));
|
||||||
|
|
|
@ -2006,7 +2006,8 @@ static void addPath(
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
PathFilter filter = filterFun ? ([&](const Path & p) {
|
std::unique_ptr<PathFilter> filter;
|
||||||
|
if (filterFun) filter = std::make_unique<PathFilter>([&](const Path & p) {
|
||||||
SourcePath path2{path.accessor, CanonPath(p)};
|
SourcePath path2{path.accessor, CanonPath(p)};
|
||||||
|
|
||||||
auto st = path2.lstat();
|
auto st = path2.lstat();
|
||||||
|
@ -2025,7 +2026,7 @@ static void addPath(
|
||||||
state.callFunction(*filterFun, 2, args, res, pos);
|
state.callFunction(*filterFun, 2, args, res, pos);
|
||||||
|
|
||||||
return state.forceBool(res, pos);
|
return state.forceBool(res, pos);
|
||||||
}) : defaultPathFilter;
|
});
|
||||||
|
|
||||||
std::optional<StorePath> expectedStorePath;
|
std::optional<StorePath> expectedStorePath;
|
||||||
if (expectedHash)
|
if (expectedHash)
|
||||||
|
@ -2036,13 +2037,10 @@ static void addPath(
|
||||||
// store on-demand.
|
// store on-demand.
|
||||||
|
|
||||||
if (!expectedHash || !state.store->isValidPath(*expectedStorePath)) {
|
if (!expectedHash || !state.store->isValidPath(*expectedStorePath)) {
|
||||||
auto source = sinkToSource([&](Sink & sink) {
|
// FIXME
|
||||||
path.dumpPath(sink, filter);
|
if (method != FileIngestionMethod::Recursive)
|
||||||
});
|
throw Error("'recursive = false' is not implemented");
|
||||||
auto dstPath =
|
auto dstPath = path.fetchToStore(state.store, name, filter.get(), state.repair);
|
||||||
settings.readOnlyMode
|
|
||||||
? state.store->computeStorePathFromDump(*source, name, method, htSHA256, refs).first
|
|
||||||
: state.store->addToStoreFromDump(*source, name, method, htSHA256, state.repair);
|
|
||||||
if (expectedHash && expectedStorePath != dstPath)
|
if (expectedHash && expectedStorePath != dstPath)
|
||||||
state.debugThrowLastTrace(Error("store path mismatch in (possibly filtered) path added from '%s'", path));
|
state.debugThrowLastTrace(Error("store path mismatch in (possibly filtered) path added from '%s'", path));
|
||||||
state.allowAndSetStorePathString(dstPath, v);
|
state.allowAndSetStorePathString(dstPath, v);
|
||||||
|
|
|
@ -121,16 +121,7 @@ std::pair<StorePath, Input> Input::fetchToStore(ref<Store> store) const
|
||||||
auto [storePath, input] = [&]() -> std::pair<StorePath, Input> {
|
auto [storePath, input] = [&]() -> std::pair<StorePath, Input> {
|
||||||
try {
|
try {
|
||||||
auto [accessor, input2] = getAccessor(store);
|
auto [accessor, input2] = getAccessor(store);
|
||||||
|
auto storePath = accessor->root().fetchToStore(store, input2.getName());
|
||||||
// FIXME: add an optimisation for the case where the
|
|
||||||
// accessor is an FSInputAccessor pointing to a store
|
|
||||||
// path.
|
|
||||||
auto source = sinkToSource([&, accessor{accessor}](Sink & sink) {
|
|
||||||
accessor->dumpPath(CanonPath::root, sink);
|
|
||||||
});
|
|
||||||
|
|
||||||
auto storePath = store->addToStoreFromDump(*source, input2.getName());
|
|
||||||
|
|
||||||
return {storePath, input2};
|
return {storePath, input2};
|
||||||
} catch (Error & e) {
|
} catch (Error & e) {
|
||||||
e.addTrace({}, "while fetching the input '%s'", to_string());
|
e.addTrace({}, "while fetching the input '%s'", to_string());
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#include "input-accessor.hh"
|
#include "input-accessor.hh"
|
||||||
#include "util.hh"
|
#include "util.hh"
|
||||||
|
#include "store-api.hh"
|
||||||
|
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
|
|
||||||
|
@ -85,6 +86,28 @@ void InputAccessor::dumpPath(
|
||||||
dump(path);
|
dump(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
StorePath InputAccessor::fetchToStore(
|
||||||
|
ref<Store> store,
|
||||||
|
const CanonPath & path,
|
||||||
|
std::string_view name,
|
||||||
|
PathFilter * filter,
|
||||||
|
RepairFlag repair)
|
||||||
|
{
|
||||||
|
// FIXME: add an optimisation for the case where the accessor is
|
||||||
|
// an FSInputAccessor pointing to a store path.
|
||||||
|
|
||||||
|
auto source = sinkToSource([&](Sink & sink) {
|
||||||
|
dumpPath(path, sink, filter ? *filter : defaultPathFilter);
|
||||||
|
});
|
||||||
|
|
||||||
|
auto storePath =
|
||||||
|
settings.readOnlyMode
|
||||||
|
? store->computeStorePathFromDump(*source, name).first
|
||||||
|
: store->addToStoreFromDump(*source, name, FileIngestionMethod::Recursive, htSHA256, repair);
|
||||||
|
|
||||||
|
return storePath;
|
||||||
|
}
|
||||||
|
|
||||||
std::optional<InputAccessor::Stat> InputAccessor::maybeLstat(const CanonPath & path)
|
std::optional<InputAccessor::Stat> InputAccessor::maybeLstat(const CanonPath & path)
|
||||||
{
|
{
|
||||||
// FIXME: merge these into one operation.
|
// FIXME: merge these into one operation.
|
||||||
|
@ -164,6 +187,15 @@ ref<MemoryInputAccessor> makeMemoryInputAccessor()
|
||||||
return make_ref<MemoryInputAccessorImpl>();
|
return make_ref<MemoryInputAccessorImpl>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
StorePath SourcePath::fetchToStore(
|
||||||
|
ref<Store> store,
|
||||||
|
std::string_view name,
|
||||||
|
PathFilter * filter,
|
||||||
|
RepairFlag repair) const
|
||||||
|
{
|
||||||
|
return accessor->fetchToStore(store, path, name, filter, repair);
|
||||||
|
}
|
||||||
|
|
||||||
std::string_view SourcePath::baseName() const
|
std::string_view SourcePath::baseName() const
|
||||||
{
|
{
|
||||||
return path.baseName().value_or("source");
|
return path.baseName().value_or("source");
|
||||||
|
|
|
@ -4,12 +4,16 @@
|
||||||
#include "types.hh"
|
#include "types.hh"
|
||||||
#include "archive.hh"
|
#include "archive.hh"
|
||||||
#include "canon-path.hh"
|
#include "canon-path.hh"
|
||||||
|
#include "repair-flag.hh"
|
||||||
|
|
||||||
namespace nix {
|
namespace nix {
|
||||||
|
|
||||||
MakeError(RestrictedPathError, Error);
|
MakeError(RestrictedPathError, Error);
|
||||||
|
|
||||||
struct SourcePath;
|
struct SourcePath;
|
||||||
|
struct StorePath;
|
||||||
|
class Store;
|
||||||
|
enum RepairFlag;
|
||||||
|
|
||||||
struct InputAccessor : public std::enable_shared_from_this<InputAccessor>
|
struct InputAccessor : public std::enable_shared_from_this<InputAccessor>
|
||||||
{
|
{
|
||||||
|
@ -52,6 +56,13 @@ struct InputAccessor : public std::enable_shared_from_this<InputAccessor>
|
||||||
Sink & sink,
|
Sink & sink,
|
||||||
PathFilter & filter = defaultPathFilter);
|
PathFilter & filter = defaultPathFilter);
|
||||||
|
|
||||||
|
StorePath fetchToStore(
|
||||||
|
ref<Store> store,
|
||||||
|
const CanonPath & path,
|
||||||
|
std::string_view name,
|
||||||
|
PathFilter * filter = nullptr,
|
||||||
|
RepairFlag repair = NoRepair);
|
||||||
|
|
||||||
/* Return a corresponding path in the root filesystem, if
|
/* Return a corresponding path in the root filesystem, if
|
||||||
possible. This is only possible for inputs that are
|
possible. This is only possible for inputs that are
|
||||||
materialized in the root filesystem. */
|
materialized in the root filesystem. */
|
||||||
|
@ -124,6 +135,12 @@ struct SourcePath
|
||||||
PathFilter & filter = defaultPathFilter) const
|
PathFilter & filter = defaultPathFilter) const
|
||||||
{ return accessor->dumpPath(path, sink, filter); }
|
{ return accessor->dumpPath(path, sink, filter); }
|
||||||
|
|
||||||
|
StorePath fetchToStore(
|
||||||
|
ref<Store> store,
|
||||||
|
std::string_view name,
|
||||||
|
PathFilter * filter = nullptr,
|
||||||
|
RepairFlag repair = NoRepair) const;
|
||||||
|
|
||||||
std::optional<CanonPath> getPhysicalPath() const
|
std::optional<CanonPath> getPhysicalPath() const
|
||||||
{ return accessor->getPhysicalPath(path); }
|
{ return accessor->getPhysicalPath(path); }
|
||||||
|
|
||||||
|
|
|
@ -8,4 +8,4 @@ libplugintest_ALLOW_UNDEFINED := 1
|
||||||
|
|
||||||
libplugintest_EXCLUDE_FROM_LIBRARY_LIST := 1
|
libplugintest_EXCLUDE_FROM_LIBRARY_LIST := 1
|
||||||
|
|
||||||
libplugintest_CXXFLAGS := -I src/libutil -I src/libexpr -I src/libfetchers
|
libplugintest_CXXFLAGS := -I src/libutil -I src/libexpr -I src/libfetchers -I src/libstore
|
||||||
|
|
Loading…
Add table
Reference in a new issue