21enum class SymlinkResolution {
37MakeError(SourceAccessorError,
Error);
38MakeError(FileNotFound, SourceAccessorError);
39MakeError(NotASymlink, SourceAccessorError);
40MakeError(NotADirectory, SourceAccessorError);
41MakeError(NotARegularFile, SourceAccessorError);
49struct SourceAccessor : std::enable_shared_from_this<SourceAccessor>
54 virtual void anchor() = 0;
58 std::string displayPrefix, displaySuffix;
62 virtual ~SourceAccessor() {}
97 virtual bool pathExists(
const CanonPath & path);
120 Type type = tUnknown;
140 bool isNotNARSerialisable();
141 std::string typeString();
146 virtual std::optional<Stat> maybeLstat(
const CanonPath & path) = 0;
148 typedef std::optional<Type> DirEntry;
150 typedef std::map<std::string, DirEntry> DirEntries;
168 std::function<
void(SourceAccessor & subdirAccessor,
const CanonPath & subdirRelPath)> callback)
170 callback(*
this, dirPath);
173 virtual std::string readLink(
const CanonPath & path) = 0;
178 hashPath(
const CanonPath & path,
PathFilter & filter = defaultPathFilter, HashAlgorithm ha = HashAlgorithm::SHA256);
192 return number == x.number;
195 auto operator<=>(
const SourceAccessor & x)
const
197 return number <=> x.number;
200 void setPathDisplay(std::string displayPrefix, std::string displaySuffix =
"");
210 virtual std::string
showPath(
const CanonPath & path);
219 CanonPath
resolveSymlinks(
const CanonPath & path, SymlinkResolution mode = SymlinkResolution::Full);
267ref<SourceAccessor> makeEmptySourceAccessor();
273MakeError(RestrictedPathError, Error);
275class SymlinkNotAllowed final :
public CloneableError<SymlinkNotAllowed, Error>
277 void anchor()
override;
284 std::variant<CanonPath, OsCanonPath>
path;
287 : CloneableError(
"relative path '%s' points to a symlink, which is not allowed",
path.rel())
292 template<
typename...
Args>
299 SymlinkNotAllowed(OsCanonPath
path)
300 : CloneableError(
"relative path %s points to a symlink, which is not allowed", PathFmt(
path.
path()))
305 template<
typename... Args>
306 SymlinkNotAllowed(OsCanonPath
path,
const std::string & fs, Args &&... args)
307 : CloneableError(fs, std::forward<Args>(args)...)
333 std::filesystem::path root,
bool trackLastModified =
false,
FinalSymlink finalSymlink = FinalSymlink::DontFollow);
Definition canon-path.hh:50
Definition source-accessor.hh:276
std::variant< CanonPath, OsCanonPath > path
Definition source-accessor.hh:284
FinalSymlink
Definition file-system.hh:193
fun< bool(const std::string &path)> PathFilter
Definition file-system.hh:494
Definition serialise.hh:18
Definition source-accessor.hh:119
std::optional< uint64_t > fileSize
Definition source-accessor.hh:127
bool isExecutable
Definition source-accessor.hh:132
std::optional< uint64_t > narOffset
Definition source-accessor.hh:138
Definition source-accessor.hh:50
virtual void invalidateCache()
Definition source-accessor.hh:261
virtual std::pair< CanonPath, std::optional< std::string > > getFingerprint(const CanonPath &path)
Definition source-accessor.hh:243
virtual std::optional< time_t > getLastModified()
Definition source-accessor.hh:252
virtual std::string showPath(const CanonPath &path)
Render a human-readable representation of the accessor + path beneath it.
Definition source-accessor.cc:95
virtual void readFile(const CanonPath &path, Sink &sink, fun< void(uint64_t)> sizeCallback=[](uint64_t size) {})=0
std::string readFile(const CanonPath &path)
Definition source-accessor.cc:62
virtual DirEntries readDirectory(const CanonPath &path)=0
std::optional< std::string > fingerprint
Definition source-accessor.hh:225
virtual void readDirectory(const CanonPath &dirPath, std::function< void(SourceAccessor &subdirAccessor, const CanonPath &subdirRelPath)> callback)
Definition source-accessor.hh:166
Type
Definition source-accessor.hh:99
@ tChar
Definition source-accessor.hh:111
virtual std::optional< std::filesystem::path > getPhysicalPath(const CanonPath &path)
Definition source-accessor.hh:185
CanonPath resolveSymlinks(const CanonPath &path, SymlinkResolution mode=SymlinkResolution::Full)
Definition source-accessor.cc:100