2023-10-18 15:32:31 +02:00
|
|
|
#include "fs-input-accessor.hh"
|
2023-10-23 11:05:50 +02:00
|
|
|
#include "posix-source-accessor.hh"
|
2023-10-18 15:32:31 +02:00
|
|
|
#include "store-api.hh"
|
|
|
|
|
|
|
|
namespace nix {
|
|
|
|
|
2023-11-30 21:54:53 +01:00
|
|
|
struct FSInputAccessor : InputAccessor, PosixSourceAccessor
|
2023-10-18 15:32:31 +02:00
|
|
|
{
|
|
|
|
CanonPath root;
|
|
|
|
|
2023-11-30 21:54:53 +01:00
|
|
|
FSInputAccessor(const CanonPath & root)
|
2023-10-18 15:32:31 +02:00
|
|
|
: root(root)
|
|
|
|
{
|
2023-11-20 18:54:36 +01:00
|
|
|
displayPrefix = root.isRoot() ? "" : root.abs();
|
2023-10-18 15:32:31 +02:00
|
|
|
}
|
|
|
|
|
2023-10-20 16:36:41 +02:00
|
|
|
void readFile(
|
|
|
|
const CanonPath & path,
|
|
|
|
Sink & sink,
|
|
|
|
std::function<void(uint64_t)> sizeCallback) override
|
2023-10-18 15:32:31 +02:00
|
|
|
{
|
|
|
|
auto absPath = makeAbsPath(path);
|
2023-10-20 16:36:41 +02:00
|
|
|
PosixSourceAccessor::readFile(absPath, sink, sizeCallback);
|
2023-10-18 15:32:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool pathExists(const CanonPath & path) override
|
|
|
|
{
|
2023-11-30 21:54:53 +01:00
|
|
|
return PosixSourceAccessor::pathExists(makeAbsPath(path));
|
2023-10-18 15:32:31 +02:00
|
|
|
}
|
|
|
|
|
2023-11-01 15:26:07 +01:00
|
|
|
std::optional<Stat> maybeLstat(const CanonPath & path) override
|
2023-10-18 15:32:31 +02:00
|
|
|
{
|
2023-11-30 21:54:53 +01:00
|
|
|
return PosixSourceAccessor::maybeLstat(makeAbsPath(path));
|
2023-10-18 15:32:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
DirEntries readDirectory(const CanonPath & path) override
|
|
|
|
{
|
|
|
|
DirEntries res;
|
2023-11-30 21:54:53 +01:00
|
|
|
for (auto & entry : PosixSourceAccessor::readDirectory(makeAbsPath(path)))
|
|
|
|
res.emplace(entry);
|
2023-10-18 15:32:31 +02:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string readLink(const CanonPath & path) override
|
|
|
|
{
|
2023-11-30 21:54:53 +01:00
|
|
|
return PosixSourceAccessor::readLink(makeAbsPath(path));
|
2023-10-18 15:32:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CanonPath makeAbsPath(const CanonPath & path)
|
|
|
|
{
|
|
|
|
return root + path;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::optional<CanonPath> getPhysicalPath(const CanonPath & path) override
|
|
|
|
{
|
|
|
|
return makeAbsPath(path);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-11-30 21:54:53 +01:00
|
|
|
ref<InputAccessor> makeFSInputAccessor(const CanonPath & root)
|
2023-10-18 15:32:31 +02:00
|
|
|
{
|
2023-11-30 21:54:53 +01:00
|
|
|
return make_ref<FSInputAccessor>(root);
|
2023-10-18 15:32:31 +02:00
|
|
|
}
|
|
|
|
|
2023-11-30 21:54:53 +01:00
|
|
|
ref<InputAccessor> makeStorePathAccessor(
|
2023-10-18 15:32:31 +02:00
|
|
|
ref<Store> store,
|
2023-11-30 21:54:53 +01:00
|
|
|
const StorePath & storePath)
|
2023-10-18 15:32:31 +02:00
|
|
|
{
|
2023-11-30 21:54:53 +01:00
|
|
|
return makeFSInputAccessor(CanonPath(store->toRealPath(storePath)));
|
2023-10-18 15:32:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
SourcePath getUnfilteredRootPath(CanonPath path)
|
|
|
|
{
|
|
|
|
static auto rootFS = makeFSInputAccessor(CanonPath::root);
|
|
|
|
return {rootFS, path};
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|