diff options
Diffstat (limited to 'src/libstore')
-rw-r--r-- | src/libstore/file-hash.cc | 18 | ||||
-rw-r--r-- | src/libstore/file-hash.hh | 10 | ||||
-rw-r--r-- | src/libstore/path.hh | 9 | ||||
-rw-r--r-- | src/libstore/store-api.hh | 14 |
4 files changed, 27 insertions, 24 deletions
diff --git a/src/libstore/file-hash.cc b/src/libstore/file-hash.cc index 549540db2..ebd732759 100644 --- a/src/libstore/file-hash.cc +++ b/src/libstore/file-hash.cc @@ -24,4 +24,22 @@ std::string makeFixedOutputCA(FileIngestionMethod method, const Hash & hash) + hash.to_string(); } +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); +} + +std::string renderContentAddress(std::optionalContent<Address> ca) { + return ca ? renderContentAddress(*ca) else ""; +} + } diff --git a/src/libstore/file-hash.hh b/src/libstore/file-hash.hh index 9d2b78688..e33878bf9 100644 --- a/src/libstore/file-hash.hh +++ b/src/libstore/file-hash.hh @@ -10,6 +10,10 @@ enum struct FileIngestionMethod : uint8_t { Recursive = true }; +struct TextHash { + Hash hash; +}; + /// Pair of a hash, and how the file system was ingested struct FileSystemHash { FileIngestionMethod method; @@ -36,7 +40,7 @@ struct FileSystemHash { makeFixedOutputPath() / addToStore(). */ typedef std::variant< - Hash, // for paths computed by makeTextPath() / addTextToStore + TextHash, // for paths computed by makeTextPath() / addTextToStore FileSystemHash // for path computed by makeFixedOutputPath > ContentAddress; @@ -48,4 +52,8 @@ std::string makeFileIngestionPrefix(const FileIngestionMethod m); for paths created by makeFixedOutputPath() / addToStore(). */ std::string makeFixedOutputCA(FileIngestionMethod method, const Hash & hash); +std::string renderContentAddress(ContentAddress ca); + +std::string renderContentAddress(std::optional<ContentAddress> ca); + } diff --git a/src/libstore/path.hh b/src/libstore/path.hh index 5268b3bbf..dfc0a9531 100644 --- a/src/libstore/path.hh +++ b/src/libstore/path.hh @@ -88,15 +88,6 @@ const size_t storePathHashLen = 32; // i.e. 160 bits /* Extension of derivations in the Nix store. */ const std::string drvExtension = ".drv"; -std::string to_string(FileIngestionMethod m) { - switch(m) { - case FileIngestionMethod::Flat: - return "false"; - case FileIngestionMethod::Recursive: - return "true"; - } -} - struct StorePathWithOutputs { StorePath path; diff --git a/src/libstore/store-api.hh b/src/libstore/store-api.hh index 1f1c1e0eb..faf549fe1 100644 --- a/src/libstore/store-api.hh +++ b/src/libstore/store-api.hh @@ -111,20 +111,6 @@ struct SubstitutablePathInfo typedef std::map<StorePath, SubstitutablePathInfo> SubstitutablePathInfos; -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 { - [](Hash hash) { - return "text:" + hash.to_string(); - }, - [](FileSystemHash fsh) { - return makeFixedOutputCA(fsh.method, fsh.hash); - } - }, ca); -} - struct ValidPathInfo { StorePath path; |