diff options
Diffstat (limited to 'src/nix')
-rw-r--r-- | src/nix/add-to-store.cc | 4 | ||||
-rw-r--r-- | src/nix/daemon.cc | 2 | ||||
-rw-r--r-- | src/nix/flake.cc | 8 | ||||
-rw-r--r-- | src/nix/hash.cc | 50 | ||||
-rw-r--r-- | src/nix/main.cc | 8 | ||||
-rw-r--r-- | src/nix/path-info.cc | 2 | ||||
-rw-r--r-- | src/nix/prefetch.cc | 8 | ||||
-rw-r--r-- | src/nix/verify.cc | 4 | ||||
-rw-r--r-- | src/nix/why-depends.cc | 2 |
9 files changed, 43 insertions, 45 deletions
diff --git a/src/nix/add-to-store.cc b/src/nix/add-to-store.cc index 7e16e12c3..b9f7ece89 100644 --- a/src/nix/add-to-store.cc +++ b/src/nix/add-to-store.cc @@ -32,11 +32,11 @@ struct CmdAddToStore : MixDryRun, StoreCommand StringSink sink; sink << dumpPath(path); - auto narHash = hashString(htSHA256, sink.s); + auto narHash = hashString(HashType::SHA256, sink.s); Hash hash = narHash; if (ingestionMethod == FileIngestionMethod::Flat) { - HashSink hsink(htSHA256); + HashSink hsink(HashType::SHA256); hsink << readFileSource(path); hash = hsink.finish().first; } diff --git a/src/nix/daemon.cc b/src/nix/daemon.cc index a9211d64a..ca65c38e6 100644 --- a/src/nix/daemon.cc +++ b/src/nix/daemon.cc @@ -316,7 +316,7 @@ static void daemonLoop(std::optional<TrustedFlag> forceTrustClientOpt) socklen_t remoteAddrLen = sizeof(remoteAddr); AutoCloseFD remote{accept(fdSocket.get(), - (struct sockaddr *) &remoteAddr, &remoteAddrLen)}; + reinterpret_cast<struct sockaddr *>(&remoteAddr), &remoteAddrLen)}; checkInterrupt(); if (!remote) { if (errno == EINTR) continue; diff --git a/src/nix/flake.cc b/src/nix/flake.cc index 672930342..5ea9e077b 100644 --- a/src/nix/flake.cc +++ b/src/nix/flake.cc @@ -226,7 +226,7 @@ struct CmdFlakeMetadata : FlakeCommand, MixJSON j["url"] = flake.lockedRef.to_string(); // FIXME: rename to lockedUrl j["locked"] = fetchers::attrsToJSON(flake.lockedRef.toAttrs()); if (auto rev = flake.lockedRef.input.getRev()) - j["revision"] = rev->to_string(Base16, false); + j["revision"] = rev->to_string(Base::Base16, false); if (auto dirtyRev = fetchers::maybeGetStrAttr(flake.lockedRef.toAttrs(), "dirtyRev")) j["dirtyRevision"] = *dirtyRev; if (auto revCount = flake.lockedRef.input.getRevCount()) @@ -253,7 +253,7 @@ struct CmdFlakeMetadata : FlakeCommand, MixJSON if (auto rev = flake.lockedRef.input.getRev()) logger->cout( ANSI_BOLD "Revision:" ANSI_NORMAL " %s", - rev->to_string(Base16, false)); + rev->to_string(Base::Base16, false)); if (auto dirtyRev = fetchers::maybeGetStrAttr(flake.lockedRef.toAttrs(), "dirtyRev")) logger->cout( ANSI_BOLD "Revision:" ANSI_NORMAL " %s", @@ -1434,13 +1434,13 @@ struct CmdFlakePrefetch : FlakeCommand, MixJSON if (json) { auto res = nlohmann::json::object(); res["storePath"] = store->printStorePath(tree.storePath); - res["hash"] = hash.to_string(SRI, true); + res["hash"] = hash.to_string(Base::SRI, true); logger->cout(res.dump()); } else { notice("Downloaded '%s' to '%s' (hash '%s').", lockedRef.to_string(), store->printStorePath(tree.storePath), - hash.to_string(SRI, true)); + hash.to_string(Base::SRI, true)); } } }; diff --git a/src/nix/hash.cc b/src/nix/hash.cc index 12b66a83c..f6add527a 100644 --- a/src/nix/hash.cc +++ b/src/nix/hash.cc @@ -11,9 +11,9 @@ using namespace nix; struct CmdHashBase : Command { FileIngestionMethod mode; - Base base = SRI; + Base base = Base::SRI; bool truncate = false; - HashType ht = htSHA256; + HashType ht = HashType::SHA256; std::vector<std::string> paths; std::optional<std::string> modulus; @@ -22,25 +22,25 @@ struct CmdHashBase : Command addFlag({ .longName = "sri", .description = "Print the hash in SRI format.", - .handler = {&base, SRI}, + .handler = {&base, Base::SRI}, }); addFlag({ .longName = "base64", .description = "Print the hash in base-64 format.", - .handler = {&base, Base64}, + .handler = {&base, Base::Base64}, }); addFlag({ .longName = "base32", .description = "Print the hash in base-32 (Nix-specific) format.", - .handler = {&base, Base32}, + .handler = {&base, Base::Base32}, }); addFlag({ .longName = "base16", .description = "Print the hash in base-16 format.", - .handler = {&base, Base16}, + .handler = {&base, Base::Base16}, }); addFlag(Flag::mkHashTypeFlag("type", &ht)); @@ -90,7 +90,7 @@ struct CmdHashBase : Command ? computeHashModulo(ht, *modulus, source).first : hashSource(ht, source).first; if (truncate && h.hashSize > 20) h = compressHash(h, 20); - logger->cout(h.to_string(base, base == SRI)); + logger->cout(h.to_string(base, base == Base::SRI)); } } }; @@ -110,16 +110,16 @@ struct CmdToBase : Command std::string description() override { return fmt("convert a hash to %s representation", - base == Base16 ? "base-16" : - base == Base32 ? "base-32" : - base == Base64 ? "base-64" : + base == Base::Base16 ? "base-16" : + base == Base::Base32 ? "base-32" : + base == Base::Base64 ? "base-64" : "SRI"); } void run() override { for (auto s : args) - logger->cout(Hash::parseAny(s, ht).to_string(base, base == SRI)); + logger->cout(Hash::parseAny(s, ht).to_string(base, base == Base::SRI)); } }; @@ -129,10 +129,10 @@ struct CmdHash : NixMultiCommand : MultiCommand({ {"file", []() { return make_ref<CmdHashBase>(FileIngestionMethod::Flat);; }}, {"path", []() { return make_ref<CmdHashBase>(FileIngestionMethod::Recursive); }}, - {"to-base16", []() { return make_ref<CmdToBase>(Base16); }}, - {"to-base32", []() { return make_ref<CmdToBase>(Base32); }}, - {"to-base64", []() { return make_ref<CmdToBase>(Base64); }}, - {"to-sri", []() { return make_ref<CmdToBase>(SRI); }}, + {"to-base16", []() { return make_ref<CmdToBase>(Base::Base16); }}, + {"to-base32", []() { return make_ref<CmdToBase>(Base::Base32); }}, + {"to-base64", []() { return make_ref<CmdToBase>(Base::Base64); }}, + {"to-sri", []() { return make_ref<CmdToBase>(Base::SRI); }}, }) { } @@ -158,7 +158,7 @@ static int compatNixHash(int argc, char * * argv) { std::optional<HashType> ht; bool flat = false; - Base base = Base16; + Base base = Base::Base16; bool truncate = false; enum { opHash, opTo } op = opHash; std::vector<std::string> ss; @@ -169,10 +169,10 @@ static int compatNixHash(int argc, char * * argv) else if (*arg == "--version") printVersion("nix-hash"); else if (*arg == "--flat") flat = true; - else if (*arg == "--base16") base = Base16; - else if (*arg == "--base32") base = Base32; - else if (*arg == "--base64") base = Base64; - else if (*arg == "--sri") base = SRI; + else if (*arg == "--base16") base = Base::Base16; + else if (*arg == "--base32") base = Base::Base32; + else if (*arg == "--base64") base = Base::Base64; + else if (*arg == "--sri") base = Base::SRI; else if (*arg == "--truncate") truncate = true; else if (*arg == "--type") { std::string s = getArg(*arg, arg, end); @@ -180,19 +180,19 @@ static int compatNixHash(int argc, char * * argv) } else if (*arg == "--to-base16") { op = opTo; - base = Base16; + base = Base::Base16; } else if (*arg == "--to-base32") { op = opTo; - base = Base32; + base = Base::Base32; } else if (*arg == "--to-base64") { op = opTo; - base = Base64; + base = Base::Base64; } else if (*arg == "--to-sri") { op = opTo; - base = SRI; + base = Base::SRI; } else if (*arg != "" && arg->at(0) == '-') return false; @@ -203,7 +203,7 @@ static int compatNixHash(int argc, char * * argv) if (op == opHash) { CmdHashBase cmd(flat ? FileIngestionMethod::Flat : FileIngestionMethod::Recursive); - if (!ht.has_value()) ht = htMD5; + if (!ht.has_value()) ht = HashType::MD5; cmd.ht = ht.value(); cmd.base = base; cmd.truncate = truncate; diff --git a/src/nix/main.cc b/src/nix/main.cc index 2f52a352f..981aa2fc5 100644 --- a/src/nix/main.cc +++ b/src/nix/main.cc @@ -1,5 +1,3 @@ -#include <algorithm> - #include "args/root.hh" #include "command.hh" #include "common-args.hh" @@ -62,12 +60,12 @@ static bool haveInternet() for (auto i = addrs; i; i = i->ifa_next) { if (!i->ifa_addr) continue; if (i->ifa_addr->sa_family == AF_INET) { - if (ntohl(((sockaddr_in *) i->ifa_addr)->sin_addr.s_addr) != INADDR_LOOPBACK) { + if (ntohl(reinterpret_cast<sockaddr_in *>(i->ifa_addr)->sin_addr.s_addr) != INADDR_LOOPBACK) { return true; } } else if (i->ifa_addr->sa_family == AF_INET6) { - if (!IN6_IS_ADDR_LOOPBACK(&((sockaddr_in6 *) i->ifa_addr)->sin6_addr) && - !IN6_IS_ADDR_LINKLOCAL(&((sockaddr_in6 *) i->ifa_addr)->sin6_addr)) + if (!IN6_IS_ADDR_LOOPBACK(&reinterpret_cast<sockaddr_in6 *>(i->ifa_addr)->sin6_addr) && + !IN6_IS_ADDR_LINKLOCAL(&reinterpret_cast<sockaddr_in6 *>(i->ifa_addr)->sin6_addr)) return true; } } diff --git a/src/nix/path-info.cc b/src/nix/path-info.cc index 613c5b191..b14eef467 100644 --- a/src/nix/path-info.cc +++ b/src/nix/path-info.cc @@ -90,7 +90,7 @@ struct CmdPathInfo : StorePathsCommand, MixJSON std::cout << store->pathInfoToJSON( // FIXME: preserve order? StorePathSet(storePaths.begin(), storePaths.end()), - true, showClosureSize, SRI, AllowInvalid).dump(); + true, showClosureSize, Base::SRI, AllowInvalid).dump(); } else { diff --git a/src/nix/prefetch.cc b/src/nix/prefetch.cc index 13d94d645..0b04a04e6 100644 --- a/src/nix/prefetch.cc +++ b/src/nix/prefetch.cc @@ -133,7 +133,7 @@ std::tuple<StorePath, Hash> prefetchFile( static int main_nix_prefetch_url(int argc, char * * argv) { { - HashType ht = htSHA256; + HashType ht = HashType::SHA256; std::vector<std::string> args; bool printPath = getEnv("PRINT_PATH") == "1"; bool fromExpr = false; @@ -256,7 +256,7 @@ struct CmdStorePrefetchFile : StoreCommand, MixJSON bool executable = false; bool unpack = false; std::optional<std::string> name; - HashType hashType = htSHA256; + HashType hashType = HashType::SHA256; std::optional<Hash> expectedHash; CmdStorePrefetchFile() @@ -316,13 +316,13 @@ struct CmdStorePrefetchFile : StoreCommand, MixJSON if (json) { auto res = nlohmann::json::object(); res["storePath"] = store->printStorePath(storePath); - res["hash"] = hash.to_string(SRI, true); + res["hash"] = hash.to_string(Base::SRI, true); logger->cout(res.dump()); } else { notice("Downloaded '%s' to '%s' (hash '%s').", url, store->printStorePath(storePath), - hash.to_string(SRI, true)); + hash.to_string(Base::SRI, true)); } } }; diff --git a/src/nix/verify.cc b/src/nix/verify.cc index eb68e67bc..8783d4e04 100644 --- a/src/nix/verify.cc +++ b/src/nix/verify.cc @@ -109,8 +109,8 @@ struct CmdVerify : StorePathsCommand act2.result(resCorruptedPath, store->printStorePath(info->path)); printError("path '%s' was modified! expected hash '%s', got '%s'", store->printStorePath(info->path), - info->narHash.to_string(Base32, true), - hash.first.to_string(Base32, true)); + info->narHash.to_string(Base::Base32, true), + hash.first.to_string(Base::Base32, true)); } } diff --git a/src/nix/why-depends.cc b/src/nix/why-depends.cc index 5bef11c4d..6df84e9e4 100644 --- a/src/nix/why-depends.cc +++ b/src/nix/why-depends.cc @@ -171,7 +171,7 @@ struct CmdWhyDepends : SourceExprCommand, MixOperateOnOptions and `dependency`. */ std::function<void(Node &, const std::string &, const std::string &)> printNode; - struct BailOut { }; + struct BailOut : std::exception { }; printNode = [&](Node & node, const std::string & firstPad, const std::string & tailPad) { auto pathS = store->printStorePath(node.path); |