From 87b32bab05ff91981c8847d66cd5502feb44f3b5 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Sat, 28 Mar 2020 23:22:10 +0000 Subject: Use `enum struct` and drop prefixes This does a few enums; the rest will be gotten in subsequent commits. --- src/nix/add-to-store.cc | 2 +- src/nix/hash.cc | 42 ++++++++++++++++----------------- src/nix/installables.cc | 2 +- src/nix/main.cc | 2 +- src/nix/make-content-addressable.cc | 2 +- src/nix/path-info.cc | 2 +- src/nix/progress-bar.cc | 46 ++++++++++++++++++------------------- src/nix/repl.cc | 6 ++--- src/nix/sigs.cc | 2 +- src/nix/upgrade-nix.cc | 8 +++---- src/nix/verify.cc | 8 +++---- 11 files changed, 61 insertions(+), 61 deletions(-) (limited to 'src/nix') diff --git a/src/nix/add-to-store.cc b/src/nix/add-to-store.cc index 139db3657..ed35616e6 100644 --- a/src/nix/add-to-store.cc +++ b/src/nix/add-to-store.cc @@ -40,7 +40,7 @@ struct CmdAddToStore : MixDryRun, StoreCommand StringSink sink; dumpPath(path, sink); - auto narHash = hashString(htSHA256, *sink.s); + auto narHash = hashString(HashType::SHA256, *sink.s); ValidPathInfo info(store->makeFixedOutputPath(true, narHash, *namePart)); info.narHash = narHash; diff --git a/src/nix/hash.cc b/src/nix/hash.cc index 0cc523f50..deced3d11 100644 --- a/src/nix/hash.cc +++ b/src/nix/hash.cc @@ -11,18 +11,18 @@ struct CmdHash : Command { enum Mode { mFile, mPath }; Mode mode; - Base base = SRI; + Base base = Base::SRI; bool truncate = false; - HashType ht = htSHA256; + HashType ht = HashType::SHA256; std::vector paths; std::optional modulus; CmdHash(Mode mode) : mode(mode) { - mkFlag(0, "sri", "print hash in SRI format", &base, SRI); - mkFlag(0, "base64", "print hash in base-64", &base, Base64); - mkFlag(0, "base32", "print hash in base-32 (Nix-specific)", &base, Base32); - mkFlag(0, "base16", "print hash in base-16", &base, Base16); + mkFlag(0, "sri", "print hash in Base::SRI format", &base, Base::SRI); + mkFlag(0, "base64", "print hash in base-64", &base, Base::Base64); + mkFlag(0, "base32", "print hash in base-32 (Nix-specific)", &base, Base::Base32); + mkFlag(0, "base16", "print hash in base-16", &base, Base::Base16); mkFlag() .longName("type") .mkHashTypeFlag(&ht); @@ -61,7 +61,7 @@ struct CmdHash : Command 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); + h.to_string(base, base == Base::SRI); } } }; @@ -72,7 +72,7 @@ static RegisterCommand r2("hash-path", [](){ return make_ref(CmdHash::m struct CmdToBase : Command { Base base; - HashType ht = htUnknown; + HashType ht = HashType::Unknown; std::vector args; CmdToBase(Base base) : base(base) @@ -86,28 +86,28 @@ 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" : - "SRI"); + base == Base::Base16 ? "base-16" : + base == Base::Base32 ? "base-32" : + base == Base::Base64 ? "base-64" : + "Base::SRI"); } void run() override { for (auto s : args) - std::cout << fmt("%s\n", Hash(s, ht).to_string(base, base == SRI)); + std::cout << fmt("%s\n", Hash(s, ht).to_string(base, base == Base::SRI)); } }; -static RegisterCommand r3("to-base16", [](){ return make_ref(Base16); }); -static RegisterCommand r4("to-base32", [](){ return make_ref(Base32); }); -static RegisterCommand r5("to-base64", [](){ return make_ref(Base64); }); -static RegisterCommand r6("to-sri", [](){ return make_ref(SRI); }); +static RegisterCommand r3("to-base16", [](){ return make_ref(Base::Base16); }); +static RegisterCommand r4("to-base32", [](){ return make_ref(Base::Base32); }); +static RegisterCommand r5("to-base64", [](){ return make_ref(Base::Base64); }); +static RegisterCommand r6("to-sri", [](){ return make_ref(Base::SRI); }); /* Legacy nix-hash command. */ static int compatNixHash(int argc, char * * argv) { - HashType ht = htMD5; + HashType ht = HashType::MD5; bool flat = false; bool base32 = false; bool truncate = false; @@ -125,7 +125,7 @@ static int compatNixHash(int argc, char * * argv) else if (*arg == "--type") { string s = getArg(*arg, arg, end); ht = parseHashType(s); - if (ht == htUnknown) + if (ht == HashType::Unknown) throw UsageError(format("unknown hash type '%1%'") % s); } else if (*arg == "--to-base16") op = opTo16; @@ -140,14 +140,14 @@ static int compatNixHash(int argc, char * * argv) if (op == opHash) { CmdHash cmd(flat ? CmdHash::mFile : CmdHash::mPath); cmd.ht = ht; - cmd.base = base32 ? Base32 : Base16; + cmd.base = base32 ? Base::Base32 : Base::Base16; cmd.truncate = truncate; cmd.paths = ss; cmd.run(); } else { - CmdToBase cmd(op == opTo32 ? Base32 : Base16); + CmdToBase cmd(op == opTo32 ? Base::Base32 : Base::Base16); cmd.args = ss; cmd.ht = ht; cmd.run(); diff --git a/src/nix/installables.cc b/src/nix/installables.cc index 013218cd9..03d03e90a 100644 --- a/src/nix/installables.cc +++ b/src/nix/installables.cc @@ -272,7 +272,7 @@ Buildables build(ref store, RealiseMode mode, } if (mode == DryRun) - printMissing(store, pathsToBuild, lvlError); + printMissing(store, pathsToBuild, Verbosity::Error); else if (mode == Build) store->buildPaths(pathsToBuild); diff --git a/src/nix/main.cc b/src/nix/main.cc index 3b5f5516f..d0a43ab23 100644 --- a/src/nix/main.cc +++ b/src/nix/main.cc @@ -148,7 +148,7 @@ void mainWrapped(int argc, char * * argv) if (legacy) return legacy(argc, argv); } - verbosity = lvlWarn; + verbosity = Verbosity::Warn; settings.verboseBuild = false; NixArgs args; diff --git a/src/nix/make-content-addressable.cc b/src/nix/make-content-addressable.cc index f9c7fef3f..5c964ec27 100644 --- a/src/nix/make-content-addressable.cc +++ b/src/nix/make-content-addressable.cc @@ -69,7 +69,7 @@ struct CmdMakeContentAddressable : StorePathsCommand, MixJSON *sink.s = rewriteStrings(*sink.s, rewrites); - HashModuloSink hashModuloSink(htSHA256, oldHashPart); + HashModuloSink hashModuloSink(HashType::SHA256, oldHashPart); hashModuloSink((unsigned char *) sink.s->data(), sink.s->size()); auto narHash = hashModuloSink.finish().first; diff --git a/src/nix/path-info.cc b/src/nix/path-info.cc index 45ec297d2..a15912ccc 100644 --- a/src/nix/path-info.cc +++ b/src/nix/path-info.cc @@ -89,7 +89,7 @@ struct CmdPathInfo : StorePathsCommand, MixJSON store->pathInfoToJSON(jsonRoot, // FIXME: preserve order? storePathsToSet(storePaths), - true, showClosureSize, SRI, AllowInvalid); + true, showClosureSize, Base::SRI, AllowInvalid); } else { diff --git a/src/nix/progress-bar.cc b/src/nix/progress-bar.cc index 26631416c..d53e671ed 100644 --- a/src/nix/progress-bar.cc +++ b/src/nix/progress-bar.cc @@ -38,7 +38,7 @@ private: struct ActInfo { std::string s, lastLine, phase; - ActivityType type = actUnknown; + ActivityType type = ActivityType::Unknown; uint64_t done = 0; uint64_t expected = 0; uint64_t running = 0; @@ -152,7 +152,7 @@ public: state->its.emplace(act, i); state->activitiesByType[type].its.emplace(act, i); - if (type == actBuild) { + if (type == ActivityType::Build) { auto name = storePathToName(getS(fields, 0)); if (hasSuffix(name, ".drv")) name = name.substr(0, name.size() - 4); @@ -167,7 +167,7 @@ public: i->name = DrvName(name).name; } - if (type == actSubstitute) { + if (type == ActivityType::Substitute) { auto name = storePathToName(getS(fields, 0)); auto sub = getS(fields, 1); i->s = fmt( @@ -177,7 +177,7 @@ public: name, sub); } - if (type == actPostBuildHook) { + if (type == ActivityType::PostBuildHook) { auto name = storePathToName(getS(fields, 0)); if (hasSuffix(name, ".drv")) name = name.substr(0, name.size() - 4); @@ -185,14 +185,14 @@ public: i->name = DrvName(name).name; } - if (type == actQueryPathInfo) { + if (type == ActivityType::QueryPathInfo) { auto name = storePathToName(getS(fields, 0)); i->s = fmt("querying " ANSI_BOLD "%s" ANSI_NORMAL " on %s", name, getS(fields, 1)); } - if ((type == actDownload && hasAncestor(*state, actCopyPath, parent)) - || (type == actDownload && hasAncestor(*state, actQueryPathInfo, parent)) - || (type == actCopyPath && hasAncestor(*state, actSubstitute, parent))) + if ((type == ActivityType::Download && hasAncestor(*state, ActivityType::CopyPath, parent)) + || (type == ActivityType::Download && hasAncestor(*state, ActivityType::QueryPathInfo, parent)) + || (type == ActivityType::CopyPath && hasAncestor(*state, ActivityType::Substitute, parent))) i->visible = false; update(*state); @@ -237,13 +237,13 @@ public: { auto state(state_.lock()); - if (type == resFileLinked) { + if (type == ResultType::FileLinked) { state->filesLinked++; state->bytesLinked += getI(fields, 0); update(*state); } - else if (type == resBuildLogLine || type == resPostBuildLogLine) { + else if (type == ResultType::BuildLogLine || type == ResultType::PostBuildLogLine) { auto lastLine = trim(getS(fields, 0)); if (!lastLine.empty()) { auto i = state->its.find(act); @@ -251,10 +251,10 @@ public: ActInfo info = *i->second; if (printBuildLogs) { auto suffix = "> "; - if (type == resPostBuildLogLine) { + if (type == ResultType::PostBuildLogLine) { suffix = " (post)> "; } - log(*state, lvlInfo, ANSI_FAINT + info.name.value_or("unnamed") + suffix + ANSI_NORMAL + lastLine); + log(*state, Verbosity::Info, ANSI_FAINT + info.name.value_or("unnamed") + suffix + ANSI_NORMAL + lastLine); } else { state->activities.erase(i->second); info.lastLine = lastLine; @@ -265,24 +265,24 @@ public: } } - else if (type == resUntrustedPath) { + else if (type == ResultType::UntrustedPath) { state->untrustedPaths++; update(*state); } - else if (type == resCorruptedPath) { + else if (type == ResultType::CorruptedPath) { state->corruptedPaths++; update(*state); } - else if (type == resSetPhase) { + else if (type == ResultType::SetPhase) { auto i = state->its.find(act); assert(i != state->its.end()); i->second->phase = getS(fields, 0); update(*state); } - else if (type == resProgress) { + else if (type == ResultType::Progress) { auto i = state->its.find(act); assert(i != state->its.end()); ActInfo & actInfo = *i->second; @@ -293,7 +293,7 @@ public: update(*state); } - else if (type == resSetExpected) { + else if (type == ResultType::SetExpected) { auto i = state->its.find(act); assert(i != state->its.end()); ActInfo & actInfo = *i->second; @@ -405,10 +405,10 @@ public: res += s; }; - showActivity(actBuilds, "%s built"); + showActivity(ActivityType::Builds, "%s built"); - auto s1 = renderActivity(actCopyPaths, "%s copied"); - auto s2 = renderActivity(actCopyPath, "%s MiB", "%.1f", MiB); + auto s1 = renderActivity(ActivityType::CopyPaths, "%s copied"); + auto s2 = renderActivity(ActivityType::CopyPath, "%s MiB", "%.1f", MiB); if (!s1.empty() || !s2.empty()) { if (!res.empty()) res += ", "; @@ -416,10 +416,10 @@ public: if (!s2.empty()) { res += " ("; res += s2; res += ')'; } } - showActivity(actDownload, "%s MiB DL", "%.1f", MiB); + showActivity(ActivityType::Download, "%s MiB DL", "%.1f", MiB); { - auto s = renderActivity(actOptimiseStore, "%s paths optimised"); + auto s = renderActivity(ActivityType::OptimiseStore, "%s paths optimised"); if (s != "") { s += fmt(", %.1f MiB / %d inodes freed", state.bytesLinked / MiB, state.filesLinked); if (!res.empty()) res += ", "; @@ -428,7 +428,7 @@ public: } // FIXME: don't show "done" paths in green. - showActivity(actVerifyPaths, "%s paths verified"); + showActivity(ActivityType::VerifyPaths, "%s paths verified"); if (state.corruptedPaths) { if (!res.empty()) res += ", "; diff --git a/src/nix/repl.cc b/src/nix/repl.cc index 27727bd25..795aa6682 100644 --- a/src/nix/repl.cc +++ b/src/nix/repl.cc @@ -252,12 +252,12 @@ void NixRepl::mainLoop(const std::vector & files) // input without clearing the input so far. continue; } else { - printMsg(lvlError, format(error + "%1%%2%") % (settings.showTrace ? e.prefix() : "") % e.msg()); + printMsg(Verbosity::Error, format(error + "%1%%2%") % (settings.showTrace ? e.prefix() : "") % e.msg()); } } catch (Error & e) { - printMsg(lvlError, format(error + "%1%%2%") % (settings.showTrace ? e.prefix() : "") % e.msg()); + printMsg(Verbosity::Error, format(error + "%1%%2%") % (settings.showTrace ? e.prefix() : "") % e.msg()); } catch (Interrupted & e) { - printMsg(lvlError, format(error + "%1%%2%") % (settings.showTrace ? e.prefix() : "") % e.msg()); + printMsg(Verbosity::Error, format(error + "%1%%2%") % (settings.showTrace ? e.prefix() : "") % e.msg()); } // We handled the current input fully, so we should clear it diff --git a/src/nix/sigs.cc b/src/nix/sigs.cc index 5f07448e0..2c3d2a107 100644 --- a/src/nix/sigs.cc +++ b/src/nix/sigs.cc @@ -45,7 +45,7 @@ struct CmdCopySigs : StorePathsCommand //logger->setExpected(doneLabel, storePaths.size()); auto doPath = [&](const Path & storePathS) { - //Activity act(*logger, lvlInfo, format("getting signatures for '%s'") % storePath); + //Activity act(*logger, Verbosity::Info, format("getting signatures for '%s'") % storePath); checkInterrupt(); diff --git a/src/nix/upgrade-nix.cc b/src/nix/upgrade-nix.cc index c05c29517..26de92d32 100644 --- a/src/nix/upgrade-nix.cc +++ b/src/nix/upgrade-nix.cc @@ -69,12 +69,12 @@ struct CmdUpgradeNix : MixDryRun, StoreCommand } { - Activity act(*logger, lvlInfo, actUnknown, fmt("downloading '%s'...", store->printStorePath(storePath))); + Activity act(*logger, Verbosity::Info, ActivityType::Unknown, fmt("downloading '%s'...", store->printStorePath(storePath))); store->ensurePath(storePath); } { - Activity act(*logger, lvlInfo, actUnknown, fmt("verifying that '%s' works...", store->printStorePath(storePath))); + Activity act(*logger, Verbosity::Info, ActivityType::Unknown, fmt("verifying that '%s' works...", store->printStorePath(storePath))); auto program = store->printStorePath(storePath) + "/bin/nix-env"; auto s = runProgram(program, false, {"--version"}); if (s.find("Nix") == std::string::npos) @@ -84,7 +84,7 @@ struct CmdUpgradeNix : MixDryRun, StoreCommand stopProgressBar(); { - Activity act(*logger, lvlInfo, actUnknown, + Activity act(*logger, Verbosity::Info, ActivityType::Unknown, fmt("installing '%s' into profile '%s'...", store->printStorePath(storePath), profileDir)); runProgram(settings.nixBinDir + "/nix-env", false, {"--profile", profileDir, "-i", store->printStorePath(storePath), "--no-sandbox"}); @@ -135,7 +135,7 @@ struct CmdUpgradeNix : MixDryRun, StoreCommand /* Return the store path of the latest stable Nix. */ StorePath getLatestNix(ref store) { - Activity act(*logger, lvlInfo, actUnknown, "querying latest Nix version"); + Activity act(*logger, Verbosity::Info, ActivityType::Unknown, "querying latest Nix version"); // FIXME: use nixos.org? auto req = DownloadRequest(storePathsUrl); diff --git a/src/nix/verify.cc b/src/nix/verify.cc index 9b0658803..17d4410cf 100644 --- a/src/nix/verify.cc +++ b/src/nix/verify.cc @@ -57,7 +57,7 @@ struct CmdVerify : StorePathsCommand auto publicKeys = getDefaultPublicKeys(); - Activity act(*logger, actVerifyPaths); + Activity act(*logger, ActivityType::VerifyPaths); std::atomic done{0}; std::atomic untrusted{0}; @@ -75,7 +75,7 @@ struct CmdVerify : StorePathsCommand try { checkInterrupt(); - Activity act2(*logger, lvlInfo, actUnknown, fmt("checking '%s'", storePath)); + Activity act2(*logger, Verbosity::Info, ActivityType::Unknown, fmt("checking '%s'", storePath)); MaintainCount> mcActive(active); update(); @@ -96,7 +96,7 @@ struct CmdVerify : StorePathsCommand if (hash.first != info->narHash) { corrupted++; - act2.result(resCorruptedPath, store->printStorePath(info->path)); + act2.result(ResultType::CorruptedPath, store->printStorePath(info->path)); printError( "path '%s' was modified! expected hash '%s', got '%s'", store->printStorePath(info->path), info->narHash.to_string(), hash.first.to_string()); @@ -147,7 +147,7 @@ struct CmdVerify : StorePathsCommand if (!good) { untrusted++; - act2.result(resUntrustedPath, store->printStorePath(info->path)); + act2.result(ResultType::UntrustedPath, store->printStorePath(info->path)); printError("path '%s' is untrusted", store->printStorePath(info->path)); } -- cgit v1.2.3 From 450dcf2c1b60a36f5ffeab2411805287d122bcdd Mon Sep 17 00:00:00 2001 From: John Ericson Date: Tue, 2 Jun 2020 15:52:13 +0000 Subject: Remove `HashType::Unknown` Instead, `Hash` uses `std::optional`. In the future, we may also make `Hash` itself require a known hash type, encoraging people to use `std::optional` instead. --- src/nix/hash.cc | 4 +--- src/nix/verify.cc | 4 ++-- 2 files changed, 3 insertions(+), 5 deletions(-) (limited to 'src/nix') diff --git a/src/nix/hash.cc b/src/nix/hash.cc index 3362ffd0d..4980cd198 100644 --- a/src/nix/hash.cc +++ b/src/nix/hash.cc @@ -79,7 +79,7 @@ static RegisterCommand r2("hash-path", [](){ return make_ref(FileIngest struct CmdToBase : Command { Base base; - HashType ht = HashType::Unknown; + HashType ht; std::vector args; CmdToBase(Base base) : base(base) @@ -132,8 +132,6 @@ static int compatNixHash(int argc, char * * argv) else if (*arg == "--type") { string s = getArg(*arg, arg, end); ht = parseHashType(s); - if (ht == HashType::Unknown) - throw UsageError(format("unknown hash type '%1%'") % s); } else if (*arg == "--to-base16") op = opTo16; else if (*arg == "--to-base32") op = opTo32; diff --git a/src/nix/verify.cc b/src/nix/verify.cc index 0c3478ff5..fa05e7353 100644 --- a/src/nix/verify.cc +++ b/src/nix/verify.cc @@ -88,9 +88,9 @@ struct CmdVerify : StorePathsCommand std::unique_ptr hashSink; if (info->ca == "") - hashSink = std::make_unique(info->narHash.type); + hashSink = std::make_unique(*info->narHash.type); else - hashSink = std::make_unique(info->narHash.type, storePathToHash(store->printStorePath(info->path))); + hashSink = std::make_unique(*info->narHash.type, storePathToHash(store->printStorePath(info->path))); store->narFromPath(info->path, *hashSink); -- cgit v1.2.3 From c502119fd3b9673e966d5c34ec42cbe18baa17b9 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Tue, 2 Jun 2020 18:05:26 +0000 Subject: to-base supports parsing SRI hashes, so make type flag optional --- src/nix/hash.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nix') diff --git a/src/nix/hash.cc b/src/nix/hash.cc index 4980cd198..0e24bbaed 100644 --- a/src/nix/hash.cc +++ b/src/nix/hash.cc @@ -79,12 +79,12 @@ static RegisterCommand r2("hash-path", [](){ return make_ref(FileIngest struct CmdToBase : Command { Base base; - HashType ht; + std::optional ht; std::vector args; CmdToBase(Base base) : base(base) { - addFlag(Flag::mkHashTypeFlag("type", &ht)); + addFlag(Flag::mkHashTypeFlag("type", &*ht)); expectArgs("strings", &args); } -- cgit v1.2.3 From c664e68b87a3e9e41c4471276886da71793b2d85 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Tue, 2 Jun 2020 18:25:32 +0000 Subject: Fix to-base --type handler to correctly set std::optional flag Now that we have a separate flag function, also describe why it is optional. --- src/nix/hash.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nix') diff --git a/src/nix/hash.cc b/src/nix/hash.cc index 0e24bbaed..d1b5cca72 100644 --- a/src/nix/hash.cc +++ b/src/nix/hash.cc @@ -84,7 +84,7 @@ struct CmdToBase : Command CmdToBase(Base base) : base(base) { - addFlag(Flag::mkHashTypeFlag("type", &*ht)); + addFlag(Flag::mkHashTypeOptFlag("type", &ht)); expectArgs("strings", &args); } -- cgit v1.2.3 From 15abb2aa2ba7de06a86e05511f81633616e17d87 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Thu, 18 Jun 2020 22:09:22 +0000 Subject: Revert the `enum struct` change Not a regular git revert as there have been many merges and things. --- src/nix/add-to-store.cc | 2 +- src/nix/hash.cc | 38 ++++++++++++++++++------------------- src/nix/installables.cc | 2 +- src/nix/main.cc | 2 +- src/nix/make-content-addressable.cc | 2 +- src/nix/path-info.cc | 2 +- src/nix/repl.cc | 6 +++--- src/nix/sigs.cc | 2 +- src/nix/upgrade-nix.cc | 8 ++++---- src/nix/verify.cc | 13 +++++++------ 10 files changed, 39 insertions(+), 38 deletions(-) (limited to 'src/nix') diff --git a/src/nix/add-to-store.cc b/src/nix/add-to-store.cc index 3c0f7cdd6..f43f774c1 100644 --- a/src/nix/add-to-store.cc +++ b/src/nix/add-to-store.cc @@ -43,7 +43,7 @@ struct CmdAddToStore : MixDryRun, StoreCommand StringSink sink; dumpPath(path, sink); - auto narHash = hashString(HashType::SHA256, *sink.s); + auto narHash = hashString(htSHA256, *sink.s); ValidPathInfo info(store->makeFixedOutputPath(FileIngestionMethod::Recursive, narHash, *namePart)); info.narHash = narHash; diff --git a/src/nix/hash.cc b/src/nix/hash.cc index d1b5cca72..f435192fc 100644 --- a/src/nix/hash.cc +++ b/src/nix/hash.cc @@ -10,18 +10,18 @@ using namespace nix; struct CmdHash : Command { FileIngestionMethod mode; - Base base = Base::SRI; + Base base = SRI; bool truncate = false; - HashType ht = HashType::SHA256; + HashType ht = htSHA256; std::vector paths; std::optional modulus; CmdHash(FileIngestionMethod mode) : mode(mode) { - mkFlag(0, "sri", "print hash in Base::SRI format", &base, Base::SRI); - mkFlag(0, "base64", "print hash in base-64", &base, Base::Base64); - mkFlag(0, "base32", "print hash in base-32 (Nix-specific)", &base, Base::Base32); - mkFlag(0, "base16", "print hash in base-16", &base, Base::Base16); + mkFlag(0, "sri", "print hash in SRI format", &base, SRI); + mkFlag(0, "base64", "print hash in base-64", &base, Base64); + mkFlag(0, "base32", "print hash in base-32 (Nix-specific)", &base, Base32); + mkFlag(0, "base16", "print hash in base-16", &base, Base16); addFlag(Flag::mkHashTypeFlag("type", &ht)); #if 0 mkFlag() @@ -68,7 +68,7 @@ struct CmdHash : Command Hash h = hashSink->finish().first; if (truncate && h.hashSize > 20) h = compressHash(h, 20); - logger->stdout(h.to_string(base, base == Base::SRI)); + logger->stdout(h.to_string(base, base == SRI)); } } }; @@ -91,10 +91,10 @@ struct CmdToBase : Command std::string description() override { return fmt("convert a hash to %s representation", - base == Base::Base16 ? "base-16" : - base == Base::Base32 ? "base-32" : - base == Base::Base64 ? "base-64" : - "Base::SRI"); + base == Base16 ? "base-16" : + base == Base32 ? "base-32" : + base == Base64 ? "base-64" : + "SRI"); } Category category() override { return catUtility; } @@ -102,19 +102,19 @@ struct CmdToBase : Command void run() override { for (auto s : args) - logger->stdout(Hash(s, ht).to_string(base, base == Base::SRI)); + logger->stdout(Hash(s, ht).to_string(base, base == SRI)); } }; -static RegisterCommand r3("to-base16", [](){ return make_ref(Base::Base16); }); -static RegisterCommand r4("to-base32", [](){ return make_ref(Base::Base32); }); -static RegisterCommand r5("to-base64", [](){ return make_ref(Base::Base64); }); -static RegisterCommand r6("to-sri", [](){ return make_ref(Base::SRI); }); +static RegisterCommand r3("to-base16", [](){ return make_ref(Base16); }); +static RegisterCommand r4("to-base32", [](){ return make_ref(Base32); }); +static RegisterCommand r5("to-base64", [](){ return make_ref(Base64); }); +static RegisterCommand r6("to-sri", [](){ return make_ref(SRI); }); /* Legacy nix-hash command. */ static int compatNixHash(int argc, char * * argv) { - HashType ht = HashType::MD5; + HashType ht = htMD5; bool flat = false; bool base32 = false; bool truncate = false; @@ -145,14 +145,14 @@ static int compatNixHash(int argc, char * * argv) if (op == opHash) { CmdHash cmd(flat ? FileIngestionMethod::Flat : FileIngestionMethod::Recursive); cmd.ht = ht; - cmd.base = base32 ? Base::Base32 : Base::Base16; + cmd.base = base32 ? Base32 : Base16; cmd.truncate = truncate; cmd.paths = ss; cmd.run(); } else { - CmdToBase cmd(op == opTo32 ? Base::Base32 : Base::Base16); + CmdToBase cmd(op == opTo32 ? Base32 : Base16); cmd.args = ss; cmd.ht = ht; cmd.run(); diff --git a/src/nix/installables.cc b/src/nix/installables.cc index 687026ca7..708a0dc88 100644 --- a/src/nix/installables.cc +++ b/src/nix/installables.cc @@ -279,7 +279,7 @@ Buildables build(ref store, RealiseMode mode, } if (mode == DryRun) - printMissing(store, pathsToBuild, Verbosity::Error); + printMissing(store, pathsToBuild, lvlError); else if (mode == Build) store->buildPaths(pathsToBuild); diff --git a/src/nix/main.cc b/src/nix/main.cc index 2af28ed3e..203901168 100644 --- a/src/nix/main.cc +++ b/src/nix/main.cc @@ -163,7 +163,7 @@ void mainWrapped(int argc, char * * argv) if (legacy) return legacy(argc, argv); } - verbosity = Verbosity::Warn; + verbosity = lvlWarn; settings.verboseBuild = false; setLogFormat("bar"); diff --git a/src/nix/make-content-addressable.cc b/src/nix/make-content-addressable.cc index 8923ea05d..0ebb8f13b 100644 --- a/src/nix/make-content-addressable.cc +++ b/src/nix/make-content-addressable.cc @@ -72,7 +72,7 @@ struct CmdMakeContentAddressable : StorePathsCommand, MixJSON *sink.s = rewriteStrings(*sink.s, rewrites); - HashModuloSink hashModuloSink(HashType::SHA256, oldHashPart); + HashModuloSink hashModuloSink(htSHA256, oldHashPart); hashModuloSink((unsigned char *) sink.s->data(), sink.s->size()); auto narHash = hashModuloSink.finish().first; diff --git a/src/nix/path-info.cc b/src/nix/path-info.cc index d9b132581..fb7bacc4c 100644 --- a/src/nix/path-info.cc +++ b/src/nix/path-info.cc @@ -91,7 +91,7 @@ struct CmdPathInfo : StorePathsCommand, MixJSON store->pathInfoToJSON(jsonRoot, // FIXME: preserve order? StorePathSet(storePaths.begin(), storePaths.end()), - true, showClosureSize, Base::SRI, AllowInvalid); + true, showClosureSize, SRI, AllowInvalid); } else { diff --git a/src/nix/repl.cc b/src/nix/repl.cc index 2c3e52a16..617d49614 100644 --- a/src/nix/repl.cc +++ b/src/nix/repl.cc @@ -211,12 +211,12 @@ void NixRepl::mainLoop(const std::vector & files) // input without clearing the input so far. continue; } else { - printMsg(Verbosity::Error, error + "%1%%2%", (settings.showTrace ? e.prefix() : ""), e.msg()); + printMsg(lvlError, error + "%1%%2%", (settings.showTrace ? e.prefix() : ""), e.msg()); } } catch (Error & e) { - printMsg(Verbosity::Error, error + "%1%%2%", (settings.showTrace ? e.prefix() : ""), e.msg()); + printMsg(lvlError, error + "%1%%2%", (settings.showTrace ? e.prefix() : ""), e.msg()); } catch (Interrupted & e) { - printMsg(Verbosity::Error, error + "%1%%2%", (settings.showTrace ? e.prefix() : ""), e.msg()); + printMsg(lvlError, error + "%1%%2%", (settings.showTrace ? e.prefix() : ""), e.msg()); } // We handled the current input fully, so we should clear it diff --git a/src/nix/sigs.cc b/src/nix/sigs.cc index 311817d1f..6c9b9a792 100644 --- a/src/nix/sigs.cc +++ b/src/nix/sigs.cc @@ -47,7 +47,7 @@ struct CmdCopySigs : StorePathsCommand //logger->setExpected(doneLabel, storePaths.size()); auto doPath = [&](const Path & storePathS) { - //Activity act(*logger, Verbosity::Info, format("getting signatures for '%s'") % storePath); + //Activity act(*logger, lvlInfo, format("getting signatures for '%s'") % storePath); checkInterrupt(); diff --git a/src/nix/upgrade-nix.cc b/src/nix/upgrade-nix.cc index e3f37cb88..a880bdae0 100644 --- a/src/nix/upgrade-nix.cc +++ b/src/nix/upgrade-nix.cc @@ -76,12 +76,12 @@ struct CmdUpgradeNix : MixDryRun, StoreCommand } { - Activity act(*logger, Verbosity::Info, ActivityType::Unknown, fmt("downloading '%s'...", store->printStorePath(storePath))); + Activity act(*logger, lvlInfo, actUnknown, fmt("downloading '%s'...", store->printStorePath(storePath))); store->ensurePath(storePath); } { - Activity act(*logger, Verbosity::Info, ActivityType::Unknown, fmt("verifying that '%s' works...", store->printStorePath(storePath))); + Activity act(*logger, lvlInfo, actUnknown, fmt("verifying that '%s' works...", store->printStorePath(storePath))); auto program = store->printStorePath(storePath) + "/bin/nix-env"; auto s = runProgram(program, false, {"--version"}); if (s.find("Nix") == std::string::npos) @@ -91,7 +91,7 @@ struct CmdUpgradeNix : MixDryRun, StoreCommand stopProgressBar(); { - Activity act(*logger, Verbosity::Info, ActivityType::Unknown, + Activity act(*logger, lvlInfo, actUnknown, fmt("installing '%s' into profile '%s'...", store->printStorePath(storePath), profileDir)); runProgram(settings.nixBinDir + "/nix-env", false, {"--profile", profileDir, "-i", store->printStorePath(storePath), "--no-sandbox"}); @@ -142,7 +142,7 @@ struct CmdUpgradeNix : MixDryRun, StoreCommand /* Return the store path of the latest stable Nix. */ StorePath getLatestNix(ref store) { - Activity act(*logger, Verbosity::Info, ActivityType::Unknown, "querying latest Nix version"); + Activity act(*logger, lvlInfo, actUnknown, "querying latest Nix version"); // FIXME: use nixos.org? auto req = FileTransferRequest(storePathsUrl); diff --git a/src/nix/verify.cc b/src/nix/verify.cc index 5b9175744..d1aba08e3 100644 --- a/src/nix/verify.cc +++ b/src/nix/verify.cc @@ -59,7 +59,7 @@ struct CmdVerify : StorePathsCommand auto publicKeys = getDefaultPublicKeys(); - Activity act(*logger, ActivityType::VerifyPaths); + Activity act(*logger, actVerifyPaths); std::atomic done{0}; std::atomic untrusted{0}; @@ -77,7 +77,7 @@ struct CmdVerify : StorePathsCommand try { checkInterrupt(); - Activity act2(*logger, Verbosity::Info, ActivityType::Unknown, fmt("checking '%s'", storePath)); + Activity act2(*logger, lvlInfo, actUnknown, fmt("checking '%s'", storePath)); MaintainCount> mcActive(active); update(); @@ -98,14 +98,14 @@ struct CmdVerify : StorePathsCommand if (hash.first != info->narHash) { corrupted++; - act2.result(ResultType::CorruptedPath, store->printStorePath(info->path)); + act2.result(resCorruptedPath, store->printStorePath(info->path)); logError({ .name = "Hash error - path modified", .hint = hintfmt( "path '%s' was modified! expected hash '%s', got '%s'", store->printStorePath(info->path), - info->narHash.to_string(Base::Base32, true), - hash.first.to_string(Base::Base32, true)) + info->narHash.to_string(Base32, true), + hash.first.to_string(Base32, true)) }); } } @@ -153,12 +153,13 @@ struct CmdVerify : StorePathsCommand if (!good) { untrusted++; - act2.result(ResultType::UntrustedPath, store->printStorePath(info->path)); + act2.result(resUntrustedPath, store->printStorePath(info->path)); logError({ .name = "Untrusted path", .hint = hintfmt("path '%s' is untrusted", store->printStorePath(info->path)) }); + } } -- cgit v1.2.3