Nix 2.36.0
Nix, the purely functional package manager; unstable internal interfaces
Loading...
Searching...
No Matches
filtering-source-accessor.hh
1#pragma once
2
4
5#include <set>
6#include <unordered_set>
7
8#include <boost/unordered/concurrent_flat_map_fwd.hpp>
9
10namespace nix {
11
17typedef fun<RestrictedPathError(const CanonPath & path)> MakeNotAllowedError;
18
24struct FilteringSourceAccessor : SourceAccessor
25{
26private:
27 void anchor() override;
28
29public:
31 CanonPath prefix;
32 MakeNotAllowedError makeNotAllowedError;
33
34 FilteringSourceAccessor(const SourcePath & src, MakeNotAllowedError && makeNotAllowedError)
35 : next(src.accessor)
36 , prefix(src.path)
37 , makeNotAllowedError(std::move(makeNotAllowedError))
38 {
39 displayPrefix.clear();
40 }
41
42 std::optional<std::filesystem::path> getPhysicalPath(const CanonPath & path) override;
43
45
46 void readFile(const CanonPath & path, Sink & sink, fun<void(uint64_t)> sizeCallback) override;
47
48 bool pathExists(const CanonPath & path) override;
49
50 Stat lstat(const CanonPath & path) override;
51
52 std::optional<Stat> maybeLstat(const CanonPath & path) override;
53
54 DirEntries readDirectory(const CanonPath & path) override;
55
56 std::string readLink(const CanonPath & path) override;
57
58 std::string showPath(const CanonPath & path) override;
59
60 std::pair<CanonPath, std::optional<std::string>> getFingerprint(const CanonPath & path) override;
61
62 void invalidateCache() override
63 {
64 next->invalidateCache();
65 }
66
71 void checkAccess(const CanonPath & path);
72
76 virtual bool isAllowed(const CanonPath & path) = 0;
77};
78
83struct AllowListSourceAccessor : public FilteringSourceAccessor
84{
85private:
86 void anchor() override;
87
88public:
92 virtual void allowPrefix(CanonPath prefix) = 0;
93
94 static ref<AllowListSourceAccessor> create(
96 const std::set<CanonPath> & allowedPrefixes,
97 const std::unordered_set<CanonPath> & allowedPaths,
98 MakeNotAllowedError && makeNotAllowedError);
99
100 using FilteringSourceAccessor::FilteringSourceAccessor;
101};
102
106struct CachingFilteringSourceAccessor : FilteringSourceAccessor
107{
108private:
109 void anchor() override;
110
111public:
113
114 CachingFilteringSourceAccessor(const SourcePath & src, MakeNotAllowedError && makeNotAllowedError);
115
116 bool isAllowed(const CanonPath & path) override;
117
118 virtual bool isAllowedUncached(const CanonPath & path) = 0;
119};
120
121} // namespace nix
Definition canon-path.hh:50
Definition fun.hh:19
Definition ref.hh:58
SourcePath.
Definition filtering-source-accessor.hh:84
virtual void allowPrefix(CanonPath prefix)=0
bool isAllowed(const CanonPath &path) override
Definition filtering-source-accessor.cc:129
bool pathExists(const CanonPath &path) override
Check whether a file exists at path.
Definition filtering-source-accessor.cc:28
std::string showPath(const CanonPath &path) override
Render a human-readable representation of the accessor + path beneath it.
Definition filtering-source-accessor.cc:61
virtual bool isAllowed(const CanonPath &path)=0
std::optional< std::filesystem::path > getPhysicalPath(const CanonPath &path) override
Definition filtering-source-accessor.cc:16
void invalidateCache() override
Definition filtering-source-accessor.hh:62
DirEntries readDirectory(const CanonPath &path) override
Definition filtering-source-accessor.cc:44
std::pair< CanonPath, std::optional< std::string > > getFingerprint(const CanonPath &path) override
Definition filtering-source-accessor.cc:66
void readFile(const CanonPath &path, Sink &sink, fun< void(uint64_t)> sizeCallback) override
Definition filtering-source-accessor.cc:22
void checkAccess(const CanonPath &path)
Definition filtering-source-accessor.cc:73
Definition serialise.hh:18
Definition source-accessor.hh:119
std::string readFile(const CanonPath &path)
Definition source-accessor.cc:62
Definition source-path.hh:22