Skip to content

Commit

Permalink
Remove FSInputAccessor
Browse files Browse the repository at this point in the history
  • Loading branch information
edolstra committed May 3, 2024
1 parent ba5929c commit 20558e0
Show file tree
Hide file tree
Showing 15 changed files with 48 additions and 58 deletions.
3 changes: 1 addition & 2 deletions src/libcmd/installables.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#include "url.hh"
#include "registry.hh"
#include "build-result.hh"
#include "fs-input-accessor.hh"

#include <regex>
#include <queue>
Expand Down Expand Up @@ -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
});
Expand Down
5 changes: 2 additions & 3 deletions src/libexpr/eval.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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(
Expand Down
1 change: 0 additions & 1 deletion src/libexpr/primops.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
2 changes: 1 addition & 1 deletion src/libfetchers/fetch-to-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
34 changes: 0 additions & 34 deletions src/libfetchers/fs-input-accessor.cc

This file was deleted.

3 changes: 1 addition & 2 deletions src/libfetchers/git-utils.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "git-utils.hh"
#include "fs-input-accessor.hh"
#include "cache.hh"
#include "finally.hh"
#include "processes.hh"
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions src/libfetchers/path.cc
Original file line number Diff line number Diff line change
@@ -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 {

Expand Down
17 changes: 17 additions & 0 deletions src/libfetchers/store-path-accessor.cc
Original file line number Diff line number Diff line change
@@ -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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 1 addition & 2 deletions src/libfetchers/tarball.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
1 change: 0 additions & 1 deletion src/libfetchers/unix/git.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
9 changes: 3 additions & 6 deletions src/libfetchers/unix/mercurial.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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()},
Expand Down
10 changes: 10 additions & 0 deletions src/libutil/posix-source-accessor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
10 changes: 10 additions & 0 deletions src/libutil/source-accessor.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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);

}
1 change: 1 addition & 0 deletions tests/unit/libexpr/primops.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <gtest/gtest.h>

#include "eval-settings.hh"
#include "memory-source-accessor.hh"

#include "tests/libexpr.hh"

Expand Down

0 comments on commit 20558e0

Please sign in to comment.