Nix 2.93.3
Lix: A modern, delicious implementation of the Nix package manager; unstable internal interfaces
Loading...
Searching...
No Matches
source-path.hh
Go to the documentation of this file.
1#pragma once
7
8#include "lix/libutil/ref.hh"
14
15namespace nix {
16
18
22struct SourcePath
23{
24protected:
25 CanonPath path;
26
27public:
28 SourcePath(CanonPath path)
29 : path(std::move(path))
30 { }
31
32 std::string_view baseName() const;
33
38 SourcePath parent() const;
39
40 const CanonPath & canonical() const { return path; }
41
42 std::string to_string() const
43 { return path.abs(); }
44
49
53 SourcePath operator + (const CanonPath & x) const
54 { return {path + x}; }
55
61 SourcePath operator + (std::string_view c) const
62 { return {path + c}; }
63
64 bool operator == (const SourcePath & x) const
65 {
66 return path == x.path;
67 }
68
69 bool operator != (const SourcePath & x) const
70 {
71 return path != x.path;
72 }
73
74 bool operator < (const SourcePath & x) const
75 {
76 return path < x.path;
77 }
78};
79
80std::ostream & operator << (std::ostream & str, const SourcePath & path);
81
88class CheckedSourcePath : public SourcePath
89{
90 friend struct SourcePath;
91
92 CheckedSourcePath(CanonPath path): SourcePath(std::move(path)) {}
93
94public:
99 std::string readFile() const
100 { return nix::readFile(path.abs()); }
101
106 bool pathExists() const
107 { return nix::pathExists(path.abs()); }
108
114
119 std::optional<InputAccessor::Stat> maybeLstat() const;
120
126
131 std::optional<InputAccessor::Stat> maybeStat() const;
132
137 InputAccessor::DirEntries readDirectory() const;
138
143 std::string readLink() const
144 { return nix::readLink(path.abs()); }
145
150 Sink & sink,
151 PathFilter & filter = defaultPathFilter) const
152 { sink << nix::dumpPath(path.abs(), filter); }
153};
154
156{
157 return CheckedSourcePath(std::move(path));
158}
159
160}
Definition canon-path.hh:28
Definition source-path.hh:89
std::optional< InputAccessor::Stat > maybeStat() const
Definition source-path.cc:56
void dumpPath(Sink &sink, PathFilter &filter=defaultPathFilter) const
Definition source-path.hh:149
bool pathExists() const
Definition source-path.hh:106
InputAccessor::Stat lstat() const
Definition source-path.cc:37
InputAccessor::Stat stat() const
Definition source-path.cc:51
std::string readLink() const
Definition source-path.hh:143
InputAccessor::DirEntries readDirectory() const
Definition source-path.cc:65
std::string readFile() const
Definition source-path.hh:99
std::optional< InputAccessor::Stat > maybeLstat() const
Definition source-path.cc:42
std::function< bool(const Path &path)> PathFilter
Definition file-system.hh:318
Definition input-accessor.hh:26
Definition serialise.hh:18
Definition source-path.hh:23
SourcePath operator+(const CanonPath &x) const
Definition source-path.hh:53
CheckedSourcePath unsafeIntoChecked()
Definition source-path.hh:155
SourcePath parent() const
Definition source-path.cc:18