#include "nix/util/source-accessor.hh" namespace nix { struct SubdirSourceAccessor : SourceAccessor { ref parent; CanonPath subdirectory; SubdirSourceAccessor(ref && parent, CanonPath && subdirectory) : parent(std::move(parent)) , subdirectory(std::move(subdirectory)) { displayPrefix.clear(); } std::string readFile(const CanonPath & path) override { return parent->readFile(subdirectory / path); } void readFile(const CanonPath & path, Sink & sink, std::function sizeCallback) override { return parent->readFile(subdirectory / path, sink, sizeCallback); } bool pathExists(const CanonPath & path) override { return parent->pathExists(subdirectory / path); } std::optional maybeLstat(const CanonPath & path) override { return parent->maybeLstat(subdirectory / path); } DirEntries readDirectory(const CanonPath & path) override { return parent->readDirectory(subdirectory / path); } std::string readLink(const CanonPath & path) override { return parent->readLink(subdirectory / path); } std::string showPath(const CanonPath & path) override { return displayPrefix + parent->showPath(subdirectory / path) + displaySuffix; } }; ref projectSubdirSourceAccessor(ref parent, CanonPath subdirectory) { return make_ref(std::move(parent), std::move(subdirectory)); } } // namespace nix