Nix 2.36.0
Nix, the purely functional package manager; unstable internal interfaces
Loading...
Searching...
No Matches
fs-sink.hh
Go to the documentation of this file.
1#pragma once
3
5#include "nix/util/source-accessor.hh"
8
9namespace nix {
10
17{
18private:
19 void anchor() override;
20
21public:
28 bool skipContents = false;
29
30 virtual void isExecutable() = 0;
31
35 virtual void preallocateContents(uint64_t size) {};
36};
37
39{
40private:
41 /* VTable anchor to avoid weak linkage of the vtable - it breaks
42 dynamic_cast across shared libraries on Darwin. */
43 virtual void anchor();
44
45public:
46 virtual ~FileSystemObjectSink() = default;
47
48 virtual void createDirectory(const CanonPath & path) = 0;
49
50 using DirectoryCreatedCallback = fun<void(FileSystemObjectSink & dirSink, const CanonPath & dirRelPath)>;
51
61 virtual void createDirectory(const CanonPath & path, DirectoryCreatedCallback callback)
62 {
63 createDirectory(path);
64 callback(*this, path);
65 }
66
71 virtual void createRegularFile(const CanonPath & path, fun<void(CreateRegularFileSink &)>) = 0;
72
73 virtual void createSymlink(const CanonPath & path, const std::string & target) = 0;
74};
75
79void copyRecursive(
80 SourceAccessor & accessor, const CanonPath & sourcePath, FileSystemObjectSink & sink, const CanonPath & destPath);
81
86{
87private:
88 void anchor() override;
89
90public:
91 void createDirectory(const CanonPath & path) override {}
92
93 void createSymlink(const CanonPath & path, const std::string & target) override {}
94
95 void createRegularFile(const CanonPath & path, fun<void(CreateRegularFileSink &)>) override;
96};
97
99
103struct RestoreSink : FileSystemObjectSink
104{
105private:
106 void anchor() override;
107
108 RestoreSinkHooks * hooks = nullptr;
109
110public:
111 std::filesystem::path dstPath;
122 bool startFsync = false;
123
124 explicit RestoreSink(bool startFsync, RestoreSinkHooks * hooks = nullptr)
125 : hooks{hooks}
126 , startFsync{startFsync}
127 {
128 }
129
133 void createDirectory(const CanonPath & path) override;
134
135 void createDirectory(const CanonPath & path, DirectoryCreatedCallback callback) override;
136
137 void createRegularFile(const CanonPath & path, fun<void(CreateRegularFileSink &)>) override;
138
139 void createSymlink(const CanonPath & path, const std::string & target) override;
140};
141
151{
152 virtual void anchor();
153
154public:
155 virtual ~RestoreSinkHooks() = default;
156
167 virtual void directoryDone(Descriptor dirFd) = 0;
168
175 virtual void regularFileCreated(Descriptor fd, bool executable) = 0;
176
183 virtual void symlinkCreated(Descriptor parentFd, const OsFilename & name) = 0;
184};
185
191struct RegularFileSink : FileSystemObjectSink
192{
193private:
194 void anchor() override;
195
196public:
197 bool regular = true;
198 Sink & sink;
199
200 RegularFileSink(Sink & sink)
201 : sink(sink)
202 {
203 }
204
205 void createDirectory(const CanonPath & path) override
206 {
207 /* FIXME: Throw an error here. */
208 regular = false;
209 }
210
211 void createSymlink(const CanonPath & path, const std::string & target) override
212 {
213 /* FIXME: Throw an error here. */
214 regular = false;
215 }
216
217 void createRegularFile(const CanonPath & path, fun<void(CreateRegularFileSink &)>) override;
218};
219
220} // namespace nix
Definition file-descriptor.hh:265
Definition canon-path.hh:50
Definition os-filename.hh:22
Definition fs-sink.hh:151
virtual void regularFileCreated(Descriptor fd, bool executable)=0
virtual void directoryDone(Descriptor dirFd)=0
Called when the callback passed to nix::RestoreSink::createDirectory() returns.
virtual void symlinkCreated(Descriptor parentFd, const OsFilename &name)=0
Called after a symlink is created.
Definition fun.hh:19
int Descriptor
Definition file-descriptor.hh:36
Utilities for working with the file system and file paths.
Definition fs-sink.hh:17
virtual void preallocateContents(uint64_t size)
Definition fs-sink.hh:35
bool skipContents
Definition fs-sink.hh:28
Definition fs-sink.hh:39
virtual void createRegularFile(const CanonPath &path, fun< void(CreateRegularFileSink &)>)=0
virtual void createDirectory(const CanonPath &path, DirectoryCreatedCallback callback)
Definition fs-sink.hh:61
Definition fs-sink.hh:86
void createRegularFile(const CanonPath &path, fun< void(CreateRegularFileSink &)>) override
Definition fs-sink.cc:378
void createRegularFile(const CanonPath &path, fun< void(CreateRegularFileSink &)>) override
Definition fs-sink.cc:356
void createRegularFile(const CanonPath &path, fun< void(CreateRegularFileSink &)>) override
Definition fs-sink.cc:280
AutoCloseFD dirFd
Definition fs-sink.hh:121
void createDirectory(const CanonPath &path) override
Definition fs-sink.cc:200
Definition serialise.hh:18
Definition source-accessor.hh:50