diff options
author | Eelco Dolstra <edolstra@gmail.com> | 2019-10-21 18:48:21 +0200 |
---|---|---|
committer | Eelco Dolstra <edolstra@gmail.com> | 2019-10-21 18:48:21 +0200 |
commit | 9a18f544ac09c3a40e9a87c166edd878a1368c6f (patch) | |
tree | 9a2dcd0d4545f46c2c3e3930239f9a503903db19 /src/nix/hash.cc | |
parent | b82f75464d1e5ae9a00d8004e5dd7b1ca05059e4 (diff) | |
parent | 629b9b0049363e091b76b7f60a8357d9f94733cc (diff) |
Merge remote-tracking branch 'origin/master' into flakes
Diffstat (limited to 'src/nix/hash.cc')
-rw-r--r-- | src/nix/hash.cc | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/src/nix/hash.cc b/src/nix/hash.cc index 1b3ba729e..0cc523f50 100644 --- a/src/nix/hash.cc +++ b/src/nix/hash.cc @@ -2,6 +2,8 @@ #include "hash.hh" #include "legacy.hh" #include "shared.hh" +#include "references.hh" +#include "archive.hh" using namespace nix; @@ -13,6 +15,7 @@ struct CmdHash : Command bool truncate = false; HashType ht = htSHA256; std::vector<std::string> paths; + std::optional<std::string> modulus; CmdHash(Mode mode) : mode(mode) { @@ -23,6 +26,13 @@ struct CmdHash : Command mkFlag() .longName("type") .mkHashTypeFlag(&ht); + #if 0 + mkFlag() + .longName("modulo") + .description("compute hash modulo specified string") + .labels({"modulus"}) + .dest(&modulus); + #endif expectArgs("paths", &paths); } @@ -36,7 +46,19 @@ struct CmdHash : Command void run() override { for (auto path : paths) { - Hash h = mode == mFile ? hashFile(ht, path) : hashPath(ht, path).first; + + std::unique_ptr<AbstractHashSink> hashSink; + if (modulus) + hashSink = std::make_unique<HashModuloSink>(ht, *modulus); + else + hashSink = std::make_unique<HashSink>(ht); + + if (mode == mFile) + readFile(path, *hashSink); + else + dumpPath(path, *hashSink); + + Hash h = hashSink->finish().first; if (truncate && h.hashSize > 20) h = compressHash(h, 20); std::cout << format("%1%\n") % h.to_string(base, base == SRI); |