mirror of
https://github.com/NixOS/nix.git
synced 2025-02-16 17:02:28 +00:00
ParseSink
-> FileSystemObjectSink
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
This commit is contained in:
parent
5f72a97092
commit
966d6fcd01
@ -441,7 +441,7 @@ static void performOp(TunnelLogger * logger, ref<Store> store,
|
|||||||
eagerly consume the entire stream it's given, past the
|
eagerly consume the entire stream it's given, past the
|
||||||
length of the Nar. */
|
length of the Nar. */
|
||||||
TeeSource savedNARSource(from, saved);
|
TeeSource savedNARSource(from, saved);
|
||||||
NullParseSink sink; /* just parse the NAR */
|
NullFileSystemObjectSink sink; /* just parse the NAR */
|
||||||
parseDump(sink, savedNARSource);
|
parseDump(sink, savedNARSource);
|
||||||
} else {
|
} else {
|
||||||
/* Incrementally parse the NAR file, stripping the
|
/* Incrementally parse the NAR file, stripping the
|
||||||
@ -913,7 +913,7 @@ static void performOp(TunnelLogger * logger, ref<Store> store,
|
|||||||
source = std::make_unique<TunnelSource>(from, to);
|
source = std::make_unique<TunnelSource>(from, to);
|
||||||
else {
|
else {
|
||||||
TeeSource tee { from, saved };
|
TeeSource tee { from, saved };
|
||||||
NullParseSink ether;
|
NullFileSystemObjectSink ether;
|
||||||
parseDump(ether, tee);
|
parseDump(ether, tee);
|
||||||
source = std::make_unique<StringSource>(saved.s);
|
source = std::make_unique<StringSource>(saved.s);
|
||||||
}
|
}
|
||||||
|
@ -65,7 +65,7 @@ StorePaths Store::importPaths(Source & source, CheckSigsFlag checkSigs)
|
|||||||
/* Extract the NAR from the source. */
|
/* Extract the NAR from the source. */
|
||||||
StringSink saved;
|
StringSink saved;
|
||||||
TeeSource tee { source, saved };
|
TeeSource tee { source, saved };
|
||||||
NullParseSink ether;
|
NullFileSystemObjectSink ether;
|
||||||
parseDump(ether, tee);
|
parseDump(ether, tee);
|
||||||
|
|
||||||
uint32_t magic = readInt(source);
|
uint32_t magic = readInt(source);
|
||||||
|
@ -1048,7 +1048,7 @@ void LocalStore::addToStore(const ValidPathInfo & info, Source & source,
|
|||||||
bool narRead = false;
|
bool narRead = false;
|
||||||
Finally cleanup = [&]() {
|
Finally cleanup = [&]() {
|
||||||
if (!narRead) {
|
if (!narRead) {
|
||||||
NullParseSink sink;
|
NullFileSystemObjectSink sink;
|
||||||
try {
|
try {
|
||||||
parseDump(sink, source);
|
parseDump(sink, source);
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
|
@ -27,7 +27,7 @@ struct NarAccessor : public SourceAccessor
|
|||||||
|
|
||||||
NarMember root;
|
NarMember root;
|
||||||
|
|
||||||
struct NarIndexer : ParseSink, Source
|
struct NarIndexer : FileSystemObjectSink, Source
|
||||||
{
|
{
|
||||||
NarAccessor & acc;
|
NarAccessor & acc;
|
||||||
Source & source;
|
Source & source;
|
||||||
|
@ -424,12 +424,12 @@ ValidPathInfo Store::addToStoreSlow(
|
|||||||
information to narSink. */
|
information to narSink. */
|
||||||
TeeSource tapped { *fileSource, narSink };
|
TeeSource tapped { *fileSource, narSink };
|
||||||
|
|
||||||
NullParseSink blank;
|
NullFileSystemObjectSink blank;
|
||||||
auto & parseSink = method.getFileIngestionMethod() == FileIngestionMethod::Flat
|
auto & parseSink = method.getFileIngestionMethod() == FileIngestionMethod::Flat
|
||||||
? (ParseSink &) fileSink
|
? (FileSystemObjectSink &) fileSink
|
||||||
: method.getFileIngestionMethod() == FileIngestionMethod::Recursive
|
: method.getFileIngestionMethod() == FileIngestionMethod::Recursive
|
||||||
? (ParseSink &) blank
|
? (FileSystemObjectSink &) blank
|
||||||
: (abort(), (ParseSink &)*(ParseSink *)nullptr); // handled both cases
|
: (abort(), (FileSystemObjectSink &)*(FileSystemObjectSink *)nullptr); // handled both cases
|
||||||
|
|
||||||
/* The information that flows from tapped (besides being replicated in
|
/* The information that flows from tapped (besides being replicated in
|
||||||
narSink), is now put in parseSink. */
|
narSink), is now put in parseSink. */
|
||||||
|
@ -133,7 +133,7 @@ static SerialisationError badArchive(const std::string & s)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void parseContents(ParseSink & sink, Source & source, const Path & path)
|
static void parseContents(FileSystemObjectSink & sink, Source & source, const Path & path)
|
||||||
{
|
{
|
||||||
uint64_t size = readLongLong(source);
|
uint64_t size = readLongLong(source);
|
||||||
|
|
||||||
@ -164,7 +164,7 @@ struct CaseInsensitiveCompare
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
static void parse(ParseSink & sink, Source & source, const Path & path)
|
static void parse(FileSystemObjectSink & sink, Source & source, const Path & path)
|
||||||
{
|
{
|
||||||
std::string s;
|
std::string s;
|
||||||
|
|
||||||
@ -266,7 +266,7 @@ static void parse(ParseSink & sink, Source & source, const Path & path)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void parseDump(ParseSink & sink, Source & source)
|
void parseDump(FileSystemObjectSink & sink, Source & source)
|
||||||
{
|
{
|
||||||
std::string version;
|
std::string version;
|
||||||
try {
|
try {
|
||||||
@ -294,7 +294,7 @@ void copyNAR(Source & source, Sink & sink)
|
|||||||
// FIXME: if 'source' is the output of dumpPath() followed by EOF,
|
// FIXME: if 'source' is the output of dumpPath() followed by EOF,
|
||||||
// we should just forward all data directly without parsing.
|
// we should just forward all data directly without parsing.
|
||||||
|
|
||||||
NullParseSink parseSink; /* just parse the NAR */
|
NullFileSystemObjectSink parseSink; /* just parse the NAR */
|
||||||
|
|
||||||
TeeSource wrapper { source, sink };
|
TeeSource wrapper { source, sink };
|
||||||
|
|
||||||
|
@ -73,7 +73,7 @@ time_t dumpPathAndGetMtime(const Path & path, Sink & sink,
|
|||||||
*/
|
*/
|
||||||
void dumpString(std::string_view s, Sink & sink);
|
void dumpString(std::string_view s, Sink & sink);
|
||||||
|
|
||||||
void parseDump(ParseSink & sink, Source & source);
|
void parseDump(FileSystemObjectSink & sink, Source & source);
|
||||||
|
|
||||||
void restorePath(const Path & path, Source & source);
|
void restorePath(const Path & path, Source & source);
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ void dumpPath(
|
|||||||
/**
|
/**
|
||||||
* Restore a serialization of the given file system object.
|
* Restore a serialization of the given file system object.
|
||||||
*
|
*
|
||||||
* @TODO use an arbitrary `ParseSink`.
|
* @TODO use an arbitrary `FileSystemObjectSink`.
|
||||||
*/
|
*/
|
||||||
void restorePath(
|
void restorePath(
|
||||||
const Path & path,
|
const Path & path,
|
||||||
|
@ -7,7 +7,7 @@ namespace nix {
|
|||||||
|
|
||||||
void copyRecursive(
|
void copyRecursive(
|
||||||
SourceAccessor & accessor, const CanonPath & from,
|
SourceAccessor & accessor, const CanonPath & from,
|
||||||
ParseSink & sink, const Path & to)
|
FileSystemObjectSink & sink, const Path & to)
|
||||||
{
|
{
|
||||||
auto stat = accessor.lstat(from);
|
auto stat = accessor.lstat(from);
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@ namespace nix {
|
|||||||
/**
|
/**
|
||||||
* \todo Fix this API, it sucks.
|
* \todo Fix this API, it sucks.
|
||||||
*/
|
*/
|
||||||
struct ParseSink
|
struct FileSystemObjectSink
|
||||||
{
|
{
|
||||||
virtual void createDirectory(const Path & path) = 0;
|
virtual void createDirectory(const Path & path) = 0;
|
||||||
|
|
||||||
@ -33,12 +33,12 @@ struct ParseSink
|
|||||||
*/
|
*/
|
||||||
void copyRecursive(
|
void copyRecursive(
|
||||||
SourceAccessor & accessor, const CanonPath & sourcePath,
|
SourceAccessor & accessor, const CanonPath & sourcePath,
|
||||||
ParseSink & sink, const Path & destPath);
|
FileSystemObjectSink & sink, const Path & destPath);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ignore everything and do nothing
|
* Ignore everything and do nothing
|
||||||
*/
|
*/
|
||||||
struct NullParseSink : ParseSink
|
struct NullFileSystemObjectSink : FileSystemObjectSink
|
||||||
{
|
{
|
||||||
void createDirectory(const Path & path) override { }
|
void createDirectory(const Path & path) override { }
|
||||||
void receiveContents(std::string_view data) override { }
|
void receiveContents(std::string_view data) override { }
|
||||||
@ -51,7 +51,7 @@ struct NullParseSink : ParseSink
|
|||||||
/**
|
/**
|
||||||
* Write files at the given path
|
* Write files at the given path
|
||||||
*/
|
*/
|
||||||
struct RestoreSink : ParseSink
|
struct RestoreSink : FileSystemObjectSink
|
||||||
{
|
{
|
||||||
Path dstPath;
|
Path dstPath;
|
||||||
|
|
||||||
@ -75,7 +75,7 @@ private:
|
|||||||
* `receiveContents` to the underlying `Sink`. For anything but a single
|
* `receiveContents` to the underlying `Sink`. For anything but a single
|
||||||
* file, set `regular = true` so the caller can fail accordingly.
|
* file, set `regular = true` so the caller can fail accordingly.
|
||||||
*/
|
*/
|
||||||
struct RegularFileSink : ParseSink
|
struct RegularFileSink : FileSystemObjectSink
|
||||||
{
|
{
|
||||||
bool regular = true;
|
bool regular = true;
|
||||||
Sink & sink;
|
Sink & sink;
|
||||||
|
@ -54,7 +54,7 @@ static std::string getString(Source & source, int n)
|
|||||||
|
|
||||||
|
|
||||||
void parse(
|
void parse(
|
||||||
ParseSink & sink,
|
FileSystemObjectSink & sink,
|
||||||
const Path & sinkPath,
|
const Path & sinkPath,
|
||||||
Source & source,
|
Source & source,
|
||||||
std::function<SinkHook> hook,
|
std::function<SinkHook> hook,
|
||||||
@ -133,7 +133,7 @@ std::optional<Mode> convertMode(SourceAccessor::Type type)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void restore(ParseSink & sink, Source & source, std::function<RestoreHook> hook)
|
void restore(FileSystemObjectSink & sink, Source & source, std::function<RestoreHook> hook)
|
||||||
{
|
{
|
||||||
parse(sink, "", source, [&](Path name, TreeEntry entry) {
|
parse(sink, "", source, [&](Path name, TreeEntry entry) {
|
||||||
auto [accessor, from] = hook(entry.hash);
|
auto [accessor, from] = hook(entry.hash);
|
||||||
|
@ -60,7 +60,7 @@ using Tree = std::map<std::string, TreeEntry>;
|
|||||||
using SinkHook = void(const Path & name, TreeEntry entry);
|
using SinkHook = void(const Path & name, TreeEntry entry);
|
||||||
|
|
||||||
void parse(
|
void parse(
|
||||||
ParseSink & sink, const Path & sinkPath,
|
FileSystemObjectSink & sink, const Path & sinkPath,
|
||||||
Source & source,
|
Source & source,
|
||||||
std::function<SinkHook> hook,
|
std::function<SinkHook> hook,
|
||||||
const ExperimentalFeatureSettings & xpSettings = experimentalFeatureSettings);
|
const ExperimentalFeatureSettings & xpSettings = experimentalFeatureSettings);
|
||||||
@ -81,7 +81,7 @@ using RestoreHook = std::pair<SourceAccessor *, CanonPath>(Hash);
|
|||||||
/**
|
/**
|
||||||
* Wrapper around `parse` and `RestoreSink`
|
* Wrapper around `parse` and `RestoreSink`
|
||||||
*/
|
*/
|
||||||
void restore(ParseSink & sink, Source & source, std::function<RestoreHook> hook);
|
void restore(FileSystemObjectSink & sink, Source & source, std::function<RestoreHook> hook);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Dumps a single file to a sink
|
* Dumps a single file to a sink
|
||||||
|
@ -75,7 +75,7 @@ struct MemorySourceAccessor : virtual SourceAccessor
|
|||||||
/**
|
/**
|
||||||
* Write to a `MemorySourceAccessor` at the given path
|
* Write to a `MemorySourceAccessor` at the given path
|
||||||
*/
|
*/
|
||||||
struct MemorySink : ParseSink
|
struct MemorySink : FileSystemObjectSink
|
||||||
{
|
{
|
||||||
MemorySourceAccessor & dst;
|
MemorySourceAccessor & dst;
|
||||||
|
|
||||||
|
@ -119,7 +119,7 @@ const static Tree tree = {
|
|||||||
TEST_F(GitTest, tree_read) {
|
TEST_F(GitTest, tree_read) {
|
||||||
readTest("tree.bin", [&](const auto & encoded) {
|
readTest("tree.bin", [&](const auto & encoded) {
|
||||||
StringSource in { encoded };
|
StringSource in { encoded };
|
||||||
NullParseSink out;
|
NullFileSystemObjectSink out;
|
||||||
Tree got;
|
Tree got;
|
||||||
parse(out, "", in, [&](auto & name, auto entry) {
|
parse(out, "", in, [&](auto & name, auto entry) {
|
||||||
auto name2 = name;
|
auto name2 = name;
|
||||||
|
Loading…
Reference in New Issue
Block a user