2020-06-02 00:32:27 +03:00
|
|
|
#include "file-hash.hh"
|
|
|
|
|
|
|
|
namespace nix {
|
|
|
|
|
|
|
|
std::string FileSystemHash::printMethodAlgo() const {
|
|
|
|
return makeFileIngestionPrefix(method) + printHashType(hash.type);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string makeFileIngestionPrefix(const FileIngestionMethod m) {
|
|
|
|
switch (m) {
|
|
|
|
case FileIngestionMethod::Flat:
|
|
|
|
return "";
|
|
|
|
case FileIngestionMethod::Recursive:
|
|
|
|
return "r:";
|
|
|
|
default:
|
|
|
|
throw Error("impossible, caught both cases");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string makeFixedOutputCA(FileIngestionMethod method, const Hash & hash)
|
|
|
|
{
|
|
|
|
return "fixed:"
|
|
|
|
+ makeFileIngestionPrefix(method)
|
|
|
|
+ hash.to_string();
|
|
|
|
}
|
|
|
|
|
2020-06-02 20:04:21 +03:00
|
|
|
// FIXME Put this somewhere?
|
2020-06-02 02:26:40 +03:00
|
|
|
template<class... Ts> struct overloaded : Ts... { using Ts::operator()...; };
|
|
|
|
template<class... Ts> overloaded(Ts...) -> overloaded<Ts...>;
|
|
|
|
|
|
|
|
std::string renderContentAddress(ContentAddress ca) {
|
|
|
|
return std::visit(overloaded {
|
|
|
|
[](TextHash th) {
|
|
|
|
return "text:" + th.hash.to_string();
|
|
|
|
},
|
|
|
|
[](FileSystemHash fsh) {
|
|
|
|
return makeFixedOutputCA(fsh.method, fsh.hash);
|
|
|
|
}
|
|
|
|
}, ca);
|
|
|
|
}
|
|
|
|
|
2020-06-02 18:00:10 +03:00
|
|
|
ContentAddress parseContentAddress(std::string_view rawCa) {
|
2020-06-02 03:37:43 +03:00
|
|
|
throw Error("TODO");
|
|
|
|
};
|
|
|
|
|
2020-06-02 18:00:10 +03:00
|
|
|
std::optional<ContentAddress> parseContentAddressOpt(std::string_view rawCaOpt) {
|
|
|
|
return rawCaOpt == "" ? std::optional<ContentAddress> {} : parseContentAddress(rawCaOpt);
|
2020-06-02 03:37:43 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
std::string renderContentAddress(std::optional<ContentAddress> ca) {
|
|
|
|
return ca ? renderContentAddress(*ca) : "";
|
2020-06-02 02:26:40 +03:00
|
|
|
}
|
|
|
|
|
2020-06-02 00:32:27 +03:00
|
|
|
}
|