Remove FSInputAccessor

This commit is contained in:
Eelco Dolstra 2024-05-03 12:30:28 +02:00
parent ba5929c7be
commit 20558e0462
15 changed files with 48 additions and 58 deletions

View File

@ -21,7 +21,6 @@
#include "url.hh"
#include "registry.hh"
#include "build-result.hh"
#include "fs-input-accessor.hh"
#include <regex>
#include <queue>
@ -147,7 +146,7 @@ MixFlakeOptions::MixFlakeOptions()
.category = category,
.labels = {"flake-lock-path"},
.handler = {[&](std::string lockFilePath) {
lockFlags.referenceLockFilePath = getUnfilteredRootPath(CanonPath(absPath(lockFilePath)));
lockFlags.referenceLockFilePath = {makeFSSourceAccessor(), CanonPath(absPath(lockFilePath))};
}},
.completer = completePath
});

View File

@ -15,7 +15,6 @@
#include "function-trace.hh"
#include "profiles.hh"
#include "print.hh"
#include "fs-input-accessor.hh"
#include "filtering-input-accessor.hh"
#include "memory-source-accessor.hh"
#include "signals.hh"
@ -400,14 +399,14 @@ EvalState::EvalState(
, emptyBindings(0)
, rootFS(
evalSettings.restrictEval || evalSettings.pureEval
? ref<SourceAccessor>(AllowListInputAccessor::create(makeFSInputAccessor(), {},
? ref<SourceAccessor>(AllowListInputAccessor::create(makeFSSourceAccessor(), {},
[](const CanonPath & path) -> RestrictedPathError {
auto modeInformation = evalSettings.pureEval
? "in pure evaluation mode (use '--impure' to override)"
: "in restricted mode";
throw RestrictedPathError("access to absolute path '%1%' is forbidden %2%", path, modeInformation);
}))
: makeFSInputAccessor())
: makeFSSourceAccessor())
, corepkgsFS(make_ref<MemorySourceAccessor>())
, internalFS(make_ref<MemorySourceAccessor>())
, derivationInternal{corepkgsFS->addFile(

View File

@ -15,7 +15,6 @@
#include "value-to-json.hh"
#include "value-to-xml.hh"
#include "primops.hh"
#include "fs-input-accessor.hh"
#include "fetch-to-store.hh"
#include <boost/container/small_vector.hpp>

View File

@ -14,7 +14,7 @@ StorePath fetchToStore(
RepairFlag repair)
{
// FIXME: add an optimisation for the case where the accessor is
// an FSInputAccessor pointing to a store path.
// a `PosixSourceAccessor` pointing to a store path.
std::optional<fetchers::Attrs> cacheKey;

View File

@ -1,34 +0,0 @@
#include "fs-input-accessor.hh"
#include "posix-source-accessor.hh"
#include "store-api.hh"
namespace nix {
ref<SourceAccessor> makeFSInputAccessor()
{
return make_ref<PosixSourceAccessor>();
}
ref<SourceAccessor> makeFSInputAccessor(std::filesystem::path root)
{
return make_ref<PosixSourceAccessor>(std::move(root));
}
ref<SourceAccessor> makeStorePathAccessor(
ref<Store> store,
const StorePath & storePath)
{
// FIXME: should use `store->getFSAccessor()`
auto root = std::filesystem::path { store->toRealPath(storePath) };
auto accessor = makeFSInputAccessor(root);
accessor->setPathDisplay(root.string());
return accessor;
}
SourcePath getUnfilteredRootPath(CanonPath path)
{
static auto rootFS = makeFSInputAccessor();
return {rootFS, path};
}
}

View File

@ -1,5 +1,4 @@
#include "git-utils.hh"
#include "fs-input-accessor.hh"
#include "cache.hh"
#include "finally.hh"
#include "processes.hh"
@ -948,7 +947,7 @@ ref<SourceAccessor> GitRepoImpl::getAccessor(const WorkdirInfo & wd, bool export
wd.files.empty()
? makeEmptySourceAccessor()
: AllowListInputAccessor::create(
makeFSInputAccessor(path),
makeFSSourceAccessor(path),
std::set<CanonPath> { wd.files },
std::move(makeNotAllowedError)).cast<SourceAccessor>();
if (exportIgnore)

View File

@ -1,8 +1,7 @@
#include "fetchers.hh"
#include "store-api.hh"
#include "archive.hh"
#include "fs-input-accessor.hh"
#include "posix-source-accessor.hh"
#include "store-path-accessor.hh"
namespace nix::fetchers {

View File

@ -0,0 +1,17 @@
#include "store-path-accessor.hh"
#include "store-api.hh"
namespace nix {
ref<SourceAccessor> makeStorePathAccessor(
ref<Store> store,
const StorePath & storePath)
{
// FIXME: should use `store->getFSAccessor()`
auto root = std::filesystem::path { store->toRealPath(storePath) };
auto accessor = makeFSSourceAccessor(root);
accessor->setPathDisplay(root.string());
return accessor;
}
}

View File

@ -7,10 +7,6 @@ namespace nix {
class StorePath;
class Store;
ref<SourceAccessor> makeFSInputAccessor();
ref<SourceAccessor> makeFSInputAccessor(std::filesystem::path root);
ref<SourceAccessor> makeStorePathAccessor(
ref<Store> store,
const StorePath & storePath);

View File

@ -8,8 +8,7 @@
#include "tarfile.hh"
#include "types.hh"
#include "split.hh"
#include "posix-source-accessor.hh"
#include "fs-input-accessor.hh"
#include "store-path-accessor.hh"
#include "store-api.hh"
#include "git-utils.hh"

View File

@ -9,7 +9,6 @@
#include "pathlocks.hh"
#include "processes.hh"
#include "git.hh"
#include "fs-input-accessor.hh"
#include "mounted-input-accessor.hh"
#include "git-utils.hh"
#include "logging.hh"

View File

@ -6,8 +6,7 @@
#include "tarfile.hh"
#include "store-api.hh"
#include "url-parts.hh"
#include "fs-input-accessor.hh"
#include "posix-source-accessor.hh"
#include "store-path-accessor.hh"
#include "fetch-settings.hh"
#include <sys/time.h>
@ -211,10 +210,9 @@ struct MercurialInputScheme : InputScheme
return files.count(file);
};
PosixSourceAccessor accessor;
auto storePath = store->addToStore(
input.getName(),
accessor, CanonPath { actualPath },
*makeFSSourceAccessor(), CanonPath { actualPath },
FileIngestionMethod::Recursive, HashAlgorithm::SHA256, {},
filter);
@ -320,8 +318,7 @@ struct MercurialInputScheme : InputScheme
deletePath(tmpDir + "/.hg_archival.txt");
PosixSourceAccessor accessor;
auto storePath = store->addToStore(name, accessor, CanonPath { tmpDir });
auto storePath = store->addToStore(name, *makeFSSourceAccessor(), CanonPath { tmpDir });
Attrs infoAttrs({
{"rev", input.getRev()->gitRev()},

View File

@ -166,4 +166,14 @@ void PosixSourceAccessor::assertNoSymlinks(CanonPath path)
}
}
ref<SourceAccessor> makeFSSourceAccessor()
{
static auto rootFS = make_ref<PosixSourceAccessor>();
return rootFS;
}
ref<SourceAccessor> makeFSSourceAccessor(std::filesystem::path root)
{
return make_ref<PosixSourceAccessor>(std::move(root));
}
}

View File

@ -194,4 +194,14 @@ ref<SourceAccessor> makeEmptySourceAccessor();
*/
MakeError(RestrictedPathError, Error);
/**
* Return an accessor for the root filesystem.
*/
ref<SourceAccessor> makeFSSourceAccessor();
/**
* Return an accessor for the filesystem rooted at `root`.
*/
ref<SourceAccessor> makeFSSourceAccessor(std::filesystem::path root);
}

View File

@ -2,6 +2,7 @@
#include <gtest/gtest.h>
#include "eval-settings.hh"
#include "memory-source-accessor.hh"
#include "tests/libexpr.hh"