2023-11-04 22:25:41 +02:00
|
|
|
#include "file-content-address.hh"
|
|
|
|
#include "archive.hh"
|
|
|
|
|
|
|
|
namespace nix {
|
|
|
|
|
2024-02-13 16:54:07 +02:00
|
|
|
FileIngestionMethod parseFileIngestionMethod(std::string_view input)
|
|
|
|
{
|
|
|
|
if (input == "flat") {
|
|
|
|
return FileIngestionMethod::Flat;
|
|
|
|
} else if (input == "nar") {
|
|
|
|
return FileIngestionMethod::Recursive;
|
|
|
|
} else {
|
|
|
|
throw UsageError("Unknown file ingestion method '%s', expect `flat` or `nar`");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::string_view renderFileIngestionMethod(FileIngestionMethod method)
|
|
|
|
{
|
|
|
|
switch (method) {
|
|
|
|
case FileIngestionMethod::Flat:
|
|
|
|
return "flat";
|
|
|
|
case FileIngestionMethod::Recursive:
|
|
|
|
return "nar";
|
|
|
|
default:
|
2024-02-13 19:50:10 +02:00
|
|
|
abort();
|
2024-02-13 16:54:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-11-04 22:25:41 +02:00
|
|
|
void dumpPath(
|
|
|
|
SourceAccessor & accessor, const CanonPath & path,
|
|
|
|
Sink & sink,
|
|
|
|
FileIngestionMethod method,
|
|
|
|
PathFilter & filter)
|
|
|
|
{
|
|
|
|
switch (method) {
|
|
|
|
case FileIngestionMethod::Flat:
|
|
|
|
accessor.readFile(path, sink);
|
|
|
|
break;
|
|
|
|
case FileIngestionMethod::Recursive:
|
|
|
|
accessor.dumpPath(path, sink, filter);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void restorePath(
|
|
|
|
const Path & path,
|
|
|
|
Source & source,
|
|
|
|
FileIngestionMethod method)
|
|
|
|
{
|
|
|
|
switch (method) {
|
|
|
|
case FileIngestionMethod::Flat:
|
|
|
|
writeFile(path, source);
|
|
|
|
break;
|
|
|
|
case FileIngestionMethod::Recursive:
|
|
|
|
restorePath(path, source);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
HashResult hashPath(
|
|
|
|
SourceAccessor & accessor, const CanonPath & path,
|
|
|
|
FileIngestionMethod method, HashAlgorithm ht,
|
|
|
|
PathFilter & filter)
|
|
|
|
{
|
|
|
|
HashSink sink { ht };
|
|
|
|
dumpPath(accessor, path, sink, method, filter);
|
|
|
|
return sink.finish();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|