aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/libstore/file-hash.cc18
-rw-r--r--src/libstore/file-hash.hh10
-rw-r--r--src/libstore/path.hh9
-rw-r--r--src/libstore/store-api.hh14
-rwxr-xr-xsrc/libutil/tests/libutil-testsbin14929616 -> 14929616 bytes
-rw-r--r--src/nix/path-info.cc2
6 files changed, 28 insertions, 25 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;
diff --git a/src/libutil/tests/libutil-tests b/src/libutil/tests/libutil-tests
index 919c401a1..a4f9bbbc1 100755
--- a/src/libutil/tests/libutil-tests
+++ b/src/libutil/tests/libutil-tests
Binary files differ
diff --git a/src/nix/path-info.cc b/src/nix/path-info.cc
index 91d62bcec..ffe07a3ee 100644
--- a/src/nix/path-info.cc
+++ b/src/nix/path-info.cc
@@ -115,7 +115,7 @@ struct CmdPathInfo : StorePathsCommand, MixJSON
std::cout << '\t';
Strings ss;
if (info->ultimate) ss.push_back("ultimate");
- if (info->ca != "") ss.push_back("ca:" + info->ca);
+ if (info->ca != "") ss.push_back("ca:" + renderContentAddress(*info->ca));
for (auto & sig : info->sigs) ss.push_back(sig);
std::cout << concatStringsSep(" ", ss);
}