Nix
2.36.0
Nix, the purely functional package manager; unstable internal interfaces
Toggle main menu visibility
Loading...
Searching...
No Matches
fs-sink.hh
Go to the documentation of this file.
1
#pragma once
3
4
#include "
nix/util/serialise.hh
"
5
#include "nix/util/source-accessor.hh"
6
#include "
nix/util/file-system.hh
"
7
#include "
nix/util/os-filename.hh
"
8
9
namespace
nix {
10
16
struct
CreateRegularFileSink
:
virtual
Sink
17
{
18
private
:
19
void
anchor()
override
;
20
21
public
:
28
bool
skipContents
=
false
;
29
30
virtual
void
isExecutable() = 0;
31
35
virtual
void
preallocateContents
(uint64_t size) {};
36
};
37
38
struct
FileSystemObjectSink
39
{
40
private
:
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
45
public
:
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
79
void
copyRecursive(
80
SourceAccessor
& accessor,
const
CanonPath
& sourcePath,
FileSystemObjectSink
& sink,
const
CanonPath
& destPath);
81
85
struct
NullFileSystemObjectSink
:
FileSystemObjectSink
86
{
87
private
:
88
void
anchor()
override
;
89
90
public
:
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
98
class
RestoreSinkHooks
;
99
103
struct
RestoreSink :
FileSystemObjectSink
104
{
105
private
:
106
void
anchor()
override
;
107
108
RestoreSinkHooks
* hooks =
nullptr
;
109
110
public
:
111
std::filesystem::path dstPath;
121
AutoCloseFD
dirFd
;
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
150
class
RestoreSinkHooks
151
{
152
virtual
void
anchor();
153
154
public
:
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
191
struct
RegularFileSink :
FileSystemObjectSink
192
{
193
private
:
194
void
anchor()
override
;
195
196
public
:
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
nix::AutoCloseFD
Definition
file-descriptor.hh:265
nix::CanonPath
Definition
canon-path.hh:50
nix::OsFilename
Definition
os-filename.hh:22
nix::RestoreSinkHooks
Definition
fs-sink.hh:151
nix::RestoreSinkHooks::regularFileCreated
virtual void regularFileCreated(Descriptor fd, bool executable)=0
nix::RestoreSinkHooks::directoryDone
virtual void directoryDone(Descriptor dirFd)=0
Called when the callback passed to nix::RestoreSink::createDirectory() returns.
nix::RestoreSinkHooks::symlinkCreated
virtual void symlinkCreated(Descriptor parentFd, const OsFilename &name)=0
Called after a symlink is created.
nix::fun
Definition
fun.hh:19
nix::Descriptor
int Descriptor
Definition
file-descriptor.hh:36
file-system.hh
Utilities for working with the file system and file paths.
os-filename.hh
serialise.hh
nix::CreateRegularFileSink
Definition
fs-sink.hh:17
nix::CreateRegularFileSink::preallocateContents
virtual void preallocateContents(uint64_t size)
Definition
fs-sink.hh:35
nix::CreateRegularFileSink::skipContents
bool skipContents
Definition
fs-sink.hh:28
nix::FileSystemObjectSink
Definition
fs-sink.hh:39
nix::FileSystemObjectSink::createRegularFile
virtual void createRegularFile(const CanonPath &path, fun< void(CreateRegularFileSink &)>)=0
nix::FileSystemObjectSink::createDirectory
virtual void createDirectory(const CanonPath &path, DirectoryCreatedCallback callback)
Definition
fs-sink.hh:61
nix::NullFileSystemObjectSink
Definition
fs-sink.hh:86
nix::NullFileSystemObjectSink::createRegularFile
void createRegularFile(const CanonPath &path, fun< void(CreateRegularFileSink &)>) override
Definition
fs-sink.cc:378
nix::RegularFileSink::createRegularFile
void createRegularFile(const CanonPath &path, fun< void(CreateRegularFileSink &)>) override
Definition
fs-sink.cc:356
nix::RestoreSink::createRegularFile
void createRegularFile(const CanonPath &path, fun< void(CreateRegularFileSink &)>) override
Definition
fs-sink.cc:280
nix::RestoreSink::dirFd
AutoCloseFD dirFd
Definition
fs-sink.hh:121
nix::RestoreSink::createDirectory
void createDirectory(const CanonPath &path) override
Definition
fs-sink.cc:200
nix::Sink
Definition
serialise.hh:18
nix::SourceAccessor
Definition
source-accessor.hh:50
libutil
include
nix
util
fs-sink.hh
Generated by
1.18.0