From bcde5456cc3295061a0726881c3e441444dd6680 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Sat, 21 Mar 2020 11:07:16 -0400 Subject: Flip dependency so store-api.hh includes derivations.hh I think it makes more sense to define the data model (derivations), before the operations (store api). --- src/libexpr/get-drvs.cc | 2 +- src/libexpr/primops/context.cc | 2 +- src/libstore/derivations.hh | 3 ++- src/libstore/parsed-derivations.hh | 2 +- src/libstore/store-api.hh | 4 +--- 5 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/libexpr/get-drvs.cc b/src/libexpr/get-drvs.cc index ca9c547fa..16f7b5637 100644 --- a/src/libexpr/get-drvs.cc +++ b/src/libexpr/get-drvs.cc @@ -1,7 +1,7 @@ #include "get-drvs.hh" #include "util.hh" #include "eval-inline.hh" -#include "derivations.hh" +#include "store-api.hh" #include #include diff --git a/src/libexpr/primops/context.cc b/src/libexpr/primops/context.cc index 94fa0158c..66d8bab1f 100644 --- a/src/libexpr/primops/context.cc +++ b/src/libexpr/primops/context.cc @@ -1,6 +1,6 @@ #include "primops.hh" #include "eval-inline.hh" -#include "derivations.hh" +#include "store-api.hh" namespace nix { diff --git a/src/libstore/derivations.hh b/src/libstore/derivations.hh index 7222d25e5..a3651de23 100644 --- a/src/libstore/derivations.hh +++ b/src/libstore/derivations.hh @@ -1,8 +1,8 @@ #pragma once +#include "path.hh" #include "types.hh" #include "hash.hh" -#include "store-api.hh" #include @@ -76,6 +76,7 @@ struct Derivation : BasicDerivation class Store; +enum RepairFlag : bool { NoRepair = false, Repair = true }; /* Write a derivation to the Nix store, and return its path. */ StorePath writeDerivation(ref store, diff --git a/src/libstore/parsed-derivations.hh b/src/libstore/parsed-derivations.hh index f4df5dd54..d0cc70f9c 100644 --- a/src/libstore/parsed-derivations.hh +++ b/src/libstore/parsed-derivations.hh @@ -1,4 +1,4 @@ -#include "derivations.hh" +#include "store-api.hh" #include diff --git a/src/libstore/store-api.hh b/src/libstore/store-api.hh index 0fa59be6a..396709633 100644 --- a/src/libstore/store-api.hh +++ b/src/libstore/store-api.hh @@ -8,6 +8,7 @@ #include "sync.hh" #include "globals.hh" #include "config.hh" +#include "derivations.hh" #include #include @@ -30,15 +31,12 @@ MakeError(SubstituteGone, Error); MakeError(SubstituterDisabled, Error); -struct BasicDerivation; -struct Derivation; class FSAccessor; class NarInfoDiskCache; class Store; class JSONPlaceholder; -enum RepairFlag : bool { NoRepair = false, Repair = true }; enum CheckSigsFlag : bool { NoCheckSigs = false, CheckSigs = true }; enum SubstituteFlag : bool { NoSubstitute = false, Substitute = true }; enum AllowInvalidFlag : bool { DisallowInvalid = false, AllowInvalid = true }; -- cgit v1.2.3 From e433d4af4cf78c88dc0cb3e8139e835470b72fd3 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Sun, 22 Mar 2020 23:43:07 -0400 Subject: Extend Rust FFI Do idiomatic C++ copy and move constructors for a few things, so wrapping structs' defaults can work. --- nix-rust/src/c.rs | 7 +++++++ src/libstore/derivations.hh | 3 +++ src/libstore/nar-info.cc | 2 +- src/libstore/path.hh | 14 ++++++++++++++ src/libstore/store-api.cc | 15 --------------- src/libstore/store-api.hh | 5 +++-- src/libutil/hash.hh | 6 ++++++ src/libutil/rust-ffi.hh | 32 +++++++++++++++++++++++++++++--- 8 files changed, 63 insertions(+), 21 deletions(-) diff --git a/nix-rust/src/c.rs b/nix-rust/src/c.rs index c1358545f..dc2f8ddf5 100644 --- a/nix-rust/src/c.rs +++ b/nix-rust/src/c.rs @@ -64,6 +64,13 @@ pub extern "C" fn ffi_StorePath_clone(self_: &StorePath) -> StorePath { self_.clone() } +#[no_mangle] +pub extern "C" fn ffi_StorePath_clone_to(self_: &StorePath, other: *mut StorePath) { + unsafe { + core::ptr::write(other, self_.clone()); + } +} + #[no_mangle] pub extern "C" fn ffi_StorePath_name(self_: &StorePath) -> &str { self_.name.name() diff --git a/src/libstore/derivations.hh b/src/libstore/derivations.hh index 7222d25e5..f010318ce 100644 --- a/src/libstore/derivations.hh +++ b/src/libstore/derivations.hh @@ -22,6 +22,9 @@ struct DerivationOutput , hashAlgo(std::move(hashAlgo)) , hash(std::move(hash)) { } + DerivationOutput(const DerivationOutput &) = default; + DerivationOutput(DerivationOutput &&) = default; + DerivationOutput & operator = (const DerivationOutput &) = default; void parseHashInfo(bool & recursive, Hash & hash) const; }; diff --git a/src/libstore/nar-info.cc b/src/libstore/nar-info.cc index 1375094b5..87b1b656b 100644 --- a/src/libstore/nar-info.cc +++ b/src/libstore/nar-info.cc @@ -4,7 +4,7 @@ namespace nix { NarInfo::NarInfo(const Store & store, const std::string & s, const std::string & whence) - : ValidPathInfo(StorePath::dummy.clone()) // FIXME: hack + : ValidPathInfo(StorePath::dummy) // FIXME: hack { auto corrupt = [&]() { throw Error(format("NAR info file '%1%' is corrupt") % whence); diff --git a/src/libstore/path.hh b/src/libstore/path.hh index c90bb1fff..186976855 100644 --- a/src/libstore/path.hh +++ b/src/libstore/path.hh @@ -13,6 +13,7 @@ extern "C" { void ffi_StorePath_drop(void *); bool ffi_StorePath_less_than(const StorePath & a, const StorePath & b); bool ffi_StorePath_eq(const StorePath & a, const StorePath & b); + void ffi_StorePath_clone_to(const StorePath & _other, StorePath & _this); unsigned char * ffi_StorePath_hash_data(const StorePath & p); } @@ -43,6 +44,19 @@ struct StorePath : rust::Value<3 * sizeof(void *) + 24, ffi_StorePath_drop> return !(*this == other); } + StorePath(StorePath && that) = default; + + StorePath(const StorePath & that) + { + ffi_StorePath_clone_to(that, *this); + } + + void operator = (const StorePath & that) + { + (rust::Value<3 * sizeof(void *) + 24, ffi_StorePath_drop>::operator = (that)); + ffi_StorePath_clone_to(that, *this); + } + StorePath clone() const; /* Check whether a file name ends with the extension for diff --git a/src/libstore/store-api.cc b/src/libstore/store-api.cc index b9e894a9a..261afed49 100644 --- a/src/libstore/store-api.cc +++ b/src/libstore/store-api.cc @@ -687,21 +687,6 @@ void copyClosure(ref srcStore, ref dstStore, } -ValidPathInfo::ValidPathInfo(const ValidPathInfo & other) - : path(other.path.clone()) - , deriver(other.deriver ? other.deriver->clone(): std::optional{}) - , narHash(other.narHash) - , references(cloneStorePathSet(other.references)) - , registrationTime(other.registrationTime) - , narSize(other.narSize) - , id(other.id) - , ultimate(other.ultimate) - , sigs(other.sigs) - , ca(other.ca) -{ -} - - std::optional decodeValidPathInfo(const Store & store, std::istream & str, bool hashGiven) { std::string path; diff --git a/src/libstore/store-api.hh b/src/libstore/store-api.hh index 0fa59be6a..0237d0b04 100644 --- a/src/libstore/store-api.hh +++ b/src/libstore/store-api.hh @@ -189,8 +189,9 @@ struct ValidPathInfo Strings shortRefs() const; - ValidPathInfo(StorePath && path) : path(std::move(path)) { } - explicit ValidPathInfo(const ValidPathInfo & other); + ValidPathInfo(StorePath && path) : path(std::move(path)) { }; + ValidPathInfo(const StorePath & path) : path(path) { }; + ValidPathInfo(const ValidPathInfo & other) = default; virtual ~ValidPathInfo() { } }; diff --git a/src/libutil/hash.hh b/src/libutil/hash.hh index ea9fca3e7..294555a09 100644 --- a/src/libutil/hash.hh +++ b/src/libutil/hash.hh @@ -44,6 +44,12 @@ struct Hash string. */ Hash(const std::string & s, HashType type = htUnknown); + Hash(const Hash &) = default; + + Hash(Hash &&) = default; + + Hash & operator = (const Hash &) = default; + void init(); /* Check whether a hash is set. */ diff --git a/src/libutil/rust-ffi.hh b/src/libutil/rust-ffi.hh index 228e2eead..584dcf110 100644 --- a/src/libutil/rust-ffi.hh +++ b/src/libutil/rust-ffi.hh @@ -30,7 +30,10 @@ protected: // Must not be called directly. Value() - { } + { + // Precaution, in case this is used improperly + evacuate(); + } Value(Value && other) : raw(other.raw) @@ -38,6 +41,19 @@ protected: other.evacuate(); } + // Not all Rust types are Clone / Copy, but our base Value class needs to + // have a copy constructor so that ones which do implement Copy/Clone + // can be copied/cloned. + Value(const Value & other) + : raw(other.raw) + { + } + void operator =(const Value & other) + { + if (!isEvacuated()) + drop(this); + } + void operator =(Value && other) { if (!isEvacuated()) @@ -76,6 +92,16 @@ struct Vec : Value<3 * sizeof(void *), drop> { return ((const T * *) &this->raw)[0]; } + +protected: + + // Must not be called directly. + Vec(); + + Vec(Vec && other) = default; + + // Delete until we know how to do this properly. + Vec(const Vec & other) = delete; }; /* A Rust slice. */ @@ -144,7 +170,7 @@ struct Result std::exception_ptr * exc; }; - Result() : tag(Uninit) { }; // FIXME: remove + Result() = delete; Result(const Result &) = delete; @@ -171,7 +197,7 @@ struct Result } /* Rethrow the wrapped exception or return the wrapped value. */ - T unwrap() + T unwrap() && { if (tag == Ok) { tag = Uninit; -- cgit v1.2.3 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. --- perl/lib/Nix/Store.xs | 10 ++-- src/build-remote/build-remote.cc | 8 +-- src/cpptoml/cpptoml.h | 6 +-- src/libexpr/eval.cc | 4 +- src/libexpr/function-trace.cc | 4 +- src/libexpr/parser.y | 2 +- src/libexpr/primops.cc | 22 ++++---- src/libexpr/primops/fetchGit.cc | 8 +-- src/libexpr/primops/fetchMercurial.cc | 10 ++-- src/libmain/common-args.cc | 8 +-- src/libmain/shared.cc | 2 +- src/libmain/shared.hh | 4 +- src/libstore/binary-cache-store.cc | 12 ++--- src/libstore/build.cc | 92 +++++++++++++++++--------------- src/libstore/builtins/fetchurl.cc | 2 +- src/libstore/daemon.cc | 23 +++++--- src/libstore/derivations.cc | 10 ++-- src/libstore/download.cc | 14 ++--- src/libstore/export-import.cc | 8 +-- src/libstore/gc.cc | 6 +-- src/libstore/legacy-ssh-store.cc | 2 +- src/libstore/local-store.cc | 26 ++++----- src/libstore/local-store.hh | 2 +- src/libstore/misc.cc | 2 +- src/libstore/nar-info.cc | 8 +-- src/libstore/optimise-store.cc | 14 ++--- src/libstore/references.cc | 4 +- src/libstore/remote-store.cc | 10 ++-- src/libstore/remote-store.hh | 2 +- src/libstore/s3-binary-cache-store.cc | 4 +- src/libstore/ssh.cc | 4 +- src/libstore/store-api.cc | 30 +++++------ src/libstore/store-api.hh | 8 +-- src/libutil/args.cc | 2 +- src/libutil/args.hh | 2 +- src/libutil/compression.cc | 2 +- src/libutil/hash.cc | 70 ++++++++++++------------ src/libutil/hash.hh | 33 ++++++++---- src/libutil/logging.cc | 18 +++---- src/libutil/logging.hh | 88 +++++++++++++++--------------- src/libutil/util.cc | 4 +- src/libutil/util.hh | 2 +- src/nix-copy-closure/nix-copy-closure.cc | 4 +- src/nix-env/nix-env.cc | 6 +-- src/nix-prefetch-url/nix-prefetch-url.cc | 4 +- src/nix-store/nix-store.cc | 12 ++--- 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 +-- 57 files changed, 384 insertions(+), 356 deletions(-) diff --git a/perl/lib/Nix/Store.xs b/perl/lib/Nix/Store.xs index 1ca734e75..dc6db9444 100644 --- a/perl/lib/Nix/Store.xs +++ b/perl/lib/Nix/Store.xs @@ -106,7 +106,7 @@ SV * queryPathInfo(char * path, int base32) XPUSHs(&PL_sv_undef); else XPUSHs(sv_2mortal(newSVpv(store()->printStorePath(*info->deriver).c_str(), 0))); - auto s = info->narHash.to_string(base32 ? Base32 : Base16); + auto s = info->narHash.to_string(base32 ? Base::Base32 : Base::Base16); XPUSHs(sv_2mortal(newSVpv(s.c_str(), 0))); mXPUSHi(info->registrationTime); mXPUSHi(info->narSize); @@ -192,7 +192,7 @@ SV * hashPath(char * algo, int base32, char * path) PPCODE: try { Hash h = hashPath(parseHashType(algo), path).first; - auto s = h.to_string(base32 ? Base32 : Base16, false); + auto s = h.to_string(base32 ? Base::Base32 : Base::Base16, false); XPUSHs(sv_2mortal(newSVpv(s.c_str(), 0))); } catch (Error & e) { croak("%s", e.what()); @@ -203,7 +203,7 @@ SV * hashFile(char * algo, int base32, char * path) PPCODE: try { Hash h = hashFile(parseHashType(algo), path); - auto s = h.to_string(base32 ? Base32 : Base16, false); + auto s = h.to_string(base32 ? Base::Base32 : Base::Base16, false); XPUSHs(sv_2mortal(newSVpv(s.c_str(), 0))); } catch (Error & e) { croak("%s", e.what()); @@ -214,7 +214,7 @@ SV * hashString(char * algo, int base32, char * s) PPCODE: try { Hash h = hashString(parseHashType(algo), s); - auto s = h.to_string(base32 ? Base32 : Base16, false); + auto s = h.to_string(base32 ? Base::Base32 : Base::Base16, false); XPUSHs(sv_2mortal(newSVpv(s.c_str(), 0))); } catch (Error & e) { croak("%s", e.what()); @@ -225,7 +225,7 @@ SV * convertHash(char * algo, char * s, int toBase32) PPCODE: try { Hash h(s, parseHashType(algo)); - string s = h.to_string(toBase32 ? Base32 : Base16, false); + string s = h.to_string(toBase32 ? Base::Base32 : Base::Base16, false); XPUSHs(sv_2mortal(newSVpv(s.c_str(), 0))); } catch (Error & e) { croak("%s", e.what()); diff --git a/src/build-remote/build-remote.cc b/src/build-remote/build-remote.cc index 69d1c6f7e..6843a8f13 100644 --- a/src/build-remote/build-remote.cc +++ b/src/build-remote/build-remote.cc @@ -184,7 +184,7 @@ static int _main(int argc, char * * argv) try { - Activity act(*logger, lvlTalkative, actUnknown, fmt("connecting to '%s'", bestMachine->storeUri)); + Activity act(*logger, Verbosity::Talkative, ActivityType::Unknown, fmt("connecting to '%s'", bestMachine->storeUri)); Store::Params storeParams; if (hasPrefix(bestMachine->storeUri, "ssh://")) { @@ -222,7 +222,7 @@ connected: AutoCloseFD uploadLock = openLockFile(currentLoad + "/" + escapeUri(storeUri) + ".upload-lock", true); { - Activity act(*logger, lvlTalkative, actUnknown, fmt("waiting for the upload lock to '%s'", storeUri)); + Activity act(*logger, Verbosity::Talkative, ActivityType::Unknown, fmt("waiting for the upload lock to '%s'", storeUri)); auto old = signal(SIGALRM, handleAlarm); alarm(15 * 60); @@ -235,7 +235,7 @@ connected: auto substitute = settings.buildersUseSubstitutes ? Substitute : NoSubstitute; { - Activity act(*logger, lvlTalkative, actUnknown, fmt("copying dependencies to '%s'", storeUri)); + Activity act(*logger, Verbosity::Talkative, ActivityType::Unknown, fmt("copying dependencies to '%s'", storeUri)); copyPaths(store, ref(sshStore), store->parseStorePathSet(inputs), NoRepair, NoCheckSigs, substitute); } @@ -254,7 +254,7 @@ connected: if (!store->isValidPath(store->parseStorePath(path))) missing.insert(store->parseStorePath(path)); if (!missing.empty()) { - Activity act(*logger, lvlTalkative, actUnknown, fmt("copying outputs from '%s'", storeUri)); + Activity act(*logger, Verbosity::Talkative, ActivityType::Unknown, fmt("copying outputs from '%s'", storeUri)); for (auto & i : missing) store->locksHeld.insert(store->printStorePath(i)); /* FIXME: ugly */ copyPaths(ref(sshStore), store, missing, NoRepair, NoCheckSigs, NoSubstitute); diff --git a/src/cpptoml/cpptoml.h b/src/cpptoml/cpptoml.h index 5a00da3b4..fae1f0bc9 100644 --- a/src/cpptoml/cpptoml.h +++ b/src/cpptoml/cpptoml.h @@ -51,7 +51,7 @@ using string_to_base_map = std::unordered_map>; #endif -// if defined, `base` will retain type information in form of an enum class +// if defined, `base` will retain type information in form of an enum struct // such that static_cast can be used instead of dynamic_cast // #define CPPTOML_NO_RTTI @@ -405,7 +405,7 @@ inline std::shared_ptr make_table_array(bool is_inline = false); #if defined(CPPTOML_NO_RTTI) /// Base type used to store underlying data type explicitly if RTTI is disabled -enum class base_type +enum struct base_type { NONE, STRING, @@ -2268,7 +2268,7 @@ class parser return key; } - enum class parse_type + enum struct parse_type { STRING = 1, LOCAL_TIME, diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc index dac32b6f5..b94035a60 100644 --- a/src/libexpr/eval.cc +++ b/src/libexpr/eval.cc @@ -1661,10 +1661,10 @@ string EvalState::copyPathToStore(PathSet & context, const Path & path) else { auto p = settings.readOnlyMode ? store->computeStorePathForPath(std::string(baseNameOf(path)), checkSourcePath(path)).first - : store->addToStore(std::string(baseNameOf(path)), checkSourcePath(path), true, htSHA256, defaultPathFilter, repair); + : store->addToStore(std::string(baseNameOf(path)), checkSourcePath(path), true, HashType::SHA256, defaultPathFilter, repair); dstPath = store->printStorePath(p); srcToStore.insert_or_assign(path, std::move(p)); - printMsg(lvlChatty, "copied source '%1%' -> '%2%'", path, dstPath); + printMsg(Verbosity::Chatty, "copied source '%1%' -> '%2%'", path, dstPath); } context.insert(dstPath); diff --git a/src/libexpr/function-trace.cc b/src/libexpr/function-trace.cc index c6057b384..882da9937 100644 --- a/src/libexpr/function-trace.cc +++ b/src/libexpr/function-trace.cc @@ -6,13 +6,13 @@ namespace nix { FunctionCallTrace::FunctionCallTrace(const Pos & pos) : pos(pos) { auto duration = std::chrono::high_resolution_clock::now().time_since_epoch(); auto ns = std::chrono::duration_cast(duration); - printMsg(lvlInfo, "function-trace entered %1% at %2%", pos, ns.count()); + printMsg(Verbosity::Info, "function-trace entered %1% at %2%", pos, ns.count()); } FunctionCallTrace::~FunctionCallTrace() { auto duration = std::chrono::high_resolution_clock::now().time_since_epoch(); auto ns = std::chrono::duration_cast(duration); - printMsg(lvlInfo, "function-trace exited %1% at %2%", pos, ns.count()); + printMsg(Verbosity::Info, "function-trace exited %1% at %2%", pos, ns.count()); } } diff --git a/src/libexpr/parser.y b/src/libexpr/parser.y index 9c769e803..acffc23e3 100644 --- a/src/libexpr/parser.y +++ b/src/libexpr/parser.y @@ -625,7 +625,7 @@ Expr * EvalState::parseExprFromString(std::string_view s, const Path & basePath) Expr * EvalState::parseStdin() { - //Activity act(*logger, lvlTalkative, format("parsing standard input")); + //Activity act(*logger, Verbosity::Talkative, format("parsing standard input")); return parseExprFromString(drainFD(0), absPath(".")); } diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc index 8de234951..1ddbe33c4 100644 --- a/src/libexpr/primops.cc +++ b/src/libexpr/primops.cc @@ -719,14 +719,14 @@ static void prim_derivationStrict(EvalState & state, const Pos & pos, Value * * if (outputs.size() != 1 || *(outputs.begin()) != "out") throw Error(format("multiple outputs are not supported in fixed-output derivations, at %1%") % posDrvName); - HashType ht = outputHashAlgo.empty() ? htUnknown : parseHashType(outputHashAlgo); + HashType ht = outputHashAlgo.empty() ? HashType::Unknown : parseHashType(outputHashAlgo); Hash h(*outputHash, ht); auto outPath = state.store->makeFixedOutputPath(outputHashRecursive, h, drvName); if (!jsonObject) drv.env["out"] = state.store->printStorePath(outPath); drv.outputs.insert_or_assign("out", DerivationOutput(std::move(outPath), (outputHashRecursive ? "r:" : "") + printHashType(h.type), - h.to_string(Base16, false))); + h.to_string(Base::Base16, false))); } else { @@ -756,7 +756,7 @@ static void prim_derivationStrict(EvalState & state, const Pos & pos, Value * * auto drvPath = writeDerivation(state.store, drv, drvName, state.repair); auto drvPathS = state.store->printStorePath(drvPath); - printMsg(lvlChatty, "instantiated '%1%' -> '%2%'", drvName, drvPathS); + printMsg(Verbosity::Chatty, "instantiated '%1%' -> '%2%'", drvName, drvPathS); /* Optimisation, but required in read-only mode! because in that case we don't actually write store derivations, so we can't @@ -933,13 +933,13 @@ static void prim_hashFile(EvalState & state, const Pos & pos, Value * * args, Va { string type = state.forceStringNoCtx(*args[0], pos); HashType ht = parseHashType(type); - if (ht == htUnknown) + if (ht == HashType::Unknown) throw Error(format("unknown hash type '%1%', at %2%") % type % pos); PathSet context; // discarded Path p = state.coerceToPath(pos, *args[1], context); - mkString(v, hashFile(ht, state.checkSourcePath(p)).to_string(Base16, false), context); + mkString(v, hashFile(ht, state.checkSourcePath(p)).to_string(Base::Base16, false), context); } /* Read a directory (without . or ..) */ @@ -1073,8 +1073,8 @@ static void addPath(EvalState & state, const Pos & pos, const string & name, con Path dstPath; if (!expectedHash || !state.store->isValidPath(*expectedStorePath)) { dstPath = state.store->printStorePath(settings.readOnlyMode - ? state.store->computeStorePathForPath(name, path, recursive, htSHA256, filter).first - : state.store->addToStore(name, path, recursive, htSHA256, filter, state.repair)); + ? state.store->computeStorePathForPath(name, path, recursive, HashType::SHA256, filter).first + : state.store->addToStore(name, path, recursive, HashType::SHA256, filter, state.repair)); if (expectedHash && expectedStorePath != state.store->parseStorePath(dstPath)) throw Error("store path mismatch in (possibly filtered) path added from '%s'", path); } else @@ -1122,7 +1122,7 @@ static void prim_path(EvalState & state, const Pos & pos, Value * * args, Value } else if (n == "recursive") recursive = state.forceBool(*attr.value, *attr.pos); else if (n == "sha256") - expectedHash = Hash(state.forceStringNoCtx(*attr.value, *attr.pos), htSHA256); + expectedHash = Hash(state.forceStringNoCtx(*attr.value, *attr.pos), HashType::SHA256); else throw EvalError(format("unsupported argument '%1%' to 'addPath', at %2%") % attr.name % *attr.pos); } @@ -1806,13 +1806,13 @@ static void prim_hashString(EvalState & state, const Pos & pos, Value * * args, { string type = state.forceStringNoCtx(*args[0], pos); HashType ht = parseHashType(type); - if (ht == htUnknown) + if (ht == HashType::Unknown) throw Error(format("unknown hash type '%1%', at %2%") % type % pos); PathSet context; // discarded string s = state.forceString(*args[1], context, pos); - mkString(v, hashString(ht, s).to_string(Base16, false), context); + mkString(v, hashString(ht, s).to_string(Base::Base16, false), context); } @@ -2068,7 +2068,7 @@ void fetch(EvalState & state, const Pos & pos, Value * * args, Value & v, if (n == "url") request.uri = state.forceStringNoCtx(*attr.value, *attr.pos); else if (n == "sha256") - request.expectedHash = Hash(state.forceStringNoCtx(*attr.value, *attr.pos), htSHA256); + request.expectedHash = Hash(state.forceStringNoCtx(*attr.value, *attr.pos), HashType::SHA256); else if (n == "name") request.name = state.forceStringNoCtx(*attr.value, *attr.pos); else diff --git a/src/libexpr/primops/fetchGit.cc b/src/libexpr/primops/fetchGit.cc index 4aee1073e..7f70dfab0 100644 --- a/src/libexpr/primops/fetchGit.cc +++ b/src/libexpr/primops/fetchGit.cc @@ -69,7 +69,7 @@ GitInfo exportGit(ref store, const std::string & uri, return files.count(file); }; - gitInfo.storePath = store->printStorePath(store->addToStore("source", uri, true, htSHA256, filter)); + gitInfo.storePath = store->printStorePath(store->addToStore("source", uri, true, HashType::SHA256, filter)); return gitInfo; } @@ -86,7 +86,7 @@ GitInfo exportGit(ref store, const std::string & uri, deletePath(getCacheDir() + "/nix/git"); - Path cacheDir = getCacheDir() + "/nix/gitv2/" + hashString(htSHA256, uri).to_string(Base32, false); + Path cacheDir = getCacheDir() + "/nix/gitv2/" + hashString(HashType::SHA256, uri).to_string(Base::Base32, false); if (!pathExists(cacheDir)) { createDirs(dirOf(cacheDir)); @@ -123,7 +123,7 @@ GitInfo exportGit(ref store, const std::string & uri, } if (doFetch) { - Activity act(*logger, lvlTalkative, actUnknown, fmt("fetching Git repository '%s'", uri)); + Activity act(*logger, Verbosity::Talkative, ActivityType::Unknown, fmt("fetching Git repository '%s'", uri)); // FIXME: git stderr messes up our progress indicator, so // we're using --quiet for now. Should process its stderr. @@ -145,7 +145,7 @@ GitInfo exportGit(ref store, const std::string & uri, printTalkative("using revision %s of repo '%s'", gitInfo.rev, uri); - std::string storeLinkName = hashString(htSHA512, name + std::string("\0"s) + gitInfo.rev).to_string(Base32, false); + std::string storeLinkName = hashString(HashType::SHA512, name + std::string("\0"s) + gitInfo.rev).to_string(Base::Base32, false); Path storeLink = cacheDir + "/" + storeLinkName + ".link"; PathLocks storeLinkLock({storeLink}, fmt("waiting for lock on '%1%'...", storeLink)); // FIXME: broken diff --git a/src/libexpr/primops/fetchMercurial.cc b/src/libexpr/primops/fetchMercurial.cc index db274fa4f..65f52f682 100644 --- a/src/libexpr/primops/fetchMercurial.cc +++ b/src/libexpr/primops/fetchMercurial.cc @@ -63,7 +63,7 @@ HgInfo exportMercurial(ref store, const std::string & uri, return files.count(file); }; - hgInfo.storePath = store->printStorePath(store->addToStore("source", uri, true, htSHA256, filter)); + hgInfo.storePath = store->printStorePath(store->addToStore("source", uri, true, HashType::SHA256, filter)); return hgInfo; } @@ -71,9 +71,9 @@ HgInfo exportMercurial(ref store, const std::string & uri, if (rev == "") rev = "default"; - Path cacheDir = fmt("%s/nix/hg/%s", getCacheDir(), hashString(htSHA256, uri).to_string(Base32, false)); + Path cacheDir = fmt("%s/nix/hg/%s", getCacheDir(), hashString(HashType::SHA256, uri).to_string(Base::Base32, false)); - Path stampFile = fmt("%s/.hg/%s.stamp", cacheDir, hashString(htSHA512, rev).to_string(Base32, false)); + Path stampFile = fmt("%s/.hg/%s.stamp", cacheDir, hashString(HashType::SHA512, rev).to_string(Base::Base32, false)); /* If we haven't pulled this repo less than ‘tarball-ttl’ seconds, do so now. */ @@ -90,7 +90,7 @@ HgInfo exportMercurial(ref store, const std::string & uri, RunOptions("hg", { "log", "-R", cacheDir, "-r", rev, "--template", "1" }) .killStderr(true)).second == "1")) { - Activity act(*logger, lvlTalkative, actUnknown, fmt("fetching Mercurial repository '%s'", uri)); + Activity act(*logger, Verbosity::Talkative, ActivityType::Unknown, fmt("fetching Mercurial repository '%s'", uri)); if (pathExists(cacheDir)) { try { @@ -124,7 +124,7 @@ HgInfo exportMercurial(ref store, const std::string & uri, hgInfo.revCount = std::stoull(tokens[1]); hgInfo.branch = tokens[2]; - std::string storeLinkName = hashString(htSHA512, name + std::string("\0"s) + hgInfo.rev).to_string(Base32, false); + std::string storeLinkName = hashString(HashType::SHA512, name + std::string("\0"s) + hgInfo.rev).to_string(Base::Base32, false); Path storeLink = fmt("%s/.hg/%s.link", cacheDir, storeLinkName); try { diff --git a/src/libmain/common-args.cc b/src/libmain/common-args.cc index 9e1d7cee6..9c873e22a 100644 --- a/src/libmain/common-args.cc +++ b/src/libmain/common-args.cc @@ -10,17 +10,19 @@ MixCommonArgs::MixCommonArgs(const string & programName) .longName("verbose") .shortName('v') .description("increase verbosity level") - .handler([]() { verbosity = (Verbosity) (verbosity + 1); }); + .handler([]() { verbosity = (Verbosity) ((uint64_t) verbosity + 1); }); mkFlag() .longName("quiet") .description("decrease verbosity level") - .handler([]() { verbosity = verbosity > lvlError ? (Verbosity) (verbosity - 1) : lvlError; }); + .handler([]() { verbosity = verbosity > Verbosity::Error + ? (Verbosity) ((uint64_t) verbosity - 1) + : Verbosity::Error; }); mkFlag() .longName("debug") .description("enable debug output") - .handler([]() { verbosity = lvlDebug; }); + .handler([]() { verbosity = Verbosity::Debug; }); mkFlag() .longName("option") diff --git a/src/libmain/shared.cc b/src/libmain/shared.cc index d41e772e9..79e35eedc 100644 --- a/src/libmain/shared.cc +++ b/src/libmain/shared.cc @@ -251,7 +251,7 @@ void parseCmdLine(const string & programName, const Strings & args, void printVersion(const string & programName) { std::cout << format("%1% (Nix) %2%") % programName % nixVersion << std::endl; - if (verbosity > lvlInfo) { + if (verbosity > Verbosity::Info) { Strings cfg; #if HAVE_BOEHMGC cfg.push_back("gc"); diff --git a/src/libmain/shared.hh b/src/libmain/shared.hh index b49574652..96d001ec3 100644 --- a/src/libmain/shared.hh +++ b/src/libmain/shared.hh @@ -43,11 +43,11 @@ struct StorePathWithOutputs; void printMissing( ref store, const std::vector & paths, - Verbosity lvl = lvlInfo); + Verbosity lvl = Verbosity::Info); void printMissing(ref store, const StorePathSet & willBuild, const StorePathSet & willSubstitute, const StorePathSet & unknown, - unsigned long long downloadSize, unsigned long long narSize, Verbosity lvl = lvlInfo); + unsigned long long downloadSize, unsigned long long narSize, Verbosity lvl = Verbosity::Info); string getArg(const string & opt, Strings::iterator & i, const Strings::iterator & end); diff --git a/src/libstore/binary-cache-store.cc b/src/libstore/binary-cache-store.cc index 3a2d84861..a650bbfa6 100644 --- a/src/libstore/binary-cache-store.cc +++ b/src/libstore/binary-cache-store.cc @@ -134,7 +134,7 @@ void BinaryCacheStore::addToStore(const ValidPathInfo & info, const ref(info); narInfo->narSize = nar->size(); - narInfo->narHash = hashString(htSHA256, *nar); + narInfo->narHash = hashString(HashType::SHA256, *nar); if (info.narHash && info.narHash != narInfo->narHash) throw Error("refusing to copy corrupted path '%1%' to binary cache", printStorePath(info.path)); @@ -169,16 +169,16 @@ void BinaryCacheStore::addToStore(const ValidPathInfo & info, const reffileHash = hashString(htSHA256, *narCompressed); + narInfo->fileHash = hashString(HashType::SHA256, *narCompressed); narInfo->fileSize = narCompressed->size(); auto duration = std::chrono::duration_cast(now2 - now1).count(); - printMsg(lvlTalkative, "copying path '%1%' (%2% bytes, compressed %3$.1f%% in %4% ms) to binary cache", + printMsg(Verbosity::Talkative, "copying path '%1%' (%2% bytes, compressed %3$.1f%% in %4% ms) to binary cache", printStorePath(narInfo->path), narInfo->narSize, ((1.0 - (double) narCompressed->size() / nar->size()) * 100.0), duration); - narInfo->url = "nar/" + narInfo->fileHash.to_string(Base32, false) + ".nar" + narInfo->url = "nar/" + narInfo->fileHash.to_string(Base::Base32, false) + ".nar" + (compression == "xz" ? ".xz" : compression == "bzip2" ? ".bz2" : compression == "br" ? ".br" : @@ -206,7 +206,7 @@ void BinaryCacheStore::addToStore(const ValidPathInfo & info, const ref(*logger, lvlTalkative, actQueryPathInfo, + auto act = std::make_shared(*logger, Verbosity::Talkative, ActivityType::QueryPathInfo, fmt("querying info about '%s' on '%s'", storePathS, uri), Logger::Fields{storePathS, uri}); PushActivity pact(act->id); diff --git a/src/libstore/build.cc b/src/libstore/build.cc index 0e3a23a4d..0259cfd0b 100644 --- a/src/libstore/build.cc +++ b/src/libstore/build.cc @@ -107,7 +107,13 @@ typedef std::map WeakGoalMap; class Goal : public std::enable_shared_from_this { public: - typedef enum {ecBusy, ecSuccess, ecFailed, ecNoSubstituters, ecIncompleteClosure} ExitCode; + enum struct ExitCode { + Busy, + Success, + Failed, + NoSubstituters, + IncompleteClosure, + }; protected: @@ -141,7 +147,7 @@ protected: Goal(Worker & worker) : worker(worker) { nrFailed = nrNoSubstituters = nrIncompleteClosure = 0; - exitCode = ecBusy; + exitCode = ExitCode::Busy; } virtual ~Goal() @@ -361,8 +367,8 @@ public: { actDerivations.progress(doneBuilds, expectedBuilds + doneBuilds, runningBuilds, failedBuilds); actSubstitutions.progress(doneSubstitutions, expectedSubstitutions + doneSubstitutions, runningSubstitutions, failedSubstitutions); - act.setExpected(actDownload, expectedDownloadSize + doneDownloadSize); - act.setExpected(actCopyPath, expectedNarSize + doneNarSize); + act.setExpected(ActivityType::Download, expectedDownloadSize + doneDownloadSize); + act.setExpected(ActivityType::CopyPath, expectedNarSize + doneNarSize); } }; @@ -395,13 +401,13 @@ void Goal::waiteeDone(GoalPtr waitee, ExitCode result) trace(format("waitee '%1%' done; %2% left") % waitee->name % waitees.size()); - if (result == ecFailed || result == ecNoSubstituters || result == ecIncompleteClosure) ++nrFailed; + if (result == ExitCode::Failed || result == ExitCode::NoSubstituters || result == ExitCode::IncompleteClosure) ++nrFailed; - if (result == ecNoSubstituters) ++nrNoSubstituters; + if (result == ExitCode::NoSubstituters) ++nrNoSubstituters; - if (result == ecIncompleteClosure) ++nrIncompleteClosure; + if (result == ExitCode::IncompleteClosure) ++nrIncompleteClosure; - if (waitees.empty() || (result == ecFailed && !settings.keepGoing)) { + if (waitees.empty() || (result == ExitCode::Failed && !settings.keepGoing)) { /* If we failed and keepGoing is not set, we remove all remaining waitees. */ @@ -421,8 +427,8 @@ void Goal::waiteeDone(GoalPtr waitee, ExitCode result) void Goal::amDone(ExitCode result) { trace("done"); - assert(exitCode == ecBusy); - assert(result == ecSuccess || result == ecFailed || result == ecNoSubstituters || result == ecIncompleteClosure); + assert(exitCode == ExitCode::Busy); + assert(result == ExitCode::Success || result == ExitCode::Failed || result == ExitCode::NoSubstituters || result == ExitCode::IncompleteClosure); exitCode = result; for (auto & i : waiters) { GoalPtr goal = i.lock(); @@ -668,7 +674,7 @@ HookInstance::HookInstance() Strings args = { std::string(baseNameOf(settings.buildHook.get())), - std::to_string(verbosity), + std::to_string((uint64_t)verbosity), }; execv(settings.buildHook.get().c_str(), stringsToCharPtrs(args).data()); @@ -1445,7 +1451,7 @@ void DerivationGoal::tryToBuild() "building '%s'", worker.store.printStorePath(drvPath), curRound, nrRounds); fmt("building '%s'", worker.store.printStorePath(drvPath)); if (hook) msg += fmt(" on '%s'", machineName); - act = std::make_unique(*logger, lvlInfo, actBuild, msg, + act = std::make_unique(*logger, Verbosity::Info, ActivityType::Build, msg, Logger::Fields{worker.store.printStorePath(drvPath), hook ? machineName : "", curRound, nrRounds}); mcRunningBuilds = std::make_unique>(worker.runningBuilds); worker.updateProgress(); @@ -1625,7 +1631,7 @@ void DerivationGoal::buildDone() registerOutputs(); if (settings.postBuildHook != "") { - Activity act(*logger, lvlInfo, actPostBuildHook, + Activity act(*logger, Verbosity::Info, ActivityType::PostBuildHook, fmt("running post-build-hook '%s'", settings.postBuildHook), Logger::Fields{worker.store.printStorePath(drvPath)}); PushActivity pact(act.id); @@ -1660,7 +1666,7 @@ void DerivationGoal::buildDone() if (settings.verboseBuild) { printError("post-build-hook: " + currentLine); } else { - act.result(resPostBuildLogLine, currentLine); + act.result(ResultType::PostBuildLogLine, currentLine); } currentLine.clear(); } @@ -2078,7 +2084,7 @@ void DerivationGoal::startBuilder() /* Clean up the chroot directory automatically. */ autoDelChroot = std::make_shared(chrootRootDir); - printMsg(lvlChatty, format("setting up chroot environment in '%1%'") % chrootRootDir); + printMsg(Verbosity::Chatty, format("setting up chroot environment in '%1%'") % chrootRootDir); if (mkdir(chrootRootDir.c_str(), 0750) == -1) throw SysError(format("cannot create '%1%'") % chrootRootDir); @@ -2187,7 +2193,7 @@ void DerivationGoal::startBuilder() } if (useChroot && settings.preBuildHook != "" && dynamic_cast(drv.get())) { - printMsg(lvlChatty, format("executing pre-build hook '%1%'") + printMsg(Verbosity::Chatty, format("executing pre-build hook '%1%'") % settings.preBuildHook); auto args = useChroot ? Strings({worker.store.printStorePath(drvPath), chrootRootDir}) : Strings({ worker.store.printStorePath(drvPath) }); @@ -2229,7 +2235,7 @@ void DerivationGoal::startBuilder() startDaemon(); /* Run the builder. */ - printMsg(lvlChatty, format("executing builder '%1%'") % drv->builder); + printMsg(Verbosity::Chatty, format("executing builder '%1%'") % drv->builder); /* Create the log file. */ Path logFile = openLogFile(); @@ -2462,8 +2468,8 @@ void DerivationGoal::initTmpDir() { if (passAsFile.find(i.first) == passAsFile.end()) { env[i.first] = i.second; } else { - auto hash = hashString(htSHA256, i.first); - string fn = ".attr-" + hash.to_string(Base32, false); + auto hash = hashString(HashType::SHA256, i.first); + string fn = ".attr-" + hash.to_string(Base::Base32, false); Path p = tmpDir + "/" + fn; writeFile(p, i.second); chownToBuilder(p); @@ -2712,7 +2718,7 @@ struct RestrictedStore : public LocalFSStore { throw Error("queryPathFromHashPart"); } StorePath addToStore(const string & name, const Path & srcPath, - bool recursive = true, HashType hashAlgo = htSHA256, + bool recursive = true, HashType hashAlgo = HashType::SHA256, PathFilter & filter = defaultPathFilter, RepairFlag repair = NoRepair) override { throw Error("addToStore"); } @@ -2725,7 +2731,7 @@ struct RestrictedStore : public LocalFSStore } StorePath addToStoreFromDump(const string & dump, const string & name, - bool recursive = true, HashType hashAlgo = htSHA256, RepairFlag repair = NoRepair) override + bool recursive = true, HashType hashAlgo = HashType::SHA256, RepairFlag repair = NoRepair) override { auto path = next->addToStoreFromDump(dump, name, recursive, hashAlgo, repair); goal.addDependency(path); @@ -3670,7 +3676,7 @@ void DerivationGoal::registerOutputs() worker.hashMismatch = true; delayedException = std::make_exception_ptr( BuildError("hash mismatch in fixed-output derivation '%s':\n wanted: %s\n got: %s", - worker.store.printStorePath(dest), h.to_string(SRI), h2.to_string(SRI))); + worker.store.printStorePath(dest), h.to_string(Base::SRI), h2.to_string(Base::SRI))); Path actualDest = worker.store.Store::toRealPath(dest); @@ -4114,7 +4120,7 @@ void DerivationGoal::flushLine() if (logTail.size() > settings.logLines) logTail.pop_front(); } - act->result(resBuildLogLine, currentLogLine); + act->result(ResultType::BuildLogLine, currentLogLine); } currentLogLine = ""; @@ -4141,7 +4147,7 @@ void DerivationGoal::addHashRewrite(const StorePath & path) auto h1 = std::string(((std::string_view) path.to_string()).substr(0, 32)); auto p = worker.store.makeStorePath( "rewrite:" + std::string(drvPath.to_string()) + ":" + std::string(path.to_string()), - Hash(htSHA256), path.name()); + Hash(HashType::SHA256), path.name()); auto h2 = std::string(((std::string_view) p.to_string()).substr(0, 32)); deletePath(worker.store.printStorePath(p)); inputRewrites[h1] = h2; @@ -4154,7 +4160,7 @@ void DerivationGoal::done(BuildResult::Status status, const string & msg) { result.status = status; result.errorMsg = msg; - amDone(result.success() ? ecSuccess : ecFailed); + amDone(result.success() ? ExitCode::Success : ExitCode::Failed); if (result.status == BuildResult::TimedOut) worker.timedOut = true; if (result.status == BuildResult::PermanentFailure) @@ -4295,7 +4301,7 @@ void SubstitutionGoal::init() /* If the path already exists we're done. */ if (!repair && worker.store.isValidPath(storePath)) { - amDone(ecSuccess); + amDone(ExitCode::Success); return; } @@ -4320,7 +4326,7 @@ void SubstitutionGoal::tryNext() /* Hack: don't indicate failure if there were no substituters. In that case the calling derivation should just do a build. */ - amDone(substituterFailed ? ecFailed : ecNoSubstituters); + amDone(substituterFailed ? ExitCode::Failed : ExitCode::NoSubstituters); if (substituterFailed) { worker.failedSubstitutions++; @@ -4403,7 +4409,7 @@ void SubstitutionGoal::referencesValid() if (nrFailed > 0) { debug("some references of path '%s' could not be realised", worker.store.printStorePath(storePath)); - amDone(nrNoSubstituters > 0 || nrIncompleteClosure > 0 ? ecIncompleteClosure : ecFailed); + amDone(nrNoSubstituters > 0 || nrIncompleteClosure > 0 ? ExitCode::IncompleteClosure : ExitCode::Failed); return; } @@ -4441,7 +4447,7 @@ void SubstitutionGoal::tryToRun() /* Wake up the worker loop when we're done. */ Finally updateStats([this]() { outPipe.writeSide = -1; }); - Activity act(*logger, actSubstitute, Logger::Fields{worker.store.printStorePath(storePath), sub->getUri()}); + Activity act(*logger, ActivityType::Substitute, Logger::Fields{worker.store.printStorePath(storePath), sub->getUri()}); PushActivity pact(act.id); copyStorePath(ref(sub), ref(worker.store.shared_from_this()), @@ -4490,7 +4496,7 @@ void SubstitutionGoal::finished() worker.markContentsGood(storePath.clone()); - printMsg(lvlChatty, "substitution of path '%s' succeeded", worker.store.printStorePath(storePath)); + printMsg(Verbosity::Chatty, "substitution of path '%s' succeeded", worker.store.printStorePath(storePath)); maintainRunningSubstitutions.reset(); @@ -4508,7 +4514,7 @@ void SubstitutionGoal::finished() worker.updateProgress(); - amDone(ecSuccess); + amDone(ExitCode::Success); } @@ -4527,9 +4533,9 @@ void SubstitutionGoal::handleEOF(int fd) Worker::Worker(LocalStore & store) - : act(*logger, actRealise) - , actDerivations(*logger, actBuilds) - , actSubstitutions(*logger, actCopyPaths) + : act(*logger, ActivityType::Realise) + , actDerivations(*logger, ActivityType::Builds) + , actSubstitutions(*logger, ActivityType::CopyPaths) , store(store) { /* Debugging: prevent recursive workers. */ @@ -4613,7 +4619,7 @@ void Worker::removeGoal(GoalPtr goal) topGoals.erase(goal); /* If a top-level goal failed, then kill all other goals (unless keepGoing was set). */ - if (goal->getExitCode() == Goal::ecFailed && !settings.keepGoing) + if (goal->getExitCode() == Goal::ExitCode::Failed && !settings.keepGoing) topGoals.clear(); } @@ -4757,7 +4763,7 @@ void Worker::run(const Goals & _topGoals) void Worker::waitForInput() { - printMsg(lvlVomit, "waiting for children"); + printMsg(Verbosity::Vomit, "waiting for children"); /* Process output from the file descriptors attached to the children, namely log output and output path creation commands. @@ -4852,7 +4858,7 @@ void Worker::waitForInput() if (errno != EINTR) throw SysError("%s: read failed", goal->getName()); } else { - printMsg(lvlVomit, format("%1%: read %2% bytes") + printMsg(Verbosity::Vomit, format("%1%: read %2% bytes") % goal->getName() % rd); string data((char *) buffer.data(), rd); j->lastOutput = after; @@ -4861,7 +4867,7 @@ void Worker::waitForInput() } } - if (goal->getExitCode() == Goal::ecBusy && + if (goal->getExitCode() == Goal::ExitCode::Busy && 0 != settings.maxSilentTime && j->respectTimeouts && after - j->lastOutput >= std::chrono::seconds(settings.maxSilentTime)) @@ -4872,7 +4878,7 @@ void Worker::waitForInput() goal->timedOut(); } - else if (goal->getExitCode() == Goal::ecBusy && + else if (goal->getExitCode() == Goal::ExitCode::Busy && 0 != settings.buildTimeout && j->respectTimeouts && after - j->timeStarted >= std::chrono::seconds(settings.buildTimeout)) @@ -4934,7 +4940,7 @@ bool Worker::pathContentsGood(const StorePath & path) res = false; else { HashResult current = hashPath(info->narHash.type, store.printStorePath(path)); - Hash nullHash(htSHA256); + Hash nullHash(HashType::SHA256); res = info->narHash == nullHash || info->narHash == current.first; } pathContentsGoodCache.insert_or_assign(path.clone(), res); @@ -4983,7 +4989,7 @@ void LocalStore::buildPaths(const std::vector & drvPaths, StorePathSet failed; for (auto & i : goals) { - if (i->getExitCode() != Goal::ecSuccess) { + if (i->getExitCode() != Goal::ExitCode::Success) { DerivationGoal * i2 = dynamic_cast(i.get()); if (i2) failed.insert(i2->getDrvPath()); else failed.insert(dynamic_cast(i.get())->getStorePath()); @@ -5028,7 +5034,7 @@ void LocalStore::ensurePath(const StorePath & path) worker.run(goals); - if (goal->getExitCode() != Goal::ecSuccess) + if (goal->getExitCode() != Goal::ExitCode::Success) throw Error(worker.exitStatus(), "path '%s' does not exist and cannot be created", printStorePath(path)); } @@ -5041,7 +5047,7 @@ void LocalStore::repairPath(const StorePath & path) worker.run(goals); - if (goal->getExitCode() != Goal::ecSuccess) { + if (goal->getExitCode() != Goal::ExitCode::Success) { /* Since substituting the path didn't work, if we have a valid deriver, then rebuild the deriver. */ auto info = queryPathInfo(path); diff --git a/src/libstore/builtins/fetchurl.cc b/src/libstore/builtins/fetchurl.cc index f6ae5d2e6..809689d44 100644 --- a/src/libstore/builtins/fetchurl.cc +++ b/src/libstore/builtins/fetchurl.cc @@ -65,7 +65,7 @@ void builtinFetchurl(const BasicDerivation & drv, const std::string & netrcData) if (!hasSuffix(hashedMirror, "/")) hashedMirror += '/'; auto ht = parseHashType(getAttr("outputHashAlgo")); auto h = Hash(getAttr("outputHash"), ht); - fetch(hashedMirror + printHashType(h.type) + "/" + h.to_string(Base16, false)); + fetch(hashedMirror + printHashType(h.type) + "/" + h.to_string(Base::Base16, false)); return; } catch (Error & e) { debug(e.what()); diff --git a/src/libstore/daemon.cc b/src/libstore/daemon.cc index 8e9f9d71b..f854d1ebd 100644 --- a/src/libstore/daemon.cc +++ b/src/libstore/daemon.cc @@ -114,7 +114,13 @@ struct TunnelLogger : public Logger } StringSink buf; - buf << STDERR_START_ACTIVITY << act << lvl << type << s << fields << parent; + buf << STDERR_START_ACTIVITY + << act + << (uint64_t) lvl + << (uint64_t) type + << s + << fields + << parent; enqueueMsg(*buf.s); } @@ -130,7 +136,10 @@ struct TunnelLogger : public Logger { if (GET_PROTOCOL_MINOR(clientVersion) < 20) return; StringSink buf; - buf << STDERR_RESULT << act << type << fields; + buf << STDERR_RESULT + << act + << (uint64_t) type + << fields; enqueueMsg(*buf.s); } }; @@ -302,7 +311,7 @@ static void performOp(TunnelLogger * logger, ref store, logger->startWork(); auto hash = store->queryPathInfo(path)->narHash; logger->stopWork(); - to << hash.to_string(Base16, false); + to << hash.to_string(Base::Base16, false); break; } @@ -542,7 +551,7 @@ static void performOp(TunnelLogger * logger, ref store, clientSettings.maxBuildJobs = readInt(from); clientSettings.maxSilentTime = readInt(from); readInt(from); // obsolete useBuildHook - clientSettings.verboseBuild = lvlError == (Verbosity) readInt(from); + clientSettings.verboseBuild = Verbosity::Error == (Verbosity) readInt(from); readInt(from); // obsolete logType readInt(from); // obsolete printBuildTrace clientSettings.buildCores = readInt(from); @@ -627,7 +636,7 @@ static void performOp(TunnelLogger * logger, ref store, if (GET_PROTOCOL_MINOR(clientVersion) >= 17) to << 1; to << (info->deriver ? store->printStorePath(*info->deriver) : "") - << info->narHash.to_string(Base16, false); + << info->narHash.to_string(Base::Base16, false); writeStorePaths(*store, to, info->references); to << info->registrationTime << info->narSize; if (GET_PROTOCOL_MINOR(clientVersion) >= 16) { @@ -687,7 +696,7 @@ static void performOp(TunnelLogger * logger, ref store, auto deriver = readString(from); if (deriver != "") info.deriver = store->parseStorePath(deriver); - info.narHash = Hash(readString(from), htSHA256); + info.narHash = Hash(readString(from), HashType::SHA256); info.references = readStorePaths(*store, from); from >> info.registrationTime >> info.narSize >> info.ultimate; info.sigs = readStrings(from); @@ -770,7 +779,7 @@ void processConnection( Finally finally([&]() { _isInterrupted = false; - prevLogger->log(lvlDebug, fmt("%d operations", opCount)); + prevLogger->log(Verbosity::Debug, fmt("%d operations", opCount)); }); if (GET_PROTOCOL_MINOR(clientVersion) >= 14 && readInt(from)) { diff --git a/src/libstore/derivations.cc b/src/libstore/derivations.cc index 973ddc86a..38b4122dd 100644 --- a/src/libstore/derivations.cc +++ b/src/libstore/derivations.cc @@ -20,7 +20,7 @@ void DerivationOutput::parseHashInfo(bool & recursive, Hash & hash) const } HashType hashType = parseHashType(algo); - if (hashType == htUnknown) + if (hashType == HashType::Unknown) throw Error("unknown hash algorithm '%s'", algo); hash = Hash(this->hash, hashType); @@ -364,7 +364,7 @@ Hash hashDerivationModulo(Store & store, const Derivation & drv, bool maskOutput /* Return a fixed hash for fixed-output derivations. */ if (drv.isFixedOutput()) { DerivationOutputs::const_iterator i = drv.outputs.begin(); - return hashString(htSHA256, "fixed:out:" + return hashString(HashType::SHA256, "fixed:out:" + i->second.hashAlgo + ":" + i->second.hash + ":" + store.printStorePath(i->second.path)); @@ -380,10 +380,10 @@ Hash hashDerivationModulo(Store & store, const Derivation & drv, bool maskOutput h = drvHashes.insert_or_assign(i.first.clone(), hashDerivationModulo(store, readDerivation(store, store.toRealPath(store.printStorePath(i.first))), false)).first; } - inputs2.insert_or_assign(h->second.to_string(Base16, false), i.second); + inputs2.insert_or_assign(h->second.to_string(Base::Base16, false), i.second); } - return hashString(htSHA256, drv.unparse(store, maskOutputs, &inputs2)); + return hashString(HashType::SHA256, drv.unparse(store, maskOutputs, &inputs2)); } @@ -453,7 +453,7 @@ void writeDerivation(Sink & out, const Store & store, const BasicDerivation & dr std::string hashPlaceholder(const std::string & outputName) { // FIXME: memoize? - return "/" + hashString(htSHA256, "nix-output:" + outputName).to_string(Base32, false); + return "/" + hashString(HashType::SHA256, "nix-output:" + outputName).to_string(Base::Base32, false); } diff --git a/src/libstore/download.cc b/src/libstore/download.cc index 149c84765..99ce291f4 100644 --- a/src/libstore/download.cc +++ b/src/libstore/download.cc @@ -85,7 +85,7 @@ struct CurlDownloader : public Downloader Callback && callback) : downloader(downloader) , request(request) - , act(*logger, lvlTalkative, actDownload, + , act(*logger, Verbosity::Talkative, ActivityType::Download, fmt(request.data ? "uploading '%s'" : "downloading '%s'", request.uri), {request.uri}, request.parentAct) , callback(std::move(callback)) @@ -164,7 +164,7 @@ struct CurlDownloader : public Downloader { size_t realSize = size * nmemb; std::string line((char *) contents, realSize); - printMsg(lvlVomit, format("got header for '%s': %s") % request.uri % trim(line)); + printMsg(Verbosity::Vomit, format("got header for '%s': %s") % request.uri % trim(line)); if (line.compare(0, 5, "HTTP/") == 0) { // new response starts result.etag = ""; auto ss = tokenizeString>(line, " "); @@ -247,7 +247,7 @@ struct CurlDownloader : public Downloader curl_easy_reset(req); - if (verbosity >= lvlVomit) { + if (verbosity >= Verbosity::Vomit) { curl_easy_setopt(req, CURLOPT_VERBOSE, 1); curl_easy_setopt(req, CURLOPT_DEBUGFUNCTION, DownloadItem::debugCallback); } @@ -826,7 +826,7 @@ CachedDownloadResult Downloader::downloadCached( Path cacheDir = getCacheDir() + "/nix/tarballs"; createDirs(cacheDir); - string urlHash = hashString(htSHA256, name + std::string("\0"s) + url).to_string(Base32, false); + string urlHash = hashString(HashType::SHA256, name + std::string("\0"s) + url).to_string(Base::Base32, false); Path dataFile = cacheDir + "/" + urlHash + ".info"; Path fileLink = cacheDir + "/" + urlHash + "-file"; @@ -874,9 +874,9 @@ CachedDownloadResult Downloader::downloadCached( if (!res.cached) { StringSink sink; dumpString(*res.data, sink); - Hash hash = hashString(request.expectedHash ? request.expectedHash.type : htSHA256, *res.data); + Hash hash = hashString(request.expectedHash ? request.expectedHash.type : HashType::SHA256, *res.data); ValidPathInfo info(store->makeFixedOutputPath(false, hash, name)); - info.narHash = hashString(htSHA256, *sink.s); + info.narHash = hashString(HashType::SHA256, *sink.s); info.narSize = sink.s->size(); info.ca = makeFixedOutputCA(false, hash); store->addToStore(info, sink.s, NoRepair, NoCheckSigs); @@ -914,7 +914,7 @@ CachedDownloadResult Downloader::downloadCached( if (members.size() != 1) throw nix::Error("tarball '%s' contains an unexpected number of top-level files", url); auto topDir = tmpDir + "/" + members.begin()->name; - unpackedStorePath = store->addToStore(name, topDir, true, htSHA256, defaultPathFilter, NoRepair); + unpackedStorePath = store->addToStore(name, topDir, true, HashType::SHA256, defaultPathFilter, NoRepair); } replaceSymlink(store->printStorePath(*unpackedStorePath), unpackedLink); storePath = std::move(*unpackedStorePath); diff --git a/src/libstore/export-import.cc b/src/libstore/export-import.cc index 4692d1a7b..8a5e9d08e 100644 --- a/src/libstore/export-import.cc +++ b/src/libstore/export-import.cc @@ -10,7 +10,7 @@ struct HashAndWriteSink : Sink { Sink & writeSink; HashSink hashSink; - HashAndWriteSink(Sink & writeSink) : writeSink(writeSink), hashSink(htSHA256) + HashAndWriteSink(Sink & writeSink) : writeSink(writeSink), hashSink(HashType::SHA256) { } virtual void operator () (const unsigned char * data, size_t len) @@ -33,7 +33,7 @@ void Store::exportPaths(const StorePathSet & paths, Sink & sink) //logger->incExpected(doneLabel, sorted.size()); for (auto & path : sorted) { - //Activity act(*logger, lvlInfo, format("exporting path '%s'") % path); + //Activity act(*logger, Verbosity::Info, format("exporting path '%s'") % path); sink << 1; exportPath(path, sink); //logger->incProgress(doneLabel); @@ -85,7 +85,7 @@ StorePaths Store::importPaths(Source & source, std::shared_ptr acces ValidPathInfo info(parseStorePath(readString(source))); - //Activity act(*logger, lvlInfo, format("importing path '%s'") % info.path); + //Activity act(*logger, Verbosity::Info, format("importing path '%s'") % info.path); info.references = readStorePaths(*this, source); @@ -93,7 +93,7 @@ StorePaths Store::importPaths(Source & source, std::shared_ptr acces if (deriver != "") info.deriver = parseStorePath(deriver); - info.narHash = hashString(htSHA256, *tee.source.data); + info.narHash = hashString(HashType::SHA256, *tee.source.data); info.narSize = tee.source.data->size(); // Ignore optional legacy signature. diff --git a/src/libstore/gc.cc b/src/libstore/gc.cc index 0c3d89611..d201958f5 100644 --- a/src/libstore/gc.cc +++ b/src/libstore/gc.cc @@ -78,7 +78,7 @@ void LocalStore::syncWithGC() void LocalStore::addIndirectRoot(const Path & path) { - string hash = hashString(htSHA1, path).to_string(Base32, false); + string hash = hashString(HashType::SHA1, path).to_string(Base::Base32, false); Path realRoot = canonPath((format("%1%/%2%/auto/%3%") % stateDir % gcRootsDir % hash).str()); makeSymlink(realRoot, path); @@ -632,7 +632,7 @@ void LocalStore::tryToDelete(GCState & state, const Path & path) auto realPath = realStoreDir + "/" + std::string(baseNameOf(path)); if (realPath == linksDir || realPath == trashDir) return; - //Activity act(*logger, lvlDebug, format("considering whether to delete '%1%'") % path); + //Activity act(*logger, Verbosity::Debug, format("considering whether to delete '%1%'") % path); auto storePath = maybeParseStorePath(path); @@ -697,7 +697,7 @@ void LocalStore::removeUnusedLinks(const GCState & state) continue; } - printMsg(lvlTalkative, format("deleting unused link '%1%'") % path); + printMsg(Verbosity::Talkative, format("deleting unused link '%1%'") % path); if (unlink(path.c_str()) == -1) throw SysError(format("deleting '%1%'") % path); diff --git a/src/libstore/legacy-ssh-store.cc b/src/libstore/legacy-ssh-store.cc index 458266be0..f123efe01 100644 --- a/src/libstore/legacy-ssh-store.cc +++ b/src/libstore/legacy-ssh-store.cc @@ -139,7 +139,7 @@ struct LegacySSHStore : public Store << cmdAddToStoreNar << printStorePath(info.path) << (info.deriver ? printStorePath(*info.deriver) : "") - << info.narHash.to_string(Base16, false); + << info.narHash.to_string(Base::Base16, false); writeStorePaths(*this, conn->to, info.references); conn->to << info.registrationTime diff --git a/src/libstore/local-store.cc b/src/libstore/local-store.cc index ae7513ad8..f293ecb4a 100644 --- a/src/libstore/local-store.cc +++ b/src/libstore/local-store.cc @@ -580,7 +580,7 @@ uint64_t LocalStore::addValidPath(State & state, state.stmtRegisterValidPath.use() (printStorePath(info.path)) - (info.narHash.to_string(Base16)) + (info.narHash.to_string(Base::Base16)) (info.registrationTime == 0 ? time(0) : info.registrationTime) (info.deriver ? printStorePath(*info.deriver) : "", (bool) info.deriver) (info.narSize, info.narSize != 0) @@ -680,7 +680,7 @@ void LocalStore::updatePathInfo(State & state, const ValidPathInfo & info) { state.stmtUpdatePathInfo.use() (info.narSize, info.narSize != 0) - (info.narHash.to_string(Base16)) + (info.narHash.to_string(Base::Base16)) (info.ultimate ? 1 : 0, info.ultimate) (concatStringsSep(" ", info.sigs), !info.sigs.empty()) (info.ca, !info.ca.empty()) @@ -908,7 +908,7 @@ void LocalStore::registerValidPaths(const ValidPathInfos & infos) StorePathSet paths; for (auto & i : infos) { - assert(i.narHash.type == htSHA256); + assert(i.narHash.type == HashType::SHA256); if (isValidPath_(*state, i.path)) updatePathInfo(*state, i); else @@ -1006,9 +1006,9 @@ void LocalStore::addToStore(const ValidPathInfo & info, Source & source, of the NAR. */ std::unique_ptr hashSink; if (info.ca == "" || !info.references.count(info.path)) - hashSink = std::make_unique(htSHA256); + hashSink = std::make_unique(HashType::SHA256); else - hashSink = std::make_unique(htSHA256, storePathToHash(printStorePath(info.path))); + hashSink = std::make_unique(HashType::SHA256, storePathToHash(printStorePath(info.path))); LambdaSource wrapperSource([&](unsigned char * data, size_t len) -> size_t { size_t n = source.read(data, len); @@ -1081,10 +1081,10 @@ StorePath LocalStore::addToStoreFromDump(const string & dump, const string & nam sha256); otherwise, compute it here. */ HashResult hash; if (recursive) { - hash.first = hashAlgo == htSHA256 ? h : hashString(htSHA256, dump); + hash.first = hashAlgo == HashType::SHA256 ? h : hashString(HashType::SHA256, dump); hash.second = dump.size(); } else - hash = hashPath(htSHA256, realPath); + hash = hashPath(HashType::SHA256, realPath); optimisePath(realPath); // FIXME: combine with hashPath() @@ -1123,7 +1123,7 @@ StorePath LocalStore::addToStore(const string & name, const Path & _srcPath, StorePath LocalStore::addTextToStore(const string & name, const string & s, const StorePathSet & references, RepairFlag repair) { - auto hash = hashString(htSHA256, s); + auto hash = hashString(HashType::SHA256, s); auto dstPath = makeTextPath(name, hash, references); addTempRoot(dstPath); @@ -1147,7 +1147,7 @@ StorePath LocalStore::addTextToStore(const string & name, const string & s, StringSink sink; dumpString(s, sink); - auto narHash = hashString(htSHA256, *sink.s); + auto narHash = hashString(HashType::SHA256, *sink.s); optimisePath(realPath); @@ -1233,9 +1233,9 @@ bool LocalStore::verifyStore(bool checkContents, RepairFlag repair) printInfo("checking link hashes..."); for (auto & link : readDirectory(linksDir)) { - printMsg(lvlTalkative, "checking contents of '%s'", link.name); + printMsg(Verbosity::Talkative, "checking contents of '%s'", link.name); Path linkPath = linksDir + "/" + link.name; - string hash = hashPath(htSHA256, linkPath).first.to_string(Base32, false); + string hash = hashPath(HashType::SHA256, linkPath).first.to_string(Base::Base32, false); if (hash != link.name) { printError( "link '%s' was modified! expected hash '%s', got '%s'", @@ -1253,14 +1253,14 @@ bool LocalStore::verifyStore(bool checkContents, RepairFlag repair) printInfo("checking store hashes..."); - Hash nullHash(htSHA256); + Hash nullHash(HashType::SHA256); for (auto & i : validPaths) { try { auto info = std::const_pointer_cast(std::shared_ptr(queryPathInfo(i))); /* Check the content hash (optionally - slow). */ - printMsg(lvlTalkative, "checking contents of '%s'", printStorePath(i)); + printMsg(Verbosity::Talkative, "checking contents of '%s'", printStorePath(i)); std::unique_ptr hashSink; if (info->ca == "" || !info->references.count(info->path)) diff --git a/src/libstore/local-store.hh b/src/libstore/local-store.hh index 16aeab0ad..76bacd326 100644 --- a/src/libstore/local-store.hh +++ b/src/libstore/local-store.hh @@ -157,7 +157,7 @@ public: true) or simply the contents of a regular file (if recursive == false). */ StorePath addToStoreFromDump(const string & dump, const string & name, - bool recursive = true, HashType hashAlgo = htSHA256, RepairFlag repair = NoRepair) override; + bool recursive = true, HashType hashAlgo = HashType::SHA256, RepairFlag repair = NoRepair) override; StorePath addTextToStore(const string & name, const string & s, const StorePathSet & references, RepairFlag repair) override; diff --git a/src/libstore/misc.cc b/src/libstore/misc.cc index 9c47fe524..fb538a1c5 100644 --- a/src/libstore/misc.cc +++ b/src/libstore/misc.cc @@ -112,7 +112,7 @@ void Store::queryMissing(const std::vector & targets, StorePathSet & willBuild_, StorePathSet & willSubstitute_, StorePathSet & unknown_, unsigned long long & downloadSize_, unsigned long long & narSize_) { - Activity act(*logger, lvlDebug, actUnknown, "querying info about missing paths"); + Activity act(*logger, Verbosity::Debug, ActivityType::Unknown, "querying info about missing paths"); downloadSize_ = narSize_ = 0; diff --git a/src/libstore/nar-info.cc b/src/libstore/nar-info.cc index 1375094b5..a35886302 100644 --- a/src/libstore/nar-info.cc +++ b/src/libstore/nar-info.cc @@ -86,11 +86,11 @@ std::string NarInfo::to_string(const Store & store) const res += "URL: " + url + "\n"; assert(compression != ""); res += "Compression: " + compression + "\n"; - assert(fileHash.type == htSHA256); - res += "FileHash: " + fileHash.to_string(Base32) + "\n"; + assert(fileHash.type == HashType::SHA256); + res += "FileHash: " + fileHash.to_string(Base::Base32) + "\n"; res += "FileSize: " + std::to_string(fileSize) + "\n"; - assert(narHash.type == htSHA256); - res += "NarHash: " + narHash.to_string(Base32) + "\n"; + assert(narHash.type == HashType::SHA256); + res += "NarHash: " + narHash.to_string(Base::Base32) + "\n"; res += "NarSize: " + std::to_string(narSize) + "\n"; res += "References: " + concatStringsSep(" ", shortRefs()) + "\n"; diff --git a/src/libstore/optimise-store.cc b/src/libstore/optimise-store.cc index 8ac382e9d..5c01e1b3b 100644 --- a/src/libstore/optimise-store.cc +++ b/src/libstore/optimise-store.cc @@ -57,7 +57,7 @@ LocalStore::InodeHash LocalStore::loadInodeHash() } if (errno) throw SysError(format("reading directory '%1%'") % linksDir); - printMsg(lvlTalkative, format("loaded %1% hash inodes") % inodeHash.size()); + printMsg(Verbosity::Talkative, format("loaded %1% hash inodes") % inodeHash.size()); return inodeHash; } @@ -149,11 +149,11 @@ void LocalStore::optimisePath_(Activity * act, OptimiseStats & stats, Also note that if `path' is a symlink, then we're hashing the contents of the symlink (i.e. the result of readlink()), not the contents of the target (which may not even exist). */ - Hash hash = hashPath(htSHA256, path).first; + Hash hash = hashPath(HashType::SHA256, path).first; debug(format("'%1%' has hash '%2%'") % path % hash.to_string()); /* Check if this is a known hash. */ - Path linkPath = linksDir + "/" + hash.to_string(Base32, false); + Path linkPath = linksDir + "/" + hash.to_string(Base::Base32, false); retry: if (!pathExists(linkPath)) { @@ -199,7 +199,7 @@ void LocalStore::optimisePath_(Activity * act, OptimiseStats & stats, goto retry; } - printMsg(lvlTalkative, format("linking '%1%' to '%2%'") % path % linkPath); + printMsg(Verbosity::Talkative, format("linking '%1%' to '%2%'") % path % linkPath); /* Make the containing directory writable, but only if it's not the store itself (we don't want or need to mess with its @@ -246,13 +246,13 @@ void LocalStore::optimisePath_(Activity * act, OptimiseStats & stats, stats.blocksFreed += st.st_blocks; if (act) - act->result(resFileLinked, st.st_size, st.st_blocks); + act->result(ResultType::FileLinked, st.st_size, st.st_blocks); } void LocalStore::optimiseStore(OptimiseStats & stats) { - Activity act(*logger, actOptimiseStore); + Activity act(*logger, ActivityType::OptimiseStore); auto paths = queryAllValidPaths(); InodeHash inodeHash = loadInodeHash(); @@ -265,7 +265,7 @@ void LocalStore::optimiseStore(OptimiseStats & stats) addTempRoot(i); if (!isValidPath(i)) continue; /* path was GC'ed, probably */ { - Activity act(*logger, lvlTalkative, actUnknown, fmt("optimising path '%s'", printStorePath(i))); + Activity act(*logger, Verbosity::Talkative, ActivityType::Unknown, fmt("optimising path '%s'", printStorePath(i))); optimisePath_(&act, stats, realStoreDir + "/" + std::string(i.to_string()), inodeHash); } done++; diff --git a/src/libstore/references.cc b/src/libstore/references.cc index 102e15921..6652e1e26 100644 --- a/src/libstore/references.cc +++ b/src/libstore/references.cc @@ -54,7 +54,7 @@ struct RefScanSink : Sink string tail; - RefScanSink() : hashSink(htSHA256) { } + RefScanSink() : hashSink(HashType::SHA256) { } void operator () (const unsigned char * data, size_t len); }; @@ -96,7 +96,7 @@ PathSet scanForReferences(const string & path, string s = string(baseName, 0, pos); assert(s.size() == refLength); assert(backMap.find(s) == backMap.end()); - // parseHash(htSHA256, s); + // parseHash(HashType::SHA256, s); sink.hashes.insert(s); backMap[s] = i; } diff --git a/src/libstore/remote-store.cc b/src/libstore/remote-store.cc index 8c55da268..3fc7ddfc0 100644 --- a/src/libstore/remote-store.cc +++ b/src/libstore/remote-store.cc @@ -177,11 +177,11 @@ void RemoteStore::setOptions(Connection & conn) << settings.keepFailed << settings.keepGoing << settings.tryFallback - << verbosity + << (uint64_t) verbosity << settings.maxBuildJobs << settings.maxSilentTime << true - << (settings.verboseBuild ? lvlError : lvlVomit) + << (uint64_t) (settings.verboseBuild ? Verbosity::Error : Verbosity::Vomit) << 0 // obsolete log type << 0 /* obsolete print build trace */ << settings.buildCores @@ -375,7 +375,7 @@ void RemoteStore::queryPathInfoUncached(const StorePath & path, info = std::make_shared(path.clone()); auto deriver = readString(conn->from); if (deriver != "") info->deriver = parseStorePath(deriver); - info->narHash = Hash(readString(conn->from), htSHA256); + info->narHash = Hash(readString(conn->from), HashType::SHA256); info->references = readStorePaths(*this, conn->from); conn->from >> info->registrationTime >> info->narSize; if (GET_PROTOCOL_MINOR(conn->daemonVersion) >= 16) { @@ -471,7 +471,7 @@ void RemoteStore::addToStore(const ValidPathInfo & info, Source & source, conn->to << wopAddToStoreNar << printStorePath(info.path) << (info.deriver ? printStorePath(*info.deriver) : "") - << info.narHash.to_string(Base16, false); + << info.narHash.to_string(Base::Base16, false); writeStorePaths(*this, conn->to, info.references); conn->to << info.registrationTime << info.narSize << info.ultimate << info.sigs << info.ca @@ -493,7 +493,7 @@ StorePath RemoteStore::addToStore(const string & name, const Path & _srcPath, Path srcPath(absPath(_srcPath)); conn->to << wopAddToStore << name - << ((hashAlgo == htSHA256 && recursive) ? 0 : 1) /* backwards compatibility hack */ + << ((hashAlgo == HashType::SHA256 && recursive) ? 0 : 1) /* backwards compatibility hack */ << (recursive ? 1 : 0) << printHashType(hashAlgo); diff --git a/src/libstore/remote-store.hh b/src/libstore/remote-store.hh index f301a97d8..62cff8e3f 100644 --- a/src/libstore/remote-store.hh +++ b/src/libstore/remote-store.hh @@ -65,7 +65,7 @@ public: std::shared_ptr accessor) override; StorePath addToStore(const string & name, const Path & srcPath, - bool recursive = true, HashType hashAlgo = htSHA256, + bool recursive = true, HashType hashAlgo = HashType::SHA256, PathFilter & filter = defaultPathFilter, RepairFlag repair = NoRepair) override; StorePath addTextToStore(const string & name, const string & s, diff --git a/src/libstore/s3-binary-cache-store.cc b/src/libstore/s3-binary-cache-store.cc index f2e4b63e0..fb56ee62e 100644 --- a/src/libstore/s3-binary-cache-store.cc +++ b/src/libstore/s3-binary-cache-store.cc @@ -68,9 +68,9 @@ static void initAWS() shared.cc), so don't let aws-sdk-cpp override it. */ options.cryptoOptions.initAndCleanupOpenSSL = false; - if (verbosity >= lvlDebug) { + if (verbosity >= Verbosity::Debug) { options.loggingOptions.logLevel = - verbosity == lvlDebug + verbosity == Verbosity::Debug ? Aws::Utils::Logging::LogLevel::Debug : Aws::Utils::Logging::LogLevel::Trace; options.loggingOptions.logger_create_fn = [options]() { diff --git a/src/libstore/ssh.cc b/src/libstore/ssh.cc index 84548a6e4..f61c094a2 100644 --- a/src/libstore/ssh.cc +++ b/src/libstore/ssh.cc @@ -58,7 +58,7 @@ std::unique_ptr SSHMaster::startCommand(const std::string addCommonSSHOpts(args); if (socketPath != "") args.insert(args.end(), {"-S", socketPath}); - if (verbosity >= lvlChatty) + if (verbosity >= Verbosity::Chatty) args.push_back("-v"); } @@ -110,7 +110,7 @@ Path SSHMaster::startMaster() , "-o", "LocalCommand=echo started" , "-o", "PermitLocalCommand=yes" }; - if (verbosity >= lvlChatty) + if (verbosity >= Verbosity::Chatty) args.push_back("-v"); addCommonSSHOpts(args); execvp(args.begin()->c_str(), stringsToCharPtrs(args).data()); diff --git a/src/libstore/store-api.cc b/src/libstore/store-api.cc index b9e894a9a..98475fd4c 100644 --- a/src/libstore/store-api.cc +++ b/src/libstore/store-api.cc @@ -141,8 +141,8 @@ StorePath Store::makeStorePath(const string & type, const Hash & hash, std::string_view name) const { /* e.g., "source:sha256:1abc...:/nix/store:foo.tar.gz" */ - string s = type + ":" + hash.to_string(Base16) + ":" + storeDir + ":" + std::string(name); - auto h = compressHash(hashString(htSHA256, s), 20); + string s = type + ":" + hash.to_string(Base::Base16) + ":" + storeDir + ":" + std::string(name); + auto h = compressHash(hashString(HashType::SHA256, s), 20); return StorePath::make(h.hash, name); } @@ -177,13 +177,13 @@ StorePath Store::makeFixedOutputPath( const StorePathSet & references, bool hasSelfReference) const { - if (hash.type == htSHA256 && recursive) { + if (hash.type == HashType::SHA256 && recursive) { return makeStorePath(makeType(*this, "source", references, hasSelfReference), hash, name); } else { assert(references.empty()); - return makeStorePath("output:out", hashString(htSHA256, + return makeStorePath("output:out", hashString(HashType::SHA256, "fixed:out:" + (recursive ? (string) "r:" : "") + - hash.to_string(Base16) + ":"), name); + hash.to_string(Base::Base16) + ":"), name); } } @@ -191,7 +191,7 @@ StorePath Store::makeFixedOutputPath( StorePath Store::makeTextPath(std::string_view name, const Hash & hash, const StorePathSet & references) const { - assert(hash.type == htSHA256); + assert(hash.type == HashType::SHA256); /* Stuff the references (if any) into the type. This is a bit hacky, but we can't put them in `s' since that would be ambiguous. */ @@ -210,7 +210,7 @@ std::pair Store::computeStorePathForPath(std::string_view name, StorePath Store::computeStorePathForText(const string & name, const string & s, const StorePathSet & references) const { - return makeTextPath(name, hashString(htSHA256, s), references); + return makeTextPath(name, hashString(HashType::SHA256, s), references); } @@ -423,7 +423,7 @@ string Store::makeValidityRegistration(const StorePathSet & paths, auto info = queryPathInfo(i); if (showHash) { - s += info->narHash.to_string(Base16, false) + "\n"; + s += info->narHash.to_string(Base::Base16, false) + "\n"; s += (format("%1%\n") % info->narSize).str(); } @@ -561,7 +561,7 @@ void copyStorePath(ref srcStore, ref dstStore, auto srcUri = srcStore->getUri(); auto dstUri = dstStore->getUri(); - Activity act(*logger, lvlInfo, actCopyPath, + Activity act(*logger, Verbosity::Info, ActivityType::CopyPath, srcUri == "local" || srcUri == "daemon" ? fmt("copying path '%s' to '%s'", srcStore->printStorePath(storePath), dstUri) : dstUri == "local" || dstUri == "daemon" @@ -578,7 +578,7 @@ void copyStorePath(ref srcStore, ref dstStore, StringSink sink; srcStore->narFromPath({storePath}, sink); auto info2 = make_ref(*info); - info2->narHash = hashString(htSHA256, *sink.s); + info2->narHash = hashString(HashType::SHA256, *sink.s); if (!info->narSize) info2->narSize = sink.s->size(); if (info->ultimate) info2->ultimate = false; info = info2; @@ -620,7 +620,7 @@ void copyPaths(ref srcStore, ref dstStore, const StorePathSet & st if (missing.empty()) return; - Activity act(*logger, lvlInfo, actCopyPaths, fmt("copying %d paths", missing.size())); + Activity act(*logger, Verbosity::Info, ActivityType::CopyPaths, fmt("copying %d paths", missing.size())); std::atomic nrDone{0}; std::atomic nrFailed{0}; @@ -646,7 +646,7 @@ void copyPaths(ref srcStore, ref dstStore, const StorePathSet & st auto info = srcStore->queryPathInfo(srcStore->parseStorePath(storePath)); bytesExpected += info->narSize; - act.setExpected(actCopyPath, bytesExpected); + act.setExpected(ActivityType::CopyPath, bytesExpected); return srcStore->printStorePathSet(info->references); }, @@ -665,7 +665,7 @@ void copyPaths(ref srcStore, ref dstStore, const StorePathSet & st nrFailed++; if (!settings.keepGoing) throw e; - logger->log(lvlError, fmt("could not copy %s: %s", storePathS, e.what())); + logger->log(Verbosity::Error, fmt("could not copy %s: %s", storePathS, e.what())); showProgress(); return; } @@ -711,7 +711,7 @@ std::optional decodeValidPathInfo(const Store & store, std::istre if (hashGiven) { string s; getline(str, s); - info.narHash = Hash(s, htSHA256); + info.narHash = Hash(s, HashType::SHA256); getline(str, s); if (!string2Int(s, info.narSize)) throw Error("number expected"); } @@ -754,7 +754,7 @@ std::string ValidPathInfo::fingerprint(const Store & store) const store.printStorePath(path)); return "1;" + store.printStorePath(path) + ";" - + narHash.to_string(Base32) + ";" + + narHash.to_string(Base::Base32) + ";" + std::to_string(narSize) + ";" + concatStringsSep(",", store.printStorePathSet(references)); } diff --git a/src/libstore/store-api.hh b/src/libstore/store-api.hh index 0fa59be6a..4247367b5 100644 --- a/src/libstore/store-api.hh +++ b/src/libstore/store-api.hh @@ -359,7 +359,7 @@ public: path and the cryptographic hash of the contents of srcPath. */ std::pair computeStorePathForPath(std::string_view name, const Path & srcPath, bool recursive = true, - HashType hashAlgo = htSHA256, PathFilter & filter = defaultPathFilter) const; + HashType hashAlgo = HashType::SHA256, PathFilter & filter = defaultPathFilter) const; /* Preparatory part of addTextToStore(). @@ -462,12 +462,12 @@ public: The function object `filter' can be used to exclude files (see libutil/archive.hh). */ virtual StorePath addToStore(const string & name, const Path & srcPath, - bool recursive = true, HashType hashAlgo = htSHA256, + bool recursive = true, HashType hashAlgo = HashType::SHA256, PathFilter & filter = defaultPathFilter, RepairFlag repair = NoRepair) = 0; // FIXME: remove? virtual StorePath addToStoreFromDump(const string & dump, const string & name, - bool recursive = true, HashType hashAlgo = htSHA256, RepairFlag repair = NoRepair) + bool recursive = true, HashType hashAlgo = HashType::SHA256, RepairFlag repair = NoRepair) { throw Error("addToStoreFromDump() is not supported by this store"); } @@ -561,7 +561,7 @@ public: each path is included. */ void pathInfoToJSON(JSONPlaceholder & jsonOut, const StorePathSet & storePaths, bool includeImpureInfo, bool showClosureSize, - Base hashBase = Base32, + Base hashBase = Base::Base32, AllowInvalidFlag allowInvalid = DisallowInvalid); /* Return the size of the closure of the specified path, that is, diff --git a/src/libutil/args.cc b/src/libutil/args.cc index ba15ea571..8fd437f26 100644 --- a/src/libutil/args.cc +++ b/src/libutil/args.cc @@ -164,7 +164,7 @@ Args::FlagMaker & Args::FlagMaker::mkHashTypeFlag(HashType * ht) description("hash algorithm ('md5', 'sha1', 'sha256', or 'sha512')"); handler([ht](std::string s) { *ht = parseHashType(s); - if (*ht == htUnknown) + if (*ht == HashType::Unknown) throw UsageError("unknown hash type '%1%'", s); }); return *this; diff --git a/src/libutil/args.hh b/src/libutil/args.hh index 967efbe1c..afa493663 100644 --- a/src/libutil/args.hh +++ b/src/libutil/args.hh @@ -10,7 +10,7 @@ namespace nix { MakeError(UsageError, Error); -enum HashType : char; +enum struct HashType : char; class Args { diff --git a/src/libutil/compression.cc b/src/libutil/compression.cc index 860b04adb..75e889f41 100644 --- a/src/libutil/compression.cc +++ b/src/libutil/compression.cc @@ -314,7 +314,7 @@ struct XzCompressionSink : CompressionSink ret = lzma_stream_encoder_mt(&strm, &mt_options); done = true; #else - printMsg(lvlError, "warning: parallel XZ compression requested but not supported, falling back to single-threaded compression"); + printMsg(Verbosity::Error, "warning: parallel XZ compression requested but not supported, falling back to single-threaded compression"); #endif } diff --git a/src/libutil/hash.cc b/src/libutil/hash.cc index 7caee1da7..5e6edeec3 100644 --- a/src/libutil/hash.cc +++ b/src/libutil/hash.cc @@ -18,10 +18,10 @@ namespace nix { void Hash::init() { - if (type == htMD5) hashSize = md5HashSize; - else if (type == htSHA1) hashSize = sha1HashSize; - else if (type == htSHA256) hashSize = sha256HashSize; - else if (type == htSHA512) hashSize = sha512HashSize; + if (type == HashType::MD5) hashSize = md5HashSize; + else if (type == HashType::SHA1) hashSize = sha1HashSize; + else if (type == HashType::SHA256) hashSize = sha256HashSize; + else if (type == HashType::SHA512) hashSize = sha512HashSize; else abort(); assert(hashSize <= maxHashSize); memset(hash, 0, maxHashSize); @@ -98,26 +98,26 @@ static string printHash32(const Hash & hash) string printHash16or32(const Hash & hash) { - return hash.to_string(hash.type == htMD5 ? Base16 : Base32, false); + return hash.to_string(hash.type == HashType::MD5 ? Base::Base16 : Base::Base32, false); } std::string Hash::to_string(Base base, bool includeType) const { std::string s; - if (base == SRI || includeType) { + if (base == Base::SRI || includeType) { s += printHashType(type); - s += base == SRI ? '-' : ':'; + s += base == Base::SRI ? '-' : ':'; } switch (base) { - case Base16: + case Base::Base16: s += printHash16(*this); break; - case Base32: + case Base::Base32: s += printHash32(*this); break; - case Base64: - case SRI: + case Base::Base64: + case Base::SRI: s += base64Encode(std::string((const char *) hash, hashSize)); break; } @@ -136,16 +136,16 @@ Hash::Hash(const std::string & s, HashType type) sep = s.find('-'); if (sep != string::npos) { isSRI = true; - } else if (type == htUnknown) + } else if (type == HashType::Unknown) throw BadHash("hash '%s' does not include a type", s); } if (sep != string::npos) { string hts = string(s, 0, sep); this->type = parseHashType(hts); - if (this->type == htUnknown) + if (this->type == HashType::Unknown) throw BadHash("unknown hash type '%s'", hts); - if (type != htUnknown && type != this->type) + if (type != HashType::Unknown && type != this->type) throw BadHash("hash '%s' should have type '%s'", s, printHashType(type)); pos = sep + 1; } @@ -217,29 +217,29 @@ union Ctx static void start(HashType ht, Ctx & ctx) { - if (ht == htMD5) MD5_Init(&ctx.md5); - else if (ht == htSHA1) SHA1_Init(&ctx.sha1); - else if (ht == htSHA256) SHA256_Init(&ctx.sha256); - else if (ht == htSHA512) SHA512_Init(&ctx.sha512); + if (ht == HashType::MD5) MD5_Init(&ctx.md5); + else if (ht == HashType::SHA1) SHA1_Init(&ctx.sha1); + else if (ht == HashType::SHA256) SHA256_Init(&ctx.sha256); + else if (ht == HashType::SHA512) SHA512_Init(&ctx.sha512); } static void update(HashType ht, Ctx & ctx, const unsigned char * bytes, size_t len) { - if (ht == htMD5) MD5_Update(&ctx.md5, bytes, len); - else if (ht == htSHA1) SHA1_Update(&ctx.sha1, bytes, len); - else if (ht == htSHA256) SHA256_Update(&ctx.sha256, bytes, len); - else if (ht == htSHA512) SHA512_Update(&ctx.sha512, bytes, len); + if (ht == HashType::MD5) MD5_Update(&ctx.md5, bytes, len); + else if (ht == HashType::SHA1) SHA1_Update(&ctx.sha1, bytes, len); + else if (ht == HashType::SHA256) SHA256_Update(&ctx.sha256, bytes, len); + else if (ht == HashType::SHA512) SHA512_Update(&ctx.sha512, bytes, len); } static void finish(HashType ht, Ctx & ctx, unsigned char * hash) { - if (ht == htMD5) MD5_Final(hash, &ctx.md5); - else if (ht == htSHA1) SHA1_Final(hash, &ctx.sha1); - else if (ht == htSHA256) SHA256_Final(hash, &ctx.sha256); - else if (ht == htSHA512) SHA512_Final(hash, &ctx.sha512); + if (ht == HashType::MD5) MD5_Final(hash, &ctx.md5); + else if (ht == HashType::SHA1) SHA1_Final(hash, &ctx.sha1); + else if (ht == HashType::SHA256) SHA256_Final(hash, &ctx.sha256); + else if (ht == HashType::SHA512) SHA512_Final(hash, &ctx.sha512); } @@ -320,20 +320,20 @@ Hash compressHash(const Hash & hash, unsigned int newSize) HashType parseHashType(const string & s) { - if (s == "md5") return htMD5; - else if (s == "sha1") return htSHA1; - else if (s == "sha256") return htSHA256; - else if (s == "sha512") return htSHA512; - else return htUnknown; + if (s == "md5") return HashType::MD5; + else if (s == "sha1") return HashType::SHA1; + else if (s == "sha256") return HashType::SHA256; + else if (s == "sha512") return HashType::SHA512; + else return HashType::Unknown; } string printHashType(HashType ht) { - if (ht == htMD5) return "md5"; - else if (ht == htSHA1) return "sha1"; - else if (ht == htSHA256) return "sha256"; - else if (ht == htSHA512) return "sha512"; + if (ht == HashType::MD5) return "md5"; + else if (ht == HashType::SHA1) return "sha1"; + else if (ht == HashType::SHA256) return "sha256"; + else if (ht == HashType::SHA512) return "sha512"; else abort(); } diff --git a/src/libutil/hash.hh b/src/libutil/hash.hh index ea9fca3e7..0fe6e7677 100644 --- a/src/libutil/hash.hh +++ b/src/libutil/hash.hh @@ -10,7 +10,13 @@ namespace nix { MakeError(BadHash, Error); -enum HashType : char { htUnknown, htMD5, htSHA1, htSHA256, htSHA512 }; +enum struct HashType : char { + Unknown, + MD5, + SHA1, + SHA256, + SHA512, +}; const int md5HashSize = 16; @@ -20,7 +26,12 @@ const int sha512HashSize = 64; extern const string base32Chars; -enum Base : int { Base64, Base32, Base16, SRI }; +enum struct Base : int { + Base64, + Base32, + Base16, + SRI, +}; struct Hash @@ -29,7 +40,7 @@ struct Hash unsigned int hashSize = 0; unsigned char hash[maxHashSize] = {}; - HashType type = htUnknown; + HashType type = HashType::Unknown; /* Create an unset hash object. */ Hash() { }; @@ -40,14 +51,14 @@ struct Hash /* Initialize the hash from a string representation, in the format "[:]" or "-" (a Subresource Integrity hash expression). If the 'type' argument - is htUnknown, then the hash type must be specified in the + is HashType::Unknown, then the hash type must be specified in the string. */ - Hash(const std::string & s, HashType type = htUnknown); + Hash(const std::string & s, HashType type = HashType::Unknown); void init(); /* Check whether a hash is set. */ - operator bool () const { return type != htUnknown; } + operator bool () const { return type != HashType::Unknown; } /* Check whether two hash are equal. */ bool operator == (const Hash & h2) const; @@ -79,18 +90,18 @@ struct Hash /* Return a string representation of the hash, in base-16, base-32 or base-64. By default, this is prefixed by the hash type (e.g. "sha256:"). */ - std::string to_string(Base base = Base32, bool includeType = true) const; + std::string to_string(Base base = Base::Base32, bool includeType = true) const; std::string gitRev() const { - assert(type == htSHA1); - return to_string(Base16, false); + assert(type == HashType::SHA1); + return to_string(Base::Base16, false); } std::string gitShortRev() const { - assert(type == htSHA1); - return std::string(to_string(Base16, false), 0, 7); + assert(type == HashType::SHA1); + return std::string(to_string(Base::Base16, false), 0, 7); } }; diff --git a/src/libutil/logging.cc b/src/libutil/logging.cc index fa5c84a27..54c73a913 100644 --- a/src/libutil/logging.cc +++ b/src/libutil/logging.cc @@ -21,7 +21,7 @@ Logger * logger = makeDefaultLogger(); void Logger::warn(const std::string & msg) { - log(lvlWarn, ANSI_YELLOW "warning:" ANSI_NORMAL " " + msg); + log(Verbosity::Warn, ANSI_YELLOW "warning:" ANSI_NORMAL " " + msg); } class SimpleLogger : public Logger @@ -45,10 +45,10 @@ public: if (systemd) { char c; switch (lvl) { - case lvlError: c = '3'; break; - case lvlWarn: c = '4'; break; - case lvlInfo: c = '5'; break; - case lvlTalkative: case lvlChatty: c = '6'; break; + case Verbosity::Error: c = '3'; break; + case Verbosity::Warn: c = '4'; break; + case Verbosity::Info: c = '5'; break; + case Verbosity::Talkative: case Verbosity::Chatty: c = '6'; break; default: c = '7'; } prefix = std::string("<") + c + ">"; @@ -66,7 +66,7 @@ public: } }; -Verbosity verbosity = lvlInfo; +Verbosity verbosity = Verbosity::Info; void warnOnce(bool & haveWarned, const FormatOrString & fs) { @@ -123,7 +123,7 @@ struct JSONLogger : Logger void write(const nlohmann::json & json) { - prevLogger.log(lvlError, "@nix " + json.dump()); + prevLogger.log(Verbosity::Error, "@nix " + json.dump()); } void log(Verbosity lvl, const FormatOrString & fs) override @@ -198,7 +198,7 @@ bool handleJSONLogMessage(const std::string & msg, if (action == "start") { auto type = (ActivityType) json["type"]; - if (trusted || type == actDownload) + if (trusted || type == ActivityType::Download) activities.emplace(std::piecewise_construct, std::forward_as_tuple(json["id"]), std::forward_as_tuple(*logger, (Verbosity) json["level"], type, @@ -216,7 +216,7 @@ bool handleJSONLogMessage(const std::string & msg, else if (action == "setPhase") { std::string phase = json["phase"]; - act.result(resSetPhase, phase); + act.result(ResultType::SetPhase, phase); } else if (action == "msg") { diff --git a/src/libutil/logging.hh b/src/libutil/logging.hh index beb5e6b64..cde525358 100644 --- a/src/libutil/logging.hh +++ b/src/libutil/logging.hh @@ -4,41 +4,41 @@ namespace nix { -typedef enum { - lvlError = 0, - lvlWarn, - lvlInfo, - lvlTalkative, - lvlChatty, - lvlDebug, - lvlVomit -} Verbosity; - -typedef enum { - actUnknown = 0, - actCopyPath = 100, - actDownload = 101, - actRealise = 102, - actCopyPaths = 103, - actBuilds = 104, - actBuild = 105, - actOptimiseStore = 106, - actVerifyPaths = 107, - actSubstitute = 108, - actQueryPathInfo = 109, - actPostBuildHook = 110, -} ActivityType; - -typedef enum { - resFileLinked = 100, - resBuildLogLine = 101, - resUntrustedPath = 102, - resCorruptedPath = 103, - resSetPhase = 104, - resProgress = 105, - resSetExpected = 106, - resPostBuildLogLine = 107, -} ResultType; +enum struct Verbosity : uint64_t { + Error = 0, + Warn, + Info, + Talkative, + Chatty, + Debug, + Vomit, +}; + +enum struct ActivityType : uint64_t { + Unknown = 0, + CopyPath = 100, + Download = 101, + Realise = 102, + CopyPaths = 103, + Builds = 104, + Build = 105, + OptimiseStore = 106, + VerifyPaths = 107, + Substitute = 108, + QueryPathInfo = 109, + PostBuildHook = 110, +}; + +enum struct ResultType : uint64_t { + FileLinked = 100, + BuildLogLine = 101, + UntrustedPath = 102, + CorruptedPath = 103, + SetPhase = 104, + Progress = 105, + SetExpected = 106, + PostBuildLogLine = 107, +}; typedef uint64_t ActivityId; @@ -67,7 +67,7 @@ public: void log(const FormatOrString & fs) { - log(lvlInfo, fs); + log(Verbosity::Info, fs); } virtual void warn(const std::string & msg); @@ -94,17 +94,17 @@ struct Activity Activity(Logger & logger, ActivityType type, const Logger::Fields & fields = {}, ActivityId parent = getCurActivity()) - : Activity(logger, lvlError, type, "", fields, parent) { }; + : Activity(logger, Verbosity::Error, type, "", fields, parent) { }; Activity(const Activity & act) = delete; ~Activity(); void progress(uint64_t done = 0, uint64_t expected = 0, uint64_t running = 0, uint64_t failed = 0) const - { result(resProgress, done, expected, running, failed); } + { result(ResultType::Progress, done, expected, running, failed); } void setExpected(ActivityType type2, uint64_t expected) const - { result(resSetExpected, type2, expected); } + { result(ResultType::SetExpected, (uint64_t)type2, expected); } template void result(ResultType type, const Args & ... args) const @@ -151,11 +151,11 @@ extern Verbosity verbosity; /* suppress msgs > this */ } \ } while (0) -#define printError(args...) printMsg(lvlError, args) -#define printInfo(args...) printMsg(lvlInfo, args) -#define printTalkative(args...) printMsg(lvlTalkative, args) -#define debug(args...) printMsg(lvlDebug, args) -#define vomit(args...) printMsg(lvlVomit, args) +#define printError(args...) printMsg(Verbosity::Error, args) +#define printInfo(args...) printMsg(Verbosity::Info, args) +#define printTalkative(args...) printMsg(Verbosity::Talkative, args) +#define debug(args...) printMsg(Verbosity::Debug, args) +#define vomit(args...) printMsg(Verbosity::Vomit, args) template inline void warn(const std::string & fs, const Args & ... args) diff --git a/src/libutil/util.cc b/src/libutil/util.cc index 097ff210a..8cabbb503 100644 --- a/src/libutil/util.cc +++ b/src/libutil/util.cc @@ -430,7 +430,7 @@ void deletePath(const Path & path) void deletePath(const Path & path, unsigned long long & bytesFreed) { - //Activity act(*logger, lvlDebug, format("recursively deleting path '%1%'") % path); + //Activity act(*logger, Verbosity::Debug, format("recursively deleting path '%1%'") % path); bytesFreed = 0; _deletePath(path, bytesFreed); } @@ -1410,7 +1410,7 @@ string base64Decode(const string & s) char digit = decode[(unsigned char) c]; if (digit == -1) - throw Error("invalid character in Base64 string"); + throw Error("invalid character in Base::Base64 string"); bits += 6; d = d << 6 | digit; diff --git a/src/libutil/util.hh b/src/libutil/util.hh index 7c3a30242..e04ce3701 100644 --- a/src/libutil/util.hh +++ b/src/libutil/util.hh @@ -468,7 +468,7 @@ std::string filterANSIEscapes(const std::string & s, unsigned int width = std::numeric_limits::max()); -/* Base64 encoding/decoding. */ +/* Base::Base64 encoding/decoding. */ string base64Encode(const string & s); string base64Decode(const string & s); diff --git a/src/nix-copy-closure/nix-copy-closure.cc b/src/nix-copy-closure/nix-copy-closure.cc index f87035760..74ab03b6f 100755 --- a/src/nix-copy-closure/nix-copy-closure.cc +++ b/src/nix-copy-closure/nix-copy-closure.cc @@ -22,7 +22,7 @@ static int _main(int argc, char ** argv) printVersion("nix-copy-closure"); else if (*arg == "--gzip" || *arg == "--bzip2" || *arg == "--xz") { if (*arg != "--gzip") - printMsg(lvlError, format("Warning: '%1%' is not implemented, falling back to gzip") % *arg); + printMsg(Verbosity::Error, format("Warning: '%1%' is not implemented, falling back to gzip") % *arg); gzip = true; } else if (*arg == "--from") toMode = false; @@ -31,7 +31,7 @@ static int _main(int argc, char ** argv) else if (*arg == "--include-outputs") includeOutputs = true; else if (*arg == "--show-progress") - printMsg(lvlError, "Warning: '--show-progress' is not implemented"); + printMsg(Verbosity::Error, "Warning: '--show-progress' is not implemented"); else if (*arg == "--dry-run") dryRun = true; else if (*arg == "--use-substitutes" || *arg == "-s") diff --git a/src/nix-env/nix-env.cc b/src/nix-env/nix-env.cc index e47b00acf..4d8537705 100644 --- a/src/nix-env/nix-env.cc +++ b/src/nix-env/nix-env.cc @@ -961,7 +961,7 @@ static void opQuery(Globals & globals, Strings opFlags, Strings opArgs) try { paths.insert(globals.state->store->parseStorePath(i.queryOutPath())); } catch (AssertionError & e) { - printMsg(lvlTalkative, "skipping derivation named '%s' which gives an assertion failure", i.queryName()); + printMsg(Verbosity::Talkative, "skipping derivation named '%s' which gives an assertion failure", i.queryName()); i.setFailed(); } validPaths = globals.state->store->queryValidPaths(paths); @@ -987,7 +987,7 @@ static void opQuery(Globals & globals, Strings opFlags, Strings opArgs) try { if (i.hasFailed()) continue; - //Activity act(*logger, lvlDebug, format("outputting query result '%1%'") % i.attrPath); + //Activity act(*logger, Verbosity::Debug, format("outputting query result '%1%'") % i.attrPath); if (globals.prebuiltOnly && !validPaths.count(globals.state->store->parseStorePath(i.queryOutPath())) && @@ -1163,7 +1163,7 @@ static void opQuery(Globals & globals, Strings opFlags, Strings opArgs) cout.flush(); } catch (AssertionError & e) { - printMsg(lvlTalkative, "skipping derivation named '%1%' which gives an assertion failure", i.queryName()); + printMsg(Verbosity::Talkative, "skipping derivation named '%1%' which gives an assertion failure", i.queryName()); } catch (Error & e) { e.addPrefix(fmt("while querying the derivation named '%1%':\n", i.queryName())); throw; diff --git a/src/nix-prefetch-url/nix-prefetch-url.cc b/src/nix-prefetch-url/nix-prefetch-url.cc index 18ced94b1..750ac2327 100644 --- a/src/nix-prefetch-url/nix-prefetch-url.cc +++ b/src/nix-prefetch-url/nix-prefetch-url.cc @@ -51,7 +51,7 @@ string resolveMirrorUri(EvalState & state, string uri) static int _main(int argc, char * * argv) { { - HashType ht = htSHA256; + HashType ht = HashType::SHA256; std::vector args; bool printPath = getEnv("PRINT_PATH") == "1"; bool fromExpr = false; @@ -72,7 +72,7 @@ static int _main(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 == "--print-path") diff --git a/src/nix-store/nix-store.cc b/src/nix-store/nix-store.cc index 806ab7563..454f3e775 100644 --- a/src/nix-store/nix-store.cc +++ b/src/nix-store/nix-store.cc @@ -372,8 +372,8 @@ static void opQuery(Strings opFlags, Strings opArgs) for (auto & j : maybeUseOutputs(store->followLinksToStorePath(i), useOutput, forceRealise)) { auto info = store->queryPathInfo(j); if (query == qHash) { - assert(info->narHash.type == htSHA256); - cout << fmt("%s\n", info->narHash.to_string(Base32)); + assert(info->narHash.type == HashType::SHA256); + cout << fmt("%s\n", info->narHash.to_string(Base::Base32)); } else if (query == qSize) cout << fmt("%d\n", info->narSize); } @@ -502,7 +502,7 @@ static void registerValidity(bool reregister, bool hashGiven, bool canonicalise) if (canonicalise) canonicalisePathMetaData(store->printStorePath(info->path), -1); if (!hashGiven) { - HashResult hash = hashPath(htSHA256, store->printStorePath(info->path)); + HashResult hash = hashPath(HashType::SHA256, store->printStorePath(info->path)); info->narHash = hash.first; info->narSize = hash.second; } @@ -720,7 +720,7 @@ static void opVerifyPath(Strings opFlags, Strings opArgs) for (auto & i : opArgs) { auto path = store->followLinksToStorePath(i); - printMsg(lvlTalkative, "checking path '%s'...", store->printStorePath(path)); + printMsg(Verbosity::Talkative, "checking path '%s'...", store->printStorePath(path)); auto info = store->queryPathInfo(path); HashSink sink(info->narHash.type); store->narFromPath(path, sink); @@ -781,7 +781,7 @@ static void opServe(Strings opFlags, Strings opArgs) auto getBuildSettings = [&]() { // FIXME: changing options here doesn't work if we're // building through the daemon. - verbosity = lvlError; + verbosity = Verbosity::Error; settings.keepLog = false; settings.useSubstitutes = false; settings.maxSilentTime = readInt(in); @@ -940,7 +940,7 @@ static void opServe(Strings opFlags, Strings opArgs) auto deriver = readString(in); if (deriver != "") info.deriver = store->parseStorePath(deriver); - info.narHash = Hash(readString(in), htSHA256); + info.narHash = Hash(readString(in), HashType::SHA256); info.references = readStorePaths(*store, in); in >> info.registrationTime >> info.narSize >> info.ultimate; info.sigs = readStrings(in); 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 832bd534dc0ab36fd8267f62b67ab1db1498d2b4 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Sun, 22 Mar 2020 23:43:07 -0400 Subject: Store parsed hashes in `DerivationOutput` It's best to detect invalid data as soon as possible, with data types that make storing it impossible. --- src/libexpr/primops.cc | 10 ++--- src/libstore/build.cc | 19 ++++----- src/libstore/derivations.cc | 99 ++++++++++++++++++++++++++++++--------------- src/libstore/derivations.hh | 21 +++++++--- src/libstore/local-store.cc | 10 +++-- src/libstore/store-api.cc | 23 ++++++++--- src/libstore/store-api.hh | 3 ++ src/nix/show-derivation.cc | 6 +-- 8 files changed, 128 insertions(+), 63 deletions(-) diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc index 7d45733f4..df0ef4e4e 100644 --- a/src/libexpr/primops.cc +++ b/src/libexpr/primops.cc @@ -724,9 +724,9 @@ static void prim_derivationStrict(EvalState & state, const Pos & pos, Value * * auto outPath = state.store->makeFixedOutputPath(outputHashRecursive, h, drvName); if (!jsonObject) drv.env["out"] = state.store->printStorePath(outPath); - drv.outputs.insert_or_assign("out", DerivationOutput(std::move(outPath), - (static_cast(outputHashRecursive) ? "r:" : "") + printHashType(h.type), - h.to_string(Base16, false))); + drv.outputs.insert_or_assign("out", DerivationOutput( + std::move(outPath), + FileSystemHash(outputHashRecursive, std::move(h)))); } else { @@ -739,7 +739,7 @@ static void prim_derivationStrict(EvalState & state, const Pos & pos, Value * * for (auto & i : outputs) { if (!jsonObject) drv.env[i] = ""; drv.outputs.insert_or_assign(i, - DerivationOutput(StorePath::dummy.clone(), "", "")); + DerivationOutput(StorePath::dummy.clone(), std::optional())); } Hash h = hashDerivationModulo(*state.store, Derivation(drv), true); @@ -748,7 +748,7 @@ static void prim_derivationStrict(EvalState & state, const Pos & pos, Value * * auto outPath = state.store->makeOutputPath(i, h, drvName); if (!jsonObject) drv.env[i] = state.store->printStorePath(outPath); drv.outputs.insert_or_assign(i, - DerivationOutput(std::move(outPath), "", "")); + DerivationOutput(std::move(outPath), std::optional())); } } diff --git a/src/libstore/build.cc b/src/libstore/build.cc index 224633106..c2605cb39 100644 --- a/src/libstore/build.cc +++ b/src/libstore/build.cc @@ -3647,10 +3647,7 @@ void DerivationGoal::registerOutputs() if (fixedOutput) { - FileIngestionMethod recursive; Hash h; - i.second.parseHashInfo(recursive, h); - - if (!static_cast(recursive)) { + if (i.second.hash->method == FileIngestionMethod::Flat) { /* The output path should be a regular file without execute permission. */ if (!S_ISREG(st.st_mode) || (st.st_mode & S_IXUSR) != 0) throw BuildError( @@ -3659,18 +3656,22 @@ void DerivationGoal::registerOutputs() /* Check the hash. In hash mode, move the path produced by the derivation to its content-addressed location. */ - Hash h2 = static_cast(recursive) ? hashPath(h.type, actualPath).first : hashFile(h.type, actualPath); + Hash h2 = i.second.hash->method == FileIngestionMethod::Recursive + ? hashPath(i.second.hash->hash.type, actualPath).first + : hashFile(i.second.hash->hash.type, actualPath); - auto dest = worker.store.makeFixedOutputPath(recursive, h2, i.second.path.name()); + auto dest = worker.store.makeFixedOutputPath(i.second.hash->method, h2, i.second.path.name()); - if (h != h2) { + if (i.second.hash->hash != h2) { /* Throw an error after registering the path as valid. */ worker.hashMismatch = true; delayedException = std::make_exception_ptr( BuildError("hash mismatch in fixed-output derivation '%s':\n wanted: %s\n got: %s", - worker.store.printStorePath(dest), h.to_string(SRI), h2.to_string(SRI))); + worker.store.printStorePath(dest), + i.second.hash->hash.to_string(SRI), + h2.to_string(SRI))); Path actualDest = worker.store.Store::toRealPath(dest); @@ -3690,7 +3691,7 @@ void DerivationGoal::registerOutputs() else assert(worker.store.parseStorePath(path) == dest); - ca = makeFixedOutputCA(recursive, h2); + ca = makeFixedOutputCA(i.second.hash->method, h2); } /* Get rid of all weird permissions. This also checks that diff --git a/src/libstore/derivations.cc b/src/libstore/derivations.cc index 5934c1912..3f5efe8a6 100644 --- a/src/libstore/derivations.cc +++ b/src/libstore/derivations.cc @@ -8,22 +8,8 @@ namespace nix { - -void DerivationOutput::parseHashInfo(FileIngestionMethod & recursive, Hash & hash) const -{ - recursive = FileIngestionMethod::Flat; - string algo = hashAlgo; - - if (string(algo, 0, 2) == "r:") { - recursive = FileIngestionMethod::Recursive; - algo = string(algo, 2); - } - - HashType hashType = parseHashType(algo); - if (hashType == htUnknown) - throw Error("unknown hash algorithm '%s'", algo); - - hash = Hash(this->hash, hashType); +std::string FileSystemHash::printMethodAlgo() const { + return makeFileIngestionPrefix(method) + printHashType(hash.type); } @@ -35,7 +21,7 @@ BasicDerivation::BasicDerivation(const BasicDerivation & other) { for (auto & i : other.outputs) outputs.insert_or_assign(i.first, - DerivationOutput(i.second.path.clone(), std::string(i.second.hashAlgo), std::string(i.second.hash))); + DerivationOutput(i.second.path.clone(), std::optional(i.second.hash))); for (auto & i : other.inputSrcs) inputSrcs.insert(i.clone()); } @@ -142,6 +128,33 @@ static StringSet parseStrings(std::istream & str, bool arePaths) } +static DerivationOutput parseDerivationOutput(const Store & store, istringstream_nocopy & str) +{ + expect(str, ","); auto path = store.parseStorePath(parsePath(str)); + expect(str, ","); auto hashAlgo = parseString(str); + expect(str, ","); const auto hash = parseString(str); + expect(str, ")"); + + auto method = FileIngestionMethod::Flat; + std::optional fsh; + if (hashAlgo != "") { + if (string(hashAlgo, 0, 2) == "r:") { + method = FileIngestionMethod::Recursive; + hashAlgo = string(hashAlgo, 2); + } + const HashType hashType = parseHashType(hashAlgo); + if (hashType == htUnknown) + throw Error("unknown hash hashAlgorithm '%s'", hashAlgo); + fsh = FileSystemHash { + std::move(method), + Hash(hash, hashType), + }; + } + + return DerivationOutput(std::move(path), std::move(fsh)); +} + + static Derivation parseDerivation(const Store & store, const string & s) { Derivation drv; @@ -151,11 +164,7 @@ static Derivation parseDerivation(const Store & store, const string & s) /* Parse the list of outputs. */ while (!endOfList(str)) { expect(str, "("); std::string id = parseString(str); - expect(str, ","); auto path = store.parseStorePath(parsePath(str)); - expect(str, ","); auto hashAlgo = parseString(str); - expect(str, ","); auto hash = parseString(str); - expect(str, ")"); - drv.outputs.emplace(id, DerivationOutput(std::move(path), std::move(hashAlgo), std::move(hash))); + drv.outputs.emplace(id, parseDerivationOutput(store, str)); } /* Parse the list of input derivations. */ @@ -275,8 +284,9 @@ string Derivation::unparse(const Store & store, bool maskOutputs, if (first) first = false; else s += ','; s += '('; printUnquotedString(s, i.first); s += ','; printUnquotedString(s, maskOutputs ? "" : store.printStorePath(i.second.path)); - s += ','; printUnquotedString(s, i.second.hashAlgo); - s += ','; printUnquotedString(s, i.second.hash); + s += ','; printUnquotedString(s, i.second.hash ? i.second.hash->printMethodAlgo() : ""); + s += ','; printUnquotedString(s, + i.second.hash ? i.second.hash->hash.to_string(Base16, false) : ""); s += ')'; } @@ -332,7 +342,7 @@ bool BasicDerivation::isFixedOutput() const { return outputs.size() == 1 && outputs.begin()->first == "out" && - outputs.begin()->second.hash != ""; + outputs.begin()->second.hash; } @@ -365,8 +375,8 @@ Hash hashDerivationModulo(Store & store, const Derivation & drv, bool maskOutput if (drv.isFixedOutput()) { DerivationOutputs::const_iterator i = drv.outputs.begin(); return hashString(htSHA256, "fixed:out:" - + i->second.hashAlgo + ":" - + i->second.hash + ":" + + i->second.hash->printMethodAlgo() + ":" + + i->second.hash->hash.to_string(Base16, false) + ":" + store.printStorePath(i->second.path)); } @@ -409,6 +419,30 @@ StorePathSet BasicDerivation::outputPaths() const return paths; } +static DerivationOutput readDerivationOutput(Source & in, const Store & store) +{ + auto path = store.parseStorePath(readString(in)); + auto hashAlgo = readString(in); + const auto hash = readString(in); + + auto method = FileIngestionMethod::Flat; + std::optional fsh; + if (hashAlgo != "") { + if (string(hashAlgo, 0, 2) == "r:") { + method = FileIngestionMethod::Recursive; + hashAlgo = string(hashAlgo, 2); + } + HashType hashType = parseHashType(hashAlgo); + if (hashType == htUnknown) + throw Error("unknown hash hashAlgorithm '%s'", hashAlgo); + fsh = FileSystemHash { + std::move(method), + Hash(hash, hashType), + }; + } + + return DerivationOutput(std::move(path), std::move(fsh)); +} Source & readDerivation(Source & in, const Store & store, BasicDerivation & drv) { @@ -416,10 +450,8 @@ Source & readDerivation(Source & in, const Store & store, BasicDerivation & drv) auto nr = readNum(in); for (size_t n = 0; n < nr; n++) { auto name = readString(in); - auto path = store.parseStorePath(readString(in)); - auto hashAlgo = readString(in); - auto hash = readString(in); - drv.outputs.emplace(name, DerivationOutput(std::move(path), std::move(hashAlgo), std::move(hash))); + auto output = readDerivationOutput(in, store); + drv.outputs.emplace(name, output); } drv.inputSrcs = readStorePaths(store, in); @@ -441,7 +473,10 @@ void writeDerivation(Sink & out, const Store & store, const BasicDerivation & dr { out << drv.outputs.size(); for (auto & i : drv.outputs) - out << i.first << store.printStorePath(i.second.path) << i.second.hashAlgo << i.second.hash; + out << i.first + << store.printStorePath(i.second.path) + << i.second.hash->printMethodAlgo() + << i.second.hash->hash.to_string(Base16, false); writeStorePaths(store, out, drv.inputSrcs); out << drv.platform << drv.builder << drv.args; out << drv.env.size(); diff --git a/src/libstore/derivations.hh b/src/libstore/derivations.hh index ea517a78c..320adc7c9 100644 --- a/src/libstore/derivations.hh +++ b/src/libstore/derivations.hh @@ -12,20 +12,31 @@ namespace nix { /* Abstract syntax of derivations. */ +/// Pair of a hash, and how the file system was ingested +struct FileSystemHash { + FileIngestionMethod method; + Hash hash; + FileSystemHash(FileIngestionMethod method, Hash hash) + : method(std::move(method)) + , hash(std::move(hash)) + { } + FileSystemHash(const FileSystemHash &) = default; + FileSystemHash(FileSystemHash &&) = default; + FileSystemHash & operator = (const FileSystemHash &) = default; + std::string printMethodAlgo() const; +}; + struct DerivationOutput { StorePath path; - std::string hashAlgo; /* hash used for expected hash computation */ - std::string hash; /* expected hash, may be null */ - DerivationOutput(StorePath && path, std::string && hashAlgo, std::string && hash) + std::optional hash; /* hash used for expected hash computation */ + DerivationOutput(StorePath && path, std::optional && hash) : path(std::move(path)) - , hashAlgo(std::move(hashAlgo)) , hash(std::move(hash)) { } DerivationOutput(const DerivationOutput &) = default; DerivationOutput(DerivationOutput &&) = default; DerivationOutput & operator = (const DerivationOutput &) = default; - void parseHashInfo(FileIngestionMethod & recursive, Hash & hash) const; }; typedef std::map DerivationOutputs; diff --git a/src/libstore/local-store.cc b/src/libstore/local-store.cc index 746f81beb..82a9eb43c 100644 --- a/src/libstore/local-store.cc +++ b/src/libstore/local-store.cc @@ -557,10 +557,12 @@ void LocalStore::checkDerivationOutputs(const StorePath & drvPath, const Derivat if (out == drv.outputs.end()) throw Error("derivation '%s' does not have an output named 'out'", printStorePath(drvPath)); - FileIngestionMethod recursive; Hash h; - out->second.parseHashInfo(recursive, h); - - check(makeFixedOutputPath(recursive, h, drvName), out->second.path, "out"); + check( + makeFixedOutputPath( + out->second.hash->method, + out->second.hash->hash, + drvName), + out->second.path, "out"); } else { diff --git a/src/libstore/store-api.cc b/src/libstore/store-api.cc index 359a9a768..d4772e04e 100644 --- a/src/libstore/store-api.cc +++ b/src/libstore/store-api.cc @@ -171,18 +171,18 @@ static std::string makeType( StorePath Store::makeFixedOutputPath( - FileIngestionMethod recursive, + FileIngestionMethod method, const Hash & hash, std::string_view name, const StorePathSet & references, bool hasSelfReference) const { - if (hash.type == htSHA256 && recursive == FileIngestionMethod::Recursive) { + if (hash.type == htSHA256 && method == FileIngestionMethod::Recursive) { return makeStorePath(makeType(*this, "source", references, hasSelfReference), hash, name); } else { assert(references.empty()); return makeStorePath("output:out", hashString(htSHA256, - "fixed:out:" + (static_cast(recursive) ? (string) "r:" : "") + + "fixed:out:" + makeFileIngestionPrefix(method) + hash.to_string(Base16) + ":"), name); } } @@ -811,9 +811,22 @@ Strings ValidPathInfo::shortRefs() const } -std::string makeFixedOutputCA(FileIngestionMethod recursive, const Hash & hash) +std::string makeFileIngestionPrefix(const FileIngestionMethod m) { + switch (m) { + case FileIngestionMethod::Flat: + return ""; + case FileIngestionMethod::Recursive: + return "r:"; + default: + throw Error("impossible, caught both cases"); + } +} + +std::string makeFixedOutputCA(FileIngestionMethod method, const Hash & hash) { - return "fixed:" + (static_cast(recursive) ? (std::string) "r:" : "") + hash.to_string(); + return "fixed:" + + makeFileIngestionPrefix(method) + + hash.to_string(); } diff --git a/src/libstore/store-api.hh b/src/libstore/store-api.hh index a4fdad8c4..ef15e60ec 100644 --- a/src/libstore/store-api.hh +++ b/src/libstore/store-api.hh @@ -847,6 +847,9 @@ std::optional decodeValidPathInfo( std::istream & str, bool hashGiven = false); +/* Compute the prefix to the hash algorithm which indicates how the files were + ingested. */ +std::string makeFileIngestionPrefix(const FileIngestionMethod m); /* Compute the content-addressability assertion (ValidPathInfo::ca) for paths created by makeFixedOutputPath() / addToStore(). */ diff --git a/src/nix/show-derivation.cc b/src/nix/show-derivation.cc index 0ede7b468..b2ec71dbb 100644 --- a/src/nix/show-derivation.cc +++ b/src/nix/show-derivation.cc @@ -69,9 +69,9 @@ struct CmdShowDerivation : InstallablesCommand for (auto & output : drv.outputs) { auto outputObj(outputsObj.object(output.first)); outputObj.attr("path", store->printStorePath(output.second.path)); - if (output.second.hash != "") { - outputObj.attr("hashAlgo", output.second.hashAlgo); - outputObj.attr("hash", output.second.hash); + if (output.second.hash) { + outputObj.attr("hashAlgo", output.second.hash->printMethodAlgo()); + outputObj.attr("hash", output.second.hash->hash.to_string(Base16, false)); } } } -- cgit v1.2.3 From c2f33edd1f30f5c7c54780636104bdef318d65db Mon Sep 17 00:00:00 2001 From: Carlo Nucera Date: Tue, 26 May 2020 11:43:18 -0400 Subject: Update src/libutil/rust-ffi.hh Co-authored-by: Cole Helbling --- src/libutil/rust-ffi.hh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libutil/rust-ffi.hh b/src/libutil/rust-ffi.hh index 584dcf110..8b61b6d00 100644 --- a/src/libutil/rust-ffi.hh +++ b/src/libutil/rust-ffi.hh @@ -42,7 +42,7 @@ protected: } // Not all Rust types are Clone / Copy, but our base Value class needs to - // have a copy constructor so that ones which do implement Copy/Clone + // have a copy constructor so that types which do implement Copy/Clone // can be copied/cloned. Value(const Value & other) : raw(other.raw) -- cgit v1.2.3 From f3f520c14ca0316f9e6333fbe939a277e5d78d1b Mon Sep 17 00:00:00 2001 From: Carlo Nucera Date: Tue, 26 May 2020 12:51:28 -0400 Subject: Change syntax for CI --- src/nix/dev-shell.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/nix/dev-shell.cc b/src/nix/dev-shell.cc index 092ff8b10..337d7750e 100644 --- a/src/nix/dev-shell.cc +++ b/src/nix/dev-shell.cc @@ -136,8 +136,7 @@ StorePath getDerivationEnvironment(ref store, const StorePath & drvPath) Hash h = hashDerivationModulo(*store, drv, true); auto shellOutPath = store->makeOutputPath("out", h, drvName); drv.outputs.insert_or_assign("out", DerivationOutput(shellOutPath.clone(), FileSystemHash { - .method = FileIngestionMethod::Flat, - .hash = Hash { } + FileIngestionMethod::Flat, Hash { } })); drv.env["out"] = store->printStorePath(shellOutPath); auto shellDrvPath2 = writeDerivation(store, drv, drvName); -- cgit v1.2.3 From 6dd471ebf6b9a4996405398093ccb371b8abdf2f Mon Sep 17 00:00:00 2001 From: Carlo Nucera Date: Thu, 28 May 2020 11:28:43 -0400 Subject: Fixing the result of merge --- src/libexpr/primops.cc | 128 ------------ src/libexpr/primops/fetchGit.cc | 360 +--------------------------------- src/libexpr/primops/fetchMercurial.cc | 310 +---------------------------- src/libexpr/primops/fetchTree.cc | 6 +- src/libfetchers/fetchers.cc | 4 +- src/libfetchers/git.cc | 18 +- src/libfetchers/github.cc | 12 +- src/libfetchers/mercurial.cc | 12 +- src/libfetchers/path.cc | 4 +- src/libfetchers/tarball.cc | 12 +- src/libmain/common-args.cc | 58 +----- src/libstore/build.cc | 2 +- src/libstore/filetransfer.cc | 134 ------------- src/libutil/tests/hash.cc | 18 +- 14 files changed, 53 insertions(+), 1025 deletions(-) diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc index 044f3290a..8fbcef8c8 100644 --- a/src/libexpr/primops.cc +++ b/src/libexpr/primops.cc @@ -2053,134 +2053,6 @@ static void prim_splitVersion(EvalState & state, const Pos & pos, Value * * args /************************************************************* -<<<<<<< HEAD - * Networking - *************************************************************/ - - -void fetch(EvalState & state, const Pos & pos, Value * * args, Value & v, - const string & who, bool unpack, const std::string & defaultName) -{ - CachedDownloadRequest request(""); - request.unpack = unpack; - request.name = defaultName; - - state.forceValue(*args[0]); - - if (args[0]->type == tAttrs) { - - state.forceAttrs(*args[0], pos); - - for (auto & attr : *args[0]->attrs) { - string n(attr.name); - if (n == "url") - request.uri = state.forceStringNoCtx(*attr.value, *attr.pos); - else if (n == "sha256") - request.expectedHash = Hash(state.forceStringNoCtx(*attr.value, *attr.pos), HashType::SHA256); - else if (n == "name") - request.name = state.forceStringNoCtx(*attr.value, *attr.pos); - else - throw EvalError(format("unsupported argument '%1%' to '%2%', at %3%") % attr.name % who % attr.pos); - } - - if (request.uri.empty()) - throw EvalError(format("'url' argument required, at %1%") % pos); - - } else - request.uri = state.forceStringNoCtx(*args[0], pos); - - state.checkURI(request.uri); - - if (evalSettings.pureEval && !request.expectedHash) - throw Error("in pure evaluation mode, '%s' requires a 'sha256' argument", who); - - auto res = getDownloader()->downloadCached(state.store, request); - - if (state.allowedPaths) - state.allowedPaths->insert(res.path); - - mkString(v, res.storePath, PathSet({res.storePath})); -} - - -static void prim_fetchurl(EvalState & state, const Pos & pos, Value * * args, Value & v) -{ - fetch(state, pos, args, v, "fetchurl", false, ""); -} - - -static void prim_fetchTarball(EvalState & state, const Pos & pos, Value * * args, Value & v) -{ - fetch(state, pos, args, v, "fetchTarball", true, "source"); -} - - -/************************************************************* -||||||| merged common ancestors - * Networking - *************************************************************/ - - -void fetch(EvalState & state, const Pos & pos, Value * * args, Value & v, - const string & who, bool unpack, const std::string & defaultName) -{ - CachedDownloadRequest request(""); - request.unpack = unpack; - request.name = defaultName; - - state.forceValue(*args[0]); - - if (args[0]->type == tAttrs) { - - state.forceAttrs(*args[0], pos); - - for (auto & attr : *args[0]->attrs) { - string n(attr.name); - if (n == "url") - request.uri = state.forceStringNoCtx(*attr.value, *attr.pos); - else if (n == "sha256") - request.expectedHash = Hash(state.forceStringNoCtx(*attr.value, *attr.pos), htSHA256); - else if (n == "name") - request.name = state.forceStringNoCtx(*attr.value, *attr.pos); - else - throw EvalError(format("unsupported argument '%1%' to '%2%', at %3%") % attr.name % who % attr.pos); - } - - if (request.uri.empty()) - throw EvalError(format("'url' argument required, at %1%") % pos); - - } else - request.uri = state.forceStringNoCtx(*args[0], pos); - - state.checkURI(request.uri); - - if (evalSettings.pureEval && !request.expectedHash) - throw Error("in pure evaluation mode, '%s' requires a 'sha256' argument", who); - - auto res = getDownloader()->downloadCached(state.store, request); - - if (state.allowedPaths) - state.allowedPaths->insert(res.path); - - mkString(v, res.storePath, PathSet({res.storePath})); -} - - -static void prim_fetchurl(EvalState & state, const Pos & pos, Value * * args, Value & v) -{ - fetch(state, pos, args, v, "fetchurl", false, ""); -} - - -static void prim_fetchTarball(EvalState & state, const Pos & pos, Value * * args, Value & v) -{ - fetch(state, pos, args, v, "fetchTarball", true, "source"); -} - - -/************************************************************* -======= ->>>>>>> f60ce4fa207a210e23a1142d3a8ead611526e6e1 * Primop registration *************************************************************/ diff --git a/src/libexpr/primops/fetchGit.cc b/src/libexpr/primops/fetchGit.cc index 1c8df145a..b199c9e13 100644 --- a/src/libexpr/primops/fetchGit.cc +++ b/src/libexpr/primops/fetchGit.cc @@ -7,362 +7,6 @@ namespace nix { -<<<<<<< HEAD -struct GitInfo -{ - Path storePath; - std::string rev; - std::string shortRev; - uint64_t revCount = 0; -}; - -std::regex revRegex("^[0-9a-fA-F]{40}$"); - -GitInfo exportGit(ref store, const std::string & uri, - std::optional ref, std::string rev, - const std::string & name) -{ - if (evalSettings.pureEval && rev == "") - throw Error("in pure evaluation mode, 'fetchGit' requires a Git revision"); - - if (!ref && rev == "" && hasPrefix(uri, "/") && pathExists(uri + "/.git")) { - - bool clean = true; - - try { - runProgram("git", true, { "-C", uri, "diff-index", "--quiet", "HEAD", "--" }); - } catch (ExecError & e) { - if (!WIFEXITED(e.status) || WEXITSTATUS(e.status) != 1) throw; - clean = false; - } - - if (!clean) { - - /* This is an unclean working tree. So copy all tracked files. */ - GitInfo gitInfo; - gitInfo.rev = "0000000000000000000000000000000000000000"; - gitInfo.shortRev = std::string(gitInfo.rev, 0, 7); - - auto files = tokenizeString>( - runProgram("git", true, { "-C", uri, "ls-files", "-z" }), "\0"s); - - PathFilter filter = [&](const Path & p) -> bool { - assert(hasPrefix(p, uri)); - std::string file(p, uri.size() + 1); - - auto st = lstat(p); - - if (S_ISDIR(st.st_mode)) { - auto prefix = file + "/"; - auto i = files.lower_bound(prefix); - return i != files.end() && hasPrefix(*i, prefix); - } - - return files.count(file); - }; - - gitInfo.storePath = store->printStorePath(store->addToStore("source", uri, true, HashType::SHA256, filter)); - - return gitInfo; - } - - // clean working tree, but no ref or rev specified. Use 'HEAD'. - rev = chomp(runProgram("git", true, { "-C", uri, "rev-parse", "HEAD" })); - ref = "HEAD"s; - } - - if (!ref) ref = "HEAD"s; - - if (rev != "" && !std::regex_match(rev, revRegex)) - throw Error("invalid Git revision '%s'", rev); - - deletePath(getCacheDir() + "/nix/git"); - - Path cacheDir = getCacheDir() + "/nix/gitv2/" + hashString(HashType::SHA256, uri).to_string(Base::Base32, false); - - if (!pathExists(cacheDir)) { - createDirs(dirOf(cacheDir)); - runProgram("git", true, { "init", "--bare", cacheDir }); - } - - Path localRefFile; - if (ref->compare(0, 5, "refs/") == 0) - localRefFile = cacheDir + "/" + *ref; - else - localRefFile = cacheDir + "/refs/heads/" + *ref; - - bool doFetch; - time_t now = time(0); - /* If a rev was specified, we need to fetch if it's not in the - repo. */ - if (rev != "") { - try { - runProgram("git", true, { "-C", cacheDir, "cat-file", "-e", rev }); - doFetch = false; - } catch (ExecError & e) { - if (WIFEXITED(e.status)) { - doFetch = true; - } else { - throw; - } - } - } else { - /* If the local ref is older than ‘tarball-ttl’ seconds, do a - git fetch to update the local ref to the remote ref. */ - struct stat st; - doFetch = stat(localRefFile.c_str(), &st) != 0 || - (uint64_t) st.st_mtime + settings.tarballTtl <= (uint64_t) now; - } - if (doFetch) - { - Activity act(*logger, Verbosity::Talkative, ActivityType::Unknown, fmt("fetching Git repository '%s'", uri)); - - // FIXME: git stderr messes up our progress indicator, so - // we're using --quiet for now. Should process its stderr. - runProgram("git", true, { "-C", cacheDir, "fetch", "--quiet", "--force", "--", uri, fmt("%s:%s", *ref, *ref) }); - - struct timeval times[2]; - times[0].tv_sec = now; - times[0].tv_usec = 0; - times[1].tv_sec = now; - times[1].tv_usec = 0; - - utimes(localRefFile.c_str(), times); - } - - // FIXME: check whether rev is an ancestor of ref. - GitInfo gitInfo; - gitInfo.rev = rev != "" ? rev : chomp(readFile(localRefFile)); - gitInfo.shortRev = std::string(gitInfo.rev, 0, 7); - - printTalkative("using revision %s of repo '%s'", gitInfo.rev, uri); - - std::string storeLinkName = hashString(HashType::SHA512, name + std::string("\0"s) + gitInfo.rev).to_string(Base::Base32, false); - Path storeLink = cacheDir + "/" + storeLinkName + ".link"; - PathLocks storeLinkLock({storeLink}, fmt("waiting for lock on '%1%'...", storeLink)); // FIXME: broken - - try { - auto json = nlohmann::json::parse(readFile(storeLink)); - - assert(json["name"] == name && json["rev"] == gitInfo.rev); - - gitInfo.storePath = json["storePath"]; - - if (store->isValidPath(store->parseStorePath(gitInfo.storePath))) { - gitInfo.revCount = json["revCount"]; - return gitInfo; - } - - } catch (SysError & e) { - if (e.errNo != ENOENT) throw; - } - - auto source = sinkToSource([&](Sink & sink) { - RunOptions gitOptions("git", { "-C", cacheDir, "archive", gitInfo.rev }); - gitOptions.standardOut = &sink; - runProgram2(gitOptions); - }); - - Path tmpDir = createTempDir(); - AutoDelete delTmpDir(tmpDir, true); - - unpackTarfile(*source, tmpDir); - - gitInfo.storePath = store->printStorePath(store->addToStore(name, tmpDir)); - - gitInfo.revCount = std::stoull(runProgram("git", true, { "-C", cacheDir, "rev-list", "--count", gitInfo.rev })); - - nlohmann::json json; - json["storePath"] = gitInfo.storePath; - json["uri"] = uri; - json["name"] = name; - json["rev"] = gitInfo.rev; - json["revCount"] = gitInfo.revCount; - - writeFile(storeLink, json.dump()); - - return gitInfo; -} - -||||||| merged common ancestors -struct GitInfo -{ - Path storePath; - std::string rev; - std::string shortRev; - uint64_t revCount = 0; -}; - -std::regex revRegex("^[0-9a-fA-F]{40}$"); - -GitInfo exportGit(ref store, const std::string & uri, - std::optional ref, std::string rev, - const std::string & name) -{ - if (evalSettings.pureEval && rev == "") - throw Error("in pure evaluation mode, 'fetchGit' requires a Git revision"); - - if (!ref && rev == "" && hasPrefix(uri, "/") && pathExists(uri + "/.git")) { - - bool clean = true; - - try { - runProgram("git", true, { "-C", uri, "diff-index", "--quiet", "HEAD", "--" }); - } catch (ExecError & e) { - if (!WIFEXITED(e.status) || WEXITSTATUS(e.status) != 1) throw; - clean = false; - } - - if (!clean) { - - /* This is an unclean working tree. So copy all tracked files. */ - GitInfo gitInfo; - gitInfo.rev = "0000000000000000000000000000000000000000"; - gitInfo.shortRev = std::string(gitInfo.rev, 0, 7); - - auto files = tokenizeString>( - runProgram("git", true, { "-C", uri, "ls-files", "-z" }), "\0"s); - - PathFilter filter = [&](const Path & p) -> bool { - assert(hasPrefix(p, uri)); - std::string file(p, uri.size() + 1); - - auto st = lstat(p); - - if (S_ISDIR(st.st_mode)) { - auto prefix = file + "/"; - auto i = files.lower_bound(prefix); - return i != files.end() && hasPrefix(*i, prefix); - } - - return files.count(file); - }; - - gitInfo.storePath = store->printStorePath(store->addToStore("source", uri, true, htSHA256, filter)); - - return gitInfo; - } - - // clean working tree, but no ref or rev specified. Use 'HEAD'. - rev = chomp(runProgram("git", true, { "-C", uri, "rev-parse", "HEAD" })); - ref = "HEAD"s; - } - - if (!ref) ref = "HEAD"s; - - if (rev != "" && !std::regex_match(rev, revRegex)) - throw Error("invalid Git revision '%s'", rev); - - deletePath(getCacheDir() + "/nix/git"); - - Path cacheDir = getCacheDir() + "/nix/gitv2/" + hashString(htSHA256, uri).to_string(Base32, false); - - if (!pathExists(cacheDir)) { - createDirs(dirOf(cacheDir)); - runProgram("git", true, { "init", "--bare", cacheDir }); - } - - Path localRefFile; - if (ref->compare(0, 5, "refs/") == 0) - localRefFile = cacheDir + "/" + *ref; - else - localRefFile = cacheDir + "/refs/heads/" + *ref; - - bool doFetch; - time_t now = time(0); - /* If a rev was specified, we need to fetch if it's not in the - repo. */ - if (rev != "") { - try { - runProgram("git", true, { "-C", cacheDir, "cat-file", "-e", rev }); - doFetch = false; - } catch (ExecError & e) { - if (WIFEXITED(e.status)) { - doFetch = true; - } else { - throw; - } - } - } else { - /* If the local ref is older than ‘tarball-ttl’ seconds, do a - git fetch to update the local ref to the remote ref. */ - struct stat st; - doFetch = stat(localRefFile.c_str(), &st) != 0 || - (uint64_t) st.st_mtime + settings.tarballTtl <= (uint64_t) now; - } - if (doFetch) - { - Activity act(*logger, lvlTalkative, actUnknown, fmt("fetching Git repository '%s'", uri)); - - // FIXME: git stderr messes up our progress indicator, so - // we're using --quiet for now. Should process its stderr. - runProgram("git", true, { "-C", cacheDir, "fetch", "--quiet", "--force", "--", uri, fmt("%s:%s", *ref, *ref) }); - - struct timeval times[2]; - times[0].tv_sec = now; - times[0].tv_usec = 0; - times[1].tv_sec = now; - times[1].tv_usec = 0; - - utimes(localRefFile.c_str(), times); - } - - // FIXME: check whether rev is an ancestor of ref. - GitInfo gitInfo; - gitInfo.rev = rev != "" ? rev : chomp(readFile(localRefFile)); - gitInfo.shortRev = std::string(gitInfo.rev, 0, 7); - - printTalkative("using revision %s of repo '%s'", gitInfo.rev, uri); - - std::string storeLinkName = hashString(htSHA512, name + std::string("\0"s) + gitInfo.rev).to_string(Base32, false); - Path storeLink = cacheDir + "/" + storeLinkName + ".link"; - PathLocks storeLinkLock({storeLink}, fmt("waiting for lock on '%1%'...", storeLink)); // FIXME: broken - - try { - auto json = nlohmann::json::parse(readFile(storeLink)); - - assert(json["name"] == name && json["rev"] == gitInfo.rev); - - gitInfo.storePath = json["storePath"]; - - if (store->isValidPath(store->parseStorePath(gitInfo.storePath))) { - gitInfo.revCount = json["revCount"]; - return gitInfo; - } - - } catch (SysError & e) { - if (e.errNo != ENOENT) throw; - } - - auto source = sinkToSource([&](Sink & sink) { - RunOptions gitOptions("git", { "-C", cacheDir, "archive", gitInfo.rev }); - gitOptions.standardOut = &sink; - runProgram2(gitOptions); - }); - - Path tmpDir = createTempDir(); - AutoDelete delTmpDir(tmpDir, true); - - unpackTarfile(*source, tmpDir); - - gitInfo.storePath = store->printStorePath(store->addToStore(name, tmpDir)); - - gitInfo.revCount = std::stoull(runProgram("git", true, { "-C", cacheDir, "rev-list", "--count", gitInfo.rev })); - - nlohmann::json json; - json["storePath"] = gitInfo.storePath; - json["uri"] = uri; - json["name"] = name; - json["rev"] = gitInfo.rev; - json["revCount"] = gitInfo.revCount; - - writeFile(storeLink, json.dump()); - - return gitInfo; -} - -======= ->>>>>>> f60ce4fa207a210e23a1142d3a8ead611526e6e1 static void prim_fetchGit(EvalState & state, const Pos & pos, Value * * args, Value & v) { std::string url; @@ -385,7 +29,7 @@ static void prim_fetchGit(EvalState & state, const Pos & pos, Value * * args, Va else if (n == "ref") ref = state.forceStringNoCtx(*attr.value, *attr.pos); else if (n == "rev") - rev = Hash(state.forceStringNoCtx(*attr.value, *attr.pos), htSHA1); + rev = Hash(state.forceStringNoCtx(*attr.value, *attr.pos), HashType::SHA1); else if (n == "name") name = state.forceStringNoCtx(*attr.value, *attr.pos); else if (n == "submodules") @@ -423,7 +67,7 @@ static void prim_fetchGit(EvalState & state, const Pos & pos, Value * * args, Va mkString(*state.allocAttr(v, state.sOutPath), storePath, PathSet({storePath})); // Backward compatibility: set 'rev' to // 0000000000000000000000000000000000000000 for a dirty tree. - auto rev2 = input2->getRev().value_or(Hash(htSHA1)); + auto rev2 = input2->getRev().value_or(Hash(HashType::SHA1)); mkString(*state.allocAttr(v, state.symbols.create("rev")), rev2.gitRev()); mkString(*state.allocAttr(v, state.symbols.create("shortRev")), rev2.gitShortRev()); // Backward compatibility: set 'revCount' to 0 for a dirty tree. diff --git a/src/libexpr/primops/fetchMercurial.cc b/src/libexpr/primops/fetchMercurial.cc index b6c5c74c4..913ae172b 100644 --- a/src/libexpr/primops/fetchMercurial.cc +++ b/src/libexpr/primops/fetchMercurial.cc @@ -8,312 +8,6 @@ namespace nix { -<<<<<<< HEAD -struct HgInfo -{ - Path storePath; - std::string branch; - std::string rev; - uint64_t revCount = 0; -}; - -std::regex commitHashRegex("^[0-9a-fA-F]{40}$"); - -HgInfo exportMercurial(ref store, const std::string & uri, - std::string rev, const std::string & name) -{ - if (evalSettings.pureEval && rev == "") - throw Error("in pure evaluation mode, 'fetchMercurial' requires a Mercurial revision"); - - if (rev == "" && hasPrefix(uri, "/") && pathExists(uri + "/.hg")) { - - bool clean = runProgram("hg", true, { "status", "-R", uri, "--modified", "--added", "--removed" }) == ""; - - if (!clean) { - - /* This is an unclean working tree. So copy all tracked - files. */ - - printTalkative("copying unclean Mercurial working tree '%s'", uri); - - HgInfo hgInfo; - hgInfo.rev = "0000000000000000000000000000000000000000"; - hgInfo.branch = chomp(runProgram("hg", true, { "branch", "-R", uri })); - - auto files = tokenizeString>( - runProgram("hg", true, { "status", "-R", uri, "--clean", "--modified", "--added", "--no-status", "--print0" }), "\0"s); - - PathFilter filter = [&](const Path & p) -> bool { - assert(hasPrefix(p, uri)); - std::string file(p, uri.size() + 1); - - auto st = lstat(p); - - if (S_ISDIR(st.st_mode)) { - auto prefix = file + "/"; - auto i = files.lower_bound(prefix); - return i != files.end() && hasPrefix(*i, prefix); - } - - return files.count(file); - }; - - hgInfo.storePath = store->printStorePath(store->addToStore("source", uri, true, HashType::SHA256, filter)); - - return hgInfo; - } - } - - if (rev == "") rev = "default"; - - Path cacheDir = fmt("%s/nix/hg/%s", getCacheDir(), hashString(HashType::SHA256, uri).to_string(Base::Base32, false)); - - Path stampFile = fmt("%s/.hg/%s.stamp", cacheDir, hashString(HashType::SHA512, rev).to_string(Base::Base32, false)); - - /* If we haven't pulled this repo less than ‘tarball-ttl’ seconds, - do so now. */ - time_t now = time(0); - struct stat st; - if (stat(stampFile.c_str(), &st) != 0 || - (uint64_t) st.st_mtime + settings.tarballTtl <= (uint64_t) now) - { - /* Except that if this is a commit hash that we already have, - we don't have to pull again. */ - if (!(std::regex_match(rev, commitHashRegex) - && pathExists(cacheDir) - && runProgram( - RunOptions("hg", { "log", "-R", cacheDir, "-r", rev, "--template", "1" }) - .killStderr(true)).second == "1")) - { - Activity act(*logger, Verbosity::Talkative, ActivityType::Unknown, fmt("fetching Mercurial repository '%s'", uri)); - - if (pathExists(cacheDir)) { - try { - runProgram("hg", true, { "pull", "-R", cacheDir, "--", uri }); - } - catch (ExecError & e) { - string transJournal = cacheDir + "/.hg/store/journal"; - /* hg throws "abandoned transaction" error only if this file exists */ - if (pathExists(transJournal)) { - runProgram("hg", true, { "recover", "-R", cacheDir }); - runProgram("hg", true, { "pull", "-R", cacheDir, "--", uri }); - } else { - throw ExecError(e.status, fmt("'hg pull' %s", statusToString(e.status))); - } - } - } else { - createDirs(dirOf(cacheDir)); - runProgram("hg", true, { "clone", "--noupdate", "--", uri, cacheDir }); - } - } - - writeFile(stampFile, ""); - } - - auto tokens = tokenizeString>( - runProgram("hg", true, { "log", "-R", cacheDir, "-r", rev, "--template", "{node} {rev} {branch}" })); - assert(tokens.size() == 3); - - HgInfo hgInfo; - hgInfo.rev = tokens[0]; - hgInfo.revCount = std::stoull(tokens[1]); - hgInfo.branch = tokens[2]; - - std::string storeLinkName = hashString(HashType::SHA512, name + std::string("\0"s) + hgInfo.rev).to_string(Base::Base32, false); - Path storeLink = fmt("%s/.hg/%s.link", cacheDir, storeLinkName); - - try { - auto json = nlohmann::json::parse(readFile(storeLink)); - - assert(json["name"] == name && json["rev"] == hgInfo.rev); - - hgInfo.storePath = json["storePath"]; - - if (store->isValidPath(store->parseStorePath(hgInfo.storePath))) { - printTalkative("using cached Mercurial store path '%s'", hgInfo.storePath); - return hgInfo; - } - - } catch (SysError & e) { - if (e.errNo != ENOENT) throw; - } - - Path tmpDir = createTempDir(); - AutoDelete delTmpDir(tmpDir, true); - - runProgram("hg", true, { "archive", "-R", cacheDir, "-r", rev, tmpDir }); - - deletePath(tmpDir + "/.hg_archival.txt"); - - hgInfo.storePath = store->printStorePath(store->addToStore(name, tmpDir)); - - nlohmann::json json; - json["storePath"] = hgInfo.storePath; - json["uri"] = uri; - json["name"] = name; - json["branch"] = hgInfo.branch; - json["rev"] = hgInfo.rev; - json["revCount"] = hgInfo.revCount; - - writeFile(storeLink, json.dump()); - - return hgInfo; -} - -||||||| merged common ancestors -struct HgInfo -{ - Path storePath; - std::string branch; - std::string rev; - uint64_t revCount = 0; -}; - -std::regex commitHashRegex("^[0-9a-fA-F]{40}$"); - -HgInfo exportMercurial(ref store, const std::string & uri, - std::string rev, const std::string & name) -{ - if (evalSettings.pureEval && rev == "") - throw Error("in pure evaluation mode, 'fetchMercurial' requires a Mercurial revision"); - - if (rev == "" && hasPrefix(uri, "/") && pathExists(uri + "/.hg")) { - - bool clean = runProgram("hg", true, { "status", "-R", uri, "--modified", "--added", "--removed" }) == ""; - - if (!clean) { - - /* This is an unclean working tree. So copy all tracked - files. */ - - printTalkative("copying unclean Mercurial working tree '%s'", uri); - - HgInfo hgInfo; - hgInfo.rev = "0000000000000000000000000000000000000000"; - hgInfo.branch = chomp(runProgram("hg", true, { "branch", "-R", uri })); - - auto files = tokenizeString>( - runProgram("hg", true, { "status", "-R", uri, "--clean", "--modified", "--added", "--no-status", "--print0" }), "\0"s); - - PathFilter filter = [&](const Path & p) -> bool { - assert(hasPrefix(p, uri)); - std::string file(p, uri.size() + 1); - - auto st = lstat(p); - - if (S_ISDIR(st.st_mode)) { - auto prefix = file + "/"; - auto i = files.lower_bound(prefix); - return i != files.end() && hasPrefix(*i, prefix); - } - - return files.count(file); - }; - - hgInfo.storePath = store->printStorePath(store->addToStore("source", uri, true, htSHA256, filter)); - - return hgInfo; - } - } - - if (rev == "") rev = "default"; - - Path cacheDir = fmt("%s/nix/hg/%s", getCacheDir(), hashString(htSHA256, uri).to_string(Base32, false)); - - Path stampFile = fmt("%s/.hg/%s.stamp", cacheDir, hashString(htSHA512, rev).to_string(Base32, false)); - - /* If we haven't pulled this repo less than ‘tarball-ttl’ seconds, - do so now. */ - time_t now = time(0); - struct stat st; - if (stat(stampFile.c_str(), &st) != 0 || - (uint64_t) st.st_mtime + settings.tarballTtl <= (uint64_t) now) - { - /* Except that if this is a commit hash that we already have, - we don't have to pull again. */ - if (!(std::regex_match(rev, commitHashRegex) - && pathExists(cacheDir) - && runProgram( - RunOptions("hg", { "log", "-R", cacheDir, "-r", rev, "--template", "1" }) - .killStderr(true)).second == "1")) - { - Activity act(*logger, lvlTalkative, actUnknown, fmt("fetching Mercurial repository '%s'", uri)); - - if (pathExists(cacheDir)) { - try { - runProgram("hg", true, { "pull", "-R", cacheDir, "--", uri }); - } - catch (ExecError & e) { - string transJournal = cacheDir + "/.hg/store/journal"; - /* hg throws "abandoned transaction" error only if this file exists */ - if (pathExists(transJournal)) { - runProgram("hg", true, { "recover", "-R", cacheDir }); - runProgram("hg", true, { "pull", "-R", cacheDir, "--", uri }); - } else { - throw ExecError(e.status, fmt("'hg pull' %s", statusToString(e.status))); - } - } - } else { - createDirs(dirOf(cacheDir)); - runProgram("hg", true, { "clone", "--noupdate", "--", uri, cacheDir }); - } - } - - writeFile(stampFile, ""); - } - - auto tokens = tokenizeString>( - runProgram("hg", true, { "log", "-R", cacheDir, "-r", rev, "--template", "{node} {rev} {branch}" })); - assert(tokens.size() == 3); - - HgInfo hgInfo; - hgInfo.rev = tokens[0]; - hgInfo.revCount = std::stoull(tokens[1]); - hgInfo.branch = tokens[2]; - - std::string storeLinkName = hashString(htSHA512, name + std::string("\0"s) + hgInfo.rev).to_string(Base32, false); - Path storeLink = fmt("%s/.hg/%s.link", cacheDir, storeLinkName); - - try { - auto json = nlohmann::json::parse(readFile(storeLink)); - - assert(json["name"] == name && json["rev"] == hgInfo.rev); - - hgInfo.storePath = json["storePath"]; - - if (store->isValidPath(store->parseStorePath(hgInfo.storePath))) { - printTalkative("using cached Mercurial store path '%s'", hgInfo.storePath); - return hgInfo; - } - - } catch (SysError & e) { - if (e.errNo != ENOENT) throw; - } - - Path tmpDir = createTempDir(); - AutoDelete delTmpDir(tmpDir, true); - - runProgram("hg", true, { "archive", "-R", cacheDir, "-r", rev, tmpDir }); - - deletePath(tmpDir + "/.hg_archival.txt"); - - hgInfo.storePath = store->printStorePath(store->addToStore(name, tmpDir)); - - nlohmann::json json; - json["storePath"] = hgInfo.storePath; - json["uri"] = uri; - json["name"] = name; - json["branch"] = hgInfo.branch; - json["rev"] = hgInfo.rev; - json["revCount"] = hgInfo.revCount; - - writeFile(storeLink, json.dump()); - - return hgInfo; -} - -======= ->>>>>>> f60ce4fa207a210e23a1142d3a8ead611526e6e1 static void prim_fetchMercurial(EvalState & state, const Pos & pos, Value * * args, Value & v) { std::string url; @@ -337,7 +31,7 @@ static void prim_fetchMercurial(EvalState & state, const Pos & pos, Value * * ar // be both a revision or a branch/tag name. auto value = state.forceStringNoCtx(*attr.value, *attr.pos); if (std::regex_match(value, revRegex)) - rev = Hash(value, htSHA1); + rev = Hash(value, HashType::SHA1); else ref = value; } @@ -377,7 +71,7 @@ static void prim_fetchMercurial(EvalState & state, const Pos & pos, Value * * ar mkString(*state.allocAttr(v, state.symbols.create("branch")), *input2->getRef()); // Backward compatibility: set 'rev' to // 0000000000000000000000000000000000000000 for a dirty tree. - auto rev2 = input2->getRev().value_or(Hash(htSHA1)); + auto rev2 = input2->getRev().value_or(Hash(HashType::SHA1)); mkString(*state.allocAttr(v, state.symbols.create("rev")), rev2.gitRev()); mkString(*state.allocAttr(v, state.symbols.create("shortRev")), std::string(rev2.gitRev(), 0, 12)); if (tree.info.revCount) diff --git a/src/libexpr/primops/fetchTree.cc b/src/libexpr/primops/fetchTree.cc index c5a0d9886..0a62a0756 100644 --- a/src/libexpr/primops/fetchTree.cc +++ b/src/libexpr/primops/fetchTree.cc @@ -23,7 +23,7 @@ void emitTreeAttrs( assert(tree.info.narHash); mkString(*state.allocAttr(v, state.symbols.create("narHash")), - tree.info.narHash.to_string(SRI)); + tree.info.narHash.to_string(Base::SRI)); if (input->getRev()) { mkString(*state.allocAttr(v, state.symbols.create("rev")), input->getRev()->gitRev()); @@ -103,7 +103,7 @@ static void fetch(EvalState & state, const Pos & pos, Value * * args, Value & v, if (n == "url") url = state.forceStringNoCtx(*attr.value, *attr.pos); else if (n == "sha256") - expectedHash = Hash(state.forceStringNoCtx(*attr.value, *attr.pos), htSHA256); + expectedHash = Hash(state.forceStringNoCtx(*attr.value, *attr.pos), HashType::SHA256); else if (n == "name") name = state.forceStringNoCtx(*attr.value, *attr.pos); else @@ -137,7 +137,7 @@ static void fetch(EvalState & state, const Pos & pos, Value * * args, Value & v, if (expectedHash) { auto hash = unpack ? state.store->queryPathInfo(storePath)->narHash - : hashFile(htSHA256, path); + : hashFile(HashType::SHA256, path); if (hash != *expectedHash) throw Error((unsigned int) 102, "hash mismatch in file downloaded from '%s':\n wanted: %s\n got: %s", *url, expectedHash->to_string(), hash.to_string()); diff --git a/src/libfetchers/fetchers.cc b/src/libfetchers/fetchers.cc index 94ac30e38..a13533c3c 100644 --- a/src/libfetchers/fetchers.cc +++ b/src/libfetchers/fetchers.cc @@ -47,7 +47,7 @@ Attrs Input::toAttrs() const { auto attrs = toAttrsInternal(); if (narHash) - attrs.emplace("narHash", narHash->to_string(SRI)); + attrs.emplace("narHash", narHash->to_string(Base::SRI)); attrs.emplace("type", type()); return attrs; } @@ -67,7 +67,7 @@ std::pair> Input::fetchTree(ref store) if (narHash && narHash != input->narHash) throw Error("NAR hash mismatch in input '%s' (%s), expected '%s', got '%s'", - to_string(), tree.actualPath, narHash->to_string(SRI), input->narHash->to_string(SRI)); + to_string(), tree.actualPath, narHash->to_string(Base::SRI), input->narHash->to_string(Base::SRI)); return {std::move(tree), input}; } diff --git a/src/libfetchers/git.cc b/src/libfetchers/git.cc index 17cc60228..7d681218e 100644 --- a/src/libfetchers/git.cc +++ b/src/libfetchers/git.cc @@ -95,7 +95,7 @@ struct GitInput : Input auto input = std::make_shared(*this); - assert(!rev || rev->type == htSHA1); + assert(!rev || rev->type == HashType::SHA1); std::string cacheType = "git"; if (shallow) cacheType += "-shallow"; @@ -195,7 +195,7 @@ struct GitInput : Input return files.count(file); }; - auto storePath = store->addToStore("source", actualUrl, FileIngestionMethod::Recursive, htSHA256, filter); + auto storePath = store->addToStore("source", actualUrl, FileIngestionMethod::Recursive, HashType::SHA256, filter); auto tree = Tree { .actualPath = store->printStorePath(storePath), @@ -225,21 +225,21 @@ struct GitInput : Input if (isLocal) { if (!input->rev) - input->rev = Hash(chomp(runProgram("git", true, { "-C", actualUrl, "rev-parse", *input->ref })), htSHA1); + input->rev = Hash(chomp(runProgram("git", true, { "-C", actualUrl, "rev-parse", *input->ref })), HashType::SHA1); repoDir = actualUrl; } else { if (auto res = getCache()->lookup(store, mutableAttrs)) { - auto rev2 = Hash(getStrAttr(res->first, "rev"), htSHA1); + auto rev2 = Hash(getStrAttr(res->first, "rev"), HashType::SHA1); if (!rev || rev == rev2) { input->rev = rev2; return makeResult(res->first, std::move(res->second)); } } - Path cacheDir = getCacheDir() + "/nix/gitv3/" + hashString(htSHA256, actualUrl).to_string(Base32, false); + Path cacheDir = getCacheDir() + "/nix/gitv3/" + hashString(HashType::SHA256, actualUrl).to_string(Base::Base32, false); repoDir = cacheDir; if (!pathExists(cacheDir)) { @@ -277,7 +277,7 @@ struct GitInput : Input } if (doFetch) { - Activity act(*logger, lvlTalkative, actUnknown, fmt("fetching Git repository '%s'", actualUrl)); + Activity act(*logger, Verbosity::Talkative, ActivityType::Unknown, fmt("fetching Git repository '%s'", actualUrl)); // FIXME: git stderr messes up our progress indicator, so // we're using --quiet for now. Should process its stderr. @@ -298,7 +298,7 @@ struct GitInput : Input } if (!input->rev) - input->rev = Hash(chomp(readFile(localRefFile)), htSHA1); + input->rev = Hash(chomp(readFile(localRefFile)), HashType::SHA1); } bool isShallow = chomp(runProgram("git", true, { "-C", repoDir, "rev-parse", "--is-shallow-repository" })) == "true"; @@ -347,7 +347,7 @@ struct GitInput : Input unpackTarfile(*source, tmpDir); } - auto storePath = store->addToStore(name, tmpDir, FileIngestionMethod::Recursive, htSHA256, filter); + auto storePath = store->addToStore(name, tmpDir, FileIngestionMethod::Recursive, HashType::SHA256, filter); auto lastModified = std::stoull(runProgram("git", true, { "-C", repoDir, "log", "-1", "--format=%ct", input->rev->gitRev() })); @@ -423,7 +423,7 @@ struct GitInputScheme : InputScheme input->ref = *ref; } if (auto rev = maybeGetStrAttr(attrs, "rev")) - input->rev = Hash(*rev, htSHA1); + input->rev = Hash(*rev, HashType::SHA1); input->shallow = maybeGetBoolAttr(attrs, "shallow").value_or(false); diff --git a/src/libfetchers/github.cc b/src/libfetchers/github.cc index 8675a5a66..99336fc54 100644 --- a/src/libfetchers/github.cc +++ b/src/libfetchers/github.cc @@ -45,7 +45,7 @@ struct GitHubInput : Input auto path = owner + "/" + repo; assert(!(ref && rev)); if (ref) path += "/" + *ref; - if (rev) path += "/" + rev->to_string(Base16, false); + if (rev) path += "/" + rev->to_string(Base::Base16, false); return ParsedURL { .scheme = "github", .path = path, @@ -76,7 +76,7 @@ struct GitHubInput : Input readFile( store->toRealPath( downloadFile(store, url, "source", false).storePath))); - rev = Hash(json["sha"], htSHA1); + rev = Hash(json["sha"], HashType::SHA1); debug("HEAD revision for '%s' is %s", url, rev->gitRev()); } @@ -106,7 +106,7 @@ struct GitHubInput : Input // might have stricter rate limits. auto url = fmt("https://api.github.com/repos/%s/%s/tarball/%s", - owner, repo, rev->to_string(Base16, false)); + owner, repo, rev->to_string(Base::Base16, false)); std::string accessToken = settings.githubAccessToken.get(); if (accessToken != "") @@ -140,7 +140,7 @@ struct GitHubInputScheme : InputScheme if (path.size() == 2) { } else if (path.size() == 3) { if (std::regex_match(path[2], revRegex)) - input->rev = Hash(path[2], htSHA1); + input->rev = Hash(path[2], HashType::SHA1); else if (std::regex_match(path[2], refRegex)) input->ref = path[2]; else @@ -152,7 +152,7 @@ struct GitHubInputScheme : InputScheme if (name == "rev") { if (input->rev) throw BadURL("GitHub URL '%s' contains multiple commit hashes", url.url); - input->rev = Hash(value, htSHA1); + input->rev = Hash(value, HashType::SHA1); } else if (name == "ref") { if (!std::regex_match(value, refRegex)) @@ -185,7 +185,7 @@ struct GitHubInputScheme : InputScheme input->repo = getStrAttr(attrs, "repo"); input->ref = maybeGetStrAttr(attrs, "ref"); if (auto rev = maybeGetStrAttr(attrs, "rev")) - input->rev = Hash(*rev, htSHA1); + input->rev = Hash(*rev, HashType::SHA1); return input; } }; diff --git a/src/libfetchers/mercurial.cc b/src/libfetchers/mercurial.cc index 2e0d4bf4d..feffc48d6 100644 --- a/src/libfetchers/mercurial.cc +++ b/src/libfetchers/mercurial.cc @@ -114,7 +114,7 @@ struct MercurialInput : Input return files.count(file); }; - auto storePath = store->addToStore("source", actualUrl, FileIngestionMethod::Recursive, htSHA256, filter); + auto storePath = store->addToStore("source", actualUrl, FileIngestionMethod::Recursive, HashType::SHA256, filter); return {Tree { .actualPath = store->printStorePath(storePath), @@ -167,14 +167,14 @@ struct MercurialInput : Input }); if (auto res = getCache()->lookup(store, mutableAttrs)) { - auto rev2 = Hash(getStrAttr(res->first, "rev"), htSHA1); + auto rev2 = Hash(getStrAttr(res->first, "rev"), HashType::SHA1); if (!rev || rev == rev2) { input->rev = rev2; return makeResult(res->first, std::move(res->second)); } } - Path cacheDir = fmt("%s/nix/hg/%s", getCacheDir(), hashString(htSHA256, actualUrl).to_string(Base32, false)); + Path cacheDir = fmt("%s/nix/hg/%s", getCacheDir(), hashString(HashType::SHA256, actualUrl).to_string(Base::Base32, false)); /* If this is a commit hash that we already have, we don't have to pull again. */ @@ -184,7 +184,7 @@ struct MercurialInput : Input RunOptions("hg", { "log", "-R", cacheDir, "-r", input->rev->gitRev(), "--template", "1" }) .killStderr(true)).second == "1")) { - Activity act(*logger, lvlTalkative, actUnknown, fmt("fetching Mercurial repository '%s'", actualUrl)); + Activity act(*logger, Verbosity::Talkative, ActivityType::Unknown, fmt("fetching Mercurial repository '%s'", actualUrl)); if (pathExists(cacheDir)) { try { @@ -210,7 +210,7 @@ struct MercurialInput : Input runProgram("hg", true, { "log", "-R", cacheDir, "-r", revOrRef, "--template", "{node} {rev} {branch}" })); assert(tokens.size() == 3); - input->rev = Hash(tokens[0], htSHA1); + input->rev = Hash(tokens[0], HashType::SHA1); auto revCount = std::stoull(tokens[1]); input->ref = tokens[2]; @@ -293,7 +293,7 @@ struct MercurialInputScheme : InputScheme input->ref = *ref; } if (auto rev = maybeGetStrAttr(attrs, "rev")) - input->rev = Hash(*rev, htSHA1); + input->rev = Hash(*rev, HashType::SHA1); return input; } }; diff --git a/src/libfetchers/path.cc b/src/libfetchers/path.cc index ba2cc192e..3f50addd8 100644 --- a/src/libfetchers/path.cc +++ b/src/libfetchers/path.cc @@ -101,7 +101,7 @@ struct PathInputScheme : InputScheme for (auto & [name, value] : url.query) if (name == "rev") - input->rev = Hash(value, htSHA1); + input->rev = Hash(value, HashType::SHA1); else if (name == "revCount") { uint64_t revCount; if (!string2Int(value, revCount)) @@ -129,7 +129,7 @@ struct PathInputScheme : InputScheme for (auto & [name, value] : attrs) if (name == "rev") - input->rev = Hash(getStrAttr(attrs, "rev"), htSHA1); + input->rev = Hash(getStrAttr(attrs, "rev"), HashType::SHA1); else if (name == "revCount") input->revCount = getIntAttr(attrs, "revCount"); else if (name == "lastModified") diff --git a/src/libfetchers/tarball.cc b/src/libfetchers/tarball.cc index bf2b2a5ff..3e9004223 100644 --- a/src/libfetchers/tarball.cc +++ b/src/libfetchers/tarball.cc @@ -66,9 +66,9 @@ DownloadFileResult downloadFile( } else { StringSink sink; dumpString(*res.data, sink); - auto hash = hashString(htSHA256, *res.data); + auto hash = hashString(HashType::SHA256, *res.data); ValidPathInfo info(store->makeFixedOutputPath(FileIngestionMethod::Flat, hash, name)); - info.narHash = hashString(htSHA256, *sink.s); + info.narHash = hashString(HashType::SHA256, *sink.s); info.narSize = sink.s->size(); info.ca = makeFixedOutputCA(FileIngestionMethod::Flat, hash); store->addToStore(info, sink.s, NoRepair, NoCheckSigs); @@ -141,7 +141,7 @@ Tree downloadTarball( throw nix::Error("tarball '%s' contains an unexpected number of top-level files", url); auto topDir = tmpDir + "/" + members.begin()->name; lastModified = lstat(topDir).st_mtime; - unpackedStorePath = store->addToStore(name, topDir, FileIngestionMethod::Recursive, htSHA256, defaultPathFilter, NoRepair); + unpackedStorePath = store->addToStore(name, topDir, FileIngestionMethod::Recursive, HashType::SHA256, defaultPathFilter, NoRepair); } Attrs infoAttrs({ @@ -195,9 +195,9 @@ struct TarballInput : Input // NAR hashes are preferred over file hashes since tar/zip files // don't have a canonical representation. if (narHash) - url2.query.insert_or_assign("narHash", narHash->to_string(SRI)); + url2.query.insert_or_assign("narHash", narHash->to_string(Base::SRI)); else if (hash) - url2.query.insert_or_assign("hash", hash->to_string(SRI)); + url2.query.insert_or_assign("hash", hash->to_string(Base::SRI)); return url2; } @@ -206,7 +206,7 @@ struct TarballInput : Input Attrs attrs; attrs.emplace("url", url.to_string()); if (hash) - attrs.emplace("hash", hash->to_string(SRI)); + attrs.emplace("hash", hash->to_string(Base::SRI)); return attrs; } diff --git a/src/libmain/common-args.cc b/src/libmain/common-args.cc index 9a8f119a3..2bcad9f7b 100644 --- a/src/libmain/common-args.cc +++ b/src/libmain/common-args.cc @@ -6,72 +6,25 @@ namespace nix { MixCommonArgs::MixCommonArgs(const string & programName) : programName(programName) { -<<<<<<< HEAD - mkFlag() - .longName("verbose") - .shortName('v') - .description("increase verbosity level") - .handler([]() { verbosity = (Verbosity) ((uint64_t) verbosity + 1); }); - - mkFlag() - .longName("quiet") - .description("decrease verbosity level") - .handler([]() { verbosity = verbosity > Verbosity::Error - ? (Verbosity) ((uint64_t) verbosity - 1) - : Verbosity::Error; }); - - mkFlag() - .longName("debug") - .description("enable debug output") - .handler([]() { verbosity = Verbosity::Debug; }); - - mkFlag() - .longName("option") - .labels({"name", "value"}) - .description("set a Nix configuration option (overriding nix.conf)") - .arity(2) - .handler([](std::vector ss) { -||||||| merged common ancestors - mkFlag() - .longName("verbose") - .shortName('v') - .description("increase verbosity level") - .handler([]() { verbosity = (Verbosity) (verbosity + 1); }); - - mkFlag() - .longName("quiet") - .description("decrease verbosity level") - .handler([]() { verbosity = verbosity > lvlError ? (Verbosity) (verbosity - 1) : lvlError; }); - - mkFlag() - .longName("debug") - .description("enable debug output") - .handler([]() { verbosity = lvlDebug; }); - - mkFlag() - .longName("option") - .labels({"name", "value"}) - .description("set a Nix configuration option (overriding nix.conf)") - .arity(2) - .handler([](std::vector ss) { -======= addFlag({ .longName = "verbose", .shortName = 'v', .description = "increase verbosity level", - .handler = {[]() { verbosity = (Verbosity) (verbosity + 1); }}, + .handler = {[]() { verbosity = (Verbosity) ((uint64_t) verbosity + 1); }}, }); addFlag({ .longName = "quiet", .description = "decrease verbosity level", - .handler = {[]() { verbosity = verbosity > lvlError ? (Verbosity) (verbosity - 1) : lvlError; }}, + .handler = {[]() { verbosity = verbosity > Verbosity::Error + ? (Verbosity) ((uint64_t) verbosity - 1) + : Verbosity::Error; }}, }); addFlag({ .longName = "debug", .description = "enable debug output", - .handler = {[]() { verbosity = lvlDebug; }}, + .handler = {[]() { verbosity = Verbosity::Debug; }}, }); addFlag({ @@ -79,7 +32,6 @@ MixCommonArgs::MixCommonArgs(const string & programName) .description = "set a Nix configuration option (overriding nix.conf)", .labels = {"name", "value"}, .handler = {[](std::string name, std::string value) { ->>>>>>> f60ce4fa207a210e23a1142d3a8ead611526e6e1 try { globalConfig.set(name, value); } catch (UsageError & e) { diff --git a/src/libstore/build.cc b/src/libstore/build.cc index ad6ba41b5..ae7ba6549 100644 --- a/src/libstore/build.cc +++ b/src/libstore/build.cc @@ -1407,7 +1407,7 @@ void DerivationGoal::started() { "building '%s'", worker.store.printStorePath(drvPath), curRound, nrRounds); fmt("building '%s'", worker.store.printStorePath(drvPath)); if (hook) msg += fmt(" on '%s'", machineName); - act = std::make_unique(*logger, lvlInfo, actBuild, msg, + act = std::make_unique(*logger, Verbosity::Info, ActivityType::Build, msg, Logger::Fields{worker.store.printStorePath(drvPath), hook ? machineName : "", curRound, nrRounds}); mcRunningBuilds = std::make_unique>(worker.runningBuilds); worker.updateProgress(); diff --git a/src/libstore/filetransfer.cc b/src/libstore/filetransfer.cc index 6a1cf1be3..933c8038d 100644 --- a/src/libstore/filetransfer.cc +++ b/src/libstore/filetransfer.cc @@ -807,140 +807,6 @@ void FileTransfer::download(FileTransferRequest && request, Sink & sink) } } -CachedDownloadResult Downloader::downloadCached( - ref store, const CachedDownloadRequest & request) -{ - auto url = resolveUri(request.uri); - - auto name = request.name; - if (name == "") { - auto p = url.rfind('/'); - if (p != string::npos) name = string(url, p + 1); - } - - std::optional expectedStorePath; - if (request.expectedHash) { - expectedStorePath = store->makeFixedOutputPath(request.unpack, request.expectedHash, name); - if (store->isValidPath(*expectedStorePath)) { - CachedDownloadResult result; - result.storePath = store->printStorePath(*expectedStorePath); - result.path = store->toRealPath(result.storePath); - return result; - } - } - - Path cacheDir = getCacheDir() + "/nix/tarballs"; - createDirs(cacheDir); - - string urlHash = hashString(HashType::SHA256, name + std::string("\0"s) + url).to_string(Base::Base32, false); - - Path dataFile = cacheDir + "/" + urlHash + ".info"; - Path fileLink = cacheDir + "/" + urlHash + "-file"; - - PathLocks lock({fileLink}, fmt("waiting for lock on '%1%'...", fileLink)); - - std::optional storePath; - - string expectedETag; - - bool skip = false; - - CachedDownloadResult result; - - if (pathExists(fileLink) && pathExists(dataFile)) { - storePath = store->parseStorePath(readLink(fileLink)); - // FIXME - store->addTempRoot(*storePath); - if (store->isValidPath(*storePath)) { - auto ss = tokenizeString>(readFile(dataFile), "\n"); - if (ss.size() >= 3 && ss[0] == url) { - time_t lastChecked; - if (string2Int(ss[2], lastChecked) && (uint64_t) lastChecked + request.ttl >= (uint64_t) time(0)) { - skip = true; - result.effectiveUri = request.uri; - result.etag = ss[1]; - } else if (!ss[1].empty()) { - debug(format("verifying previous ETag '%1%'") % ss[1]); - expectedETag = ss[1]; - } - } - } else - storePath.reset(); - } - - if (!skip) { - - try { - DownloadRequest request2(url); - request2.expectedETag = expectedETag; - auto res = download(request2); - result.effectiveUri = res.effectiveUri; - result.etag = res.etag; - - if (!res.cached) { - StringSink sink; - dumpString(*res.data, sink); - Hash hash = hashString(request.expectedHash ? request.expectedHash.type : HashType::SHA256, *res.data); - ValidPathInfo info(store->makeFixedOutputPath(false, hash, name)); - info.narHash = hashString(HashType::SHA256, *sink.s); - info.narSize = sink.s->size(); - info.ca = makeFixedOutputCA(false, hash); - store->addToStore(info, sink.s, NoRepair, NoCheckSigs); - storePath = info.path.clone(); - } - - assert(storePath); - replaceSymlink(store->printStorePath(*storePath), fileLink); - - writeFile(dataFile, url + "\n" + res.etag + "\n" + std::to_string(time(0)) + "\n"); - } catch (DownloadError & e) { - if (!storePath) throw; - warn("warning: %s; using cached result", e.msg()); - result.etag = expectedETag; - } - } - - if (request.unpack) { - Path unpackedLink = cacheDir + "/" + ((std::string) storePath->to_string()) + "-unpacked"; - PathLocks lock2({unpackedLink}, fmt("waiting for lock on '%1%'...", unpackedLink)); - std::optional unpackedStorePath; - if (pathExists(unpackedLink)) { - unpackedStorePath = store->parseStorePath(readLink(unpackedLink)); - // FIXME - store->addTempRoot(*unpackedStorePath); - if (!store->isValidPath(*unpackedStorePath)) - unpackedStorePath.reset(); - } - if (!unpackedStorePath) { - printInfo("unpacking '%s'...", url); - Path tmpDir = createTempDir(); - AutoDelete autoDelete(tmpDir, true); - unpackTarfile(store->toRealPath(store->printStorePath(*storePath)), tmpDir); - auto members = readDirectory(tmpDir); - if (members.size() != 1) - throw nix::Error("tarball '%s' contains an unexpected number of top-level files", url); - auto topDir = tmpDir + "/" + members.begin()->name; - unpackedStorePath = store->addToStore(name, topDir, true, HashType::SHA256, defaultPathFilter, NoRepair); - } - replaceSymlink(store->printStorePath(*unpackedStorePath), unpackedLink); - storePath = std::move(*unpackedStorePath); - } - - if (expectedStorePath && *storePath != *expectedStorePath) { - unsigned int statusCode = 102; - Hash gotHash = request.unpack - ? hashPath(request.expectedHash.type, store->toRealPath(store->printStorePath(*storePath))).first - : hashFile(request.expectedHash.type, store->toRealPath(store->printStorePath(*storePath))); - throw nix::Error(statusCode, "hash mismatch in file downloaded from '%s':\n wanted: %s\n got: %s", - url, request.expectedHash.to_string(), gotHash.to_string()); - } - - result.storePath = store->printStorePath(*storePath); - result.path = store->toRealPath(result.storePath); - return result; -} - - bool isUri(const string & s) { if (s.compare(0, 8, "channel:") == 0) return true; diff --git a/src/libutil/tests/hash.cc b/src/libutil/tests/hash.cc index 7cb439817..c513ce4ac 100644 --- a/src/libutil/tests/hash.cc +++ b/src/libutil/tests/hash.cc @@ -10,28 +10,28 @@ namespace nix { TEST(hashString, testKnownMD5Hashes1) { // values taken from: https://tools.ietf.org/html/rfc1321 auto s1 = ""; - auto hash = hashString(HashType::htMD5, s1); + auto hash = hashString(HashType::MD5, s1); ASSERT_EQ(hash.to_string(Base::Base16), "md5:d41d8cd98f00b204e9800998ecf8427e"); } TEST(hashString, testKnownMD5Hashes2) { // values taken from: https://tools.ietf.org/html/rfc1321 auto s2 = "abc"; - auto hash = hashString(HashType::htMD5, s2); + auto hash = hashString(HashType::MD5, s2); ASSERT_EQ(hash.to_string(Base::Base16), "md5:900150983cd24fb0d6963f7d28e17f72"); } TEST(hashString, testKnownSHA1Hashes1) { // values taken from: https://tools.ietf.org/html/rfc3174 auto s = "abc"; - auto hash = hashString(HashType::htSHA1, s); + auto hash = hashString(HashType::SHA1, s); ASSERT_EQ(hash.to_string(Base::Base16),"sha1:a9993e364706816aba3e25717850c26c9cd0d89d"); } TEST(hashString, testKnownSHA1Hashes2) { // values taken from: https://tools.ietf.org/html/rfc3174 auto s = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"; - auto hash = hashString(HashType::htSHA1, s); + auto hash = hashString(HashType::SHA1, s); ASSERT_EQ(hash.to_string(Base::Base16),"sha1:84983e441c3bd26ebaae4aa1f95129e5e54670f1"); } @@ -39,7 +39,7 @@ namespace nix { // values taken from: https://tools.ietf.org/html/rfc4634 auto s = "abc"; - auto hash = hashString(HashType::htSHA256, s); + auto hash = hashString(HashType::SHA256, s); ASSERT_EQ(hash.to_string(Base::Base16), "sha256:ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad"); } @@ -47,7 +47,7 @@ namespace nix { TEST(hashString, testKnownSHA256Hashes2) { // values taken from: https://tools.ietf.org/html/rfc4634 auto s = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"; - auto hash = hashString(HashType::htSHA256, s); + auto hash = hashString(HashType::SHA256, s); ASSERT_EQ(hash.to_string(Base::Base16), "sha256:248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1"); } @@ -55,7 +55,7 @@ namespace nix { TEST(hashString, testKnownSHA512Hashes1) { // values taken from: https://tools.ietf.org/html/rfc4634 auto s = "abc"; - auto hash = hashString(HashType::htSHA512, s); + auto hash = hashString(HashType::SHA512, s); ASSERT_EQ(hash.to_string(Base::Base16), "sha512:ddaf35a193617abacc417349ae20413112e6fa4e89a9" "7ea20a9eeee64b55d39a2192992a274fc1a836ba3c23a3feebbd" @@ -66,7 +66,7 @@ namespace nix { // values taken from: https://tools.ietf.org/html/rfc4634 auto s = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu"; - auto hash = hashString(HashType::htSHA512, s); + auto hash = hashString(HashType::SHA512, s); ASSERT_EQ(hash.to_string(Base::Base16), "sha512:8e959b75dae313da8cf4f72814fc143f8f7779c6eb9f7fa1" "7299aeadb6889018501d289e4900f7e4331b99dec4b5433a" @@ -75,6 +75,6 @@ namespace nix { TEST(hashString, hashingWithUnknownAlgoExits) { auto s = "unknown"; - ASSERT_DEATH(hashString(HashType::htUnknown, s), ""); + ASSERT_DEATH(hashString(HashType::Unknown, s), ""); } } -- cgit v1.2.3 From 0e9438b6d381a87946ddda8d4bdd06707f9b0a48 Mon Sep 17 00:00:00 2001 From: Carlo Nucera Date: Mon, 1 Jun 2020 17:32:27 -0400 Subject: Create new file-hash files --- src/libstore/derivations.cc | 5 ----- src/libstore/derivations.hh | 15 +-------------- src/libstore/file-hash.cc | 27 +++++++++++++++++++++++++++ src/libstore/file-hash.hh | 34 ++++++++++++++++++++++++++++++++++ src/libstore/path.hh | 5 ----- src/libstore/store-api.cc | 19 ------------------- src/libstore/store-api.hh | 10 +--------- src/nix/hash.cc | 1 + 8 files changed, 64 insertions(+), 52 deletions(-) create mode 100644 src/libstore/file-hash.cc create mode 100644 src/libstore/file-hash.hh diff --git a/src/libstore/derivations.cc b/src/libstore/derivations.cc index ad4d02c2c..f1569bf22 100644 --- a/src/libstore/derivations.cc +++ b/src/libstore/derivations.cc @@ -8,11 +8,6 @@ namespace nix { -std::string FileSystemHash::printMethodAlgo() const { - return makeFileIngestionPrefix(method) + printHashType(hash.type); -} - - BasicDerivation::BasicDerivation(const BasicDerivation & other) : platform(other.platform) , builder(other.builder) diff --git a/src/libstore/derivations.hh b/src/libstore/derivations.hh index 5fc3b37da..e314beac1 100644 --- a/src/libstore/derivations.hh +++ b/src/libstore/derivations.hh @@ -3,6 +3,7 @@ #include "path.hh" #include "types.hh" #include "hash.hh" +#include "file-hash.hh" #include @@ -12,20 +13,6 @@ namespace nix { /* Abstract syntax of derivations. */ -/// Pair of a hash, and how the file system was ingested -struct FileSystemHash { - FileIngestionMethod method; - Hash hash; - FileSystemHash(FileIngestionMethod method, Hash hash) - : method(std::move(method)) - , hash(std::move(hash)) - { } - FileSystemHash(const FileSystemHash &) = default; - FileSystemHash(FileSystemHash &&) = default; - FileSystemHash & operator = (const FileSystemHash &) = default; - std::string printMethodAlgo() const; -}; - struct DerivationOutput { StorePath path; diff --git a/src/libstore/file-hash.cc b/src/libstore/file-hash.cc new file mode 100644 index 000000000..549540db2 --- /dev/null +++ b/src/libstore/file-hash.cc @@ -0,0 +1,27 @@ +#include "file-hash.hh" + +namespace nix { + +std::string FileSystemHash::printMethodAlgo() const { + return makeFileIngestionPrefix(method) + printHashType(hash.type); +} + +std::string makeFileIngestionPrefix(const FileIngestionMethod m) { + switch (m) { + case FileIngestionMethod::Flat: + return ""; + case FileIngestionMethod::Recursive: + return "r:"; + default: + throw Error("impossible, caught both cases"); + } +} + +std::string makeFixedOutputCA(FileIngestionMethod method, const Hash & hash) +{ + return "fixed:" + + makeFileIngestionPrefix(method) + + hash.to_string(); +} + +} diff --git a/src/libstore/file-hash.hh b/src/libstore/file-hash.hh new file mode 100644 index 000000000..94122db07 --- /dev/null +++ b/src/libstore/file-hash.hh @@ -0,0 +1,34 @@ +#pragma once + +#include "hash.hh" + +namespace nix { + +enum struct FileIngestionMethod : uint8_t { + Flat = false, + Recursive = true +}; + +/// Pair of a hash, and how the file system was ingested +struct FileSystemHash { + FileIngestionMethod method; + Hash hash; + FileSystemHash(FileIngestionMethod method, Hash hash) + : method(std::move(method)) + , hash(std::move(hash)) + { } + FileSystemHash(const FileSystemHash &) = default; + FileSystemHash(FileSystemHash &&) = default; + FileSystemHash & operator = (const FileSystemHash &) = default; + std::string printMethodAlgo() const; +}; + +/* Compute the prefix to the hash algorithm which indicates how the files were + ingested. */ +std::string makeFileIngestionPrefix(const FileIngestionMethod m); + +/* Compute the content-addressability assertion (ValidPathInfo::ca) + for paths created by makeFixedOutputPath() / addToStore(). */ +std::string makeFixedOutputCA(FileIngestionMethod method, const Hash & hash); + +} diff --git a/src/libstore/path.hh b/src/libstore/path.hh index f3ed6ca39..186976855 100644 --- a/src/libstore/path.hh +++ b/src/libstore/path.hh @@ -87,11 +87,6 @@ const size_t storePathHashLen = 32; // i.e. 160 bits /* Extension of derivations in the Nix store. */ const std::string drvExtension = ".drv"; -enum struct FileIngestionMethod : uint8_t { - Flat = false, - Recursive = true -}; - struct StorePathWithOutputs { StorePath path; diff --git a/src/libstore/store-api.cc b/src/libstore/store-api.cc index b7ba9e4f2..3c72dc56f 100644 --- a/src/libstore/store-api.cc +++ b/src/libstore/store-api.cc @@ -814,25 +814,6 @@ Strings ValidPathInfo::shortRefs() const } -std::string makeFileIngestionPrefix(const FileIngestionMethod m) { - switch (m) { - case FileIngestionMethod::Flat: - return ""; - case FileIngestionMethod::Recursive: - return "r:"; - default: - throw Error("impossible, caught both cases"); - } -} - -std::string makeFixedOutputCA(FileIngestionMethod method, const Hash & hash) -{ - return "fixed:" - + makeFileIngestionPrefix(method) - + hash.to_string(); -} - - void Store::addToStore(const ValidPathInfo & info, Source & narSource, RepairFlag repair, CheckSigsFlag checkSigs, std::shared_ptr accessor) diff --git a/src/libstore/store-api.hh b/src/libstore/store-api.hh index 598798570..d89e10c94 100644 --- a/src/libstore/store-api.hh +++ b/src/libstore/store-api.hh @@ -2,6 +2,7 @@ #include "path.hh" #include "hash.hh" +#include "file-hash.hh" #include "serialise.hh" #include "crypto.hh" #include "lru-cache.hh" @@ -846,15 +847,6 @@ std::optional decodeValidPathInfo( std::istream & str, bool hashGiven = false); -/* Compute the prefix to the hash algorithm which indicates how the files were - ingested. */ -std::string makeFileIngestionPrefix(const FileIngestionMethod m); - -/* Compute the content-addressability assertion (ValidPathInfo::ca) - for paths created by makeFixedOutputPath() / addToStore(). */ -std::string makeFixedOutputCA(FileIngestionMethod method, const Hash & hash); - - /* Split URI into protocol+hierarchy part and its parameter set. */ std::pair splitUriAndParams(const std::string & uri); diff --git a/src/nix/hash.cc b/src/nix/hash.cc index 3362ffd0d..ec23b77bc 100644 --- a/src/nix/hash.cc +++ b/src/nix/hash.cc @@ -1,5 +1,6 @@ #include "command.hh" #include "hash.hh" +#include "file-hash.hh" #include "legacy.hh" #include "shared.hh" #include "references.hh" -- cgit v1.2.3 From da39092a39bbcca80144041b5efc8428cc3b2e4a Mon Sep 17 00:00:00 2001 From: Carlo Nucera Date: Mon, 1 Jun 2020 18:53:31 -0400 Subject: WIP --- src/libstore/file-hash.hh | 17 +++++++++++++++++ src/libstore/path.hh | 10 ++++++++++ src/libstore/store-api.cc | 2 +- src/libstore/store-api.hh | 32 ++++++++++++++++++-------------- src/nix-store/nix-store.cc | 2 +- 5 files changed, 47 insertions(+), 16 deletions(-) diff --git a/src/libstore/file-hash.hh b/src/libstore/file-hash.hh index 94122db07..9d2b78688 100644 --- a/src/libstore/file-hash.hh +++ b/src/libstore/file-hash.hh @@ -1,5 +1,6 @@ #pragma once +#include #include "hash.hh" namespace nix { @@ -23,6 +24,22 @@ struct FileSystemHash { std::string printMethodAlgo() const; }; +/* + We've accumulated several types of content-addressed paths over the years; + fixed-output derivations support multiple hash algorithms and serialisation + methods (flat file vs NAR). Thus, ‘ca’ has one of the following forms: + + * ‘text:sha256:’: For paths + computed by makeTextPath() / addTextToStore(). + + * ‘fixed:::’: For paths computed by + makeFixedOutputPath() / addToStore(). +*/ +typedef std::variant< + Hash, // for paths computed by makeTextPath() / addTextToStore + FileSystemHash // for path computed by makeFixedOutputPath +> ContentAddress; + /* Compute the prefix to the hash algorithm which indicates how the files were ingested. */ std::string makeFileIngestionPrefix(const FileIngestionMethod m); diff --git a/src/libstore/path.hh b/src/libstore/path.hh index 186976855..5268b3bbf 100644 --- a/src/libstore/path.hh +++ b/src/libstore/path.hh @@ -1,6 +1,7 @@ #pragma once #include "rust-ffi.hh" +#include "file-hash.hh" namespace nix { @@ -87,6 +88,15 @@ 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.cc b/src/libstore/store-api.cc index 3c72dc56f..0a36dcb2b 100644 --- a/src/libstore/store-api.cc +++ b/src/libstore/store-api.cc @@ -467,7 +467,7 @@ void Store::pathInfoToJSON(JSONPlaceholder & jsonOut, const StorePathSet & store jsonRefs.elem(printStorePath(ref)); } - if (info->ca != "") + if (info->ca) jsonPath.attr("ca", info->ca); std::pair closureSizes; diff --git a/src/libstore/store-api.hh b/src/libstore/store-api.hh index d89e10c94..1f1c1e0eb 100644 --- a/src/libstore/store-api.hh +++ b/src/libstore/store-api.hh @@ -19,6 +19,7 @@ #include #include #include +#include namespace nix { @@ -110,6 +111,19 @@ struct SubstitutablePathInfo typedef std::map SubstitutablePathInfos; +template struct overloaded : Ts... { using Ts::operator()...; }; +template overloaded(Ts...) -> overloaded; + +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 { @@ -139,21 +153,11 @@ struct ValidPathInfo that a particular output path was produced by a derivation; the path then implies the contents.) - Ideally, the content-addressability assertion would just be a - Boolean, and the store path would be computed from - the name component, ‘narHash’ and ‘references’. However, - 1) we've accumulated several types of content-addressed paths - over the years; and 2) fixed-output derivations support - multiple hash algorithms and serialisation methods (flat file - vs NAR). Thus, ‘ca’ has one of the following forms: - - * ‘text:sha256:’: For paths - computed by makeTextPath() / addTextToStore(). - - * ‘fixed:::’: For paths computed by - makeFixedOutputPath() / addToStore(). + Ideally, the content-addressability assertion would just be a Boolean, + and the store path would be computed from the name component, ‘narHash’ + and ‘references’. However, we support many types of content addresses. */ - std::string ca; + std::optional ca; bool operator == (const ValidPathInfo & i) const { diff --git a/src/nix-store/nix-store.cc b/src/nix-store/nix-store.cc index ace593cde..6f3a59002 100644 --- a/src/nix-store/nix-store.cc +++ b/src/nix-store/nix-store.cc @@ -856,7 +856,7 @@ static void opServe(Strings opFlags, Strings opArgs) out << info->narSize // downloadSize << info->narSize; if (GET_PROTOCOL_MINOR(clientVersion) >= 4) - out << (info->narHash ? info->narHash.to_string() : "") << info->ca << info->sigs; + out << (info->narHash ? info->narHash.to_string() : "") << renderContentAddress(info->ca) << info->sigs; } catch (InvalidPath &) { } } -- cgit v1.2.3 From 754c910953901ced4fbd27a8b86d36d57cb72996 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Mon, 1 Jun 2020 19:26:40 -0400 Subject: WIP more progress --- src/libstore/file-hash.cc | 18 ++++++++++++++++++ src/libstore/file-hash.hh | 10 +++++++++- src/libstore/path.hh | 9 --------- src/libstore/store-api.hh | 14 -------------- src/libutil/tests/libutil-tests | Bin 14929616 -> 14929616 bytes src/nix/path-info.cc | 2 +- 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 struct overloaded : Ts... { using Ts::operator()...; }; +template overloaded(Ts...) -> overloaded; + +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
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 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 SubstitutablePathInfos; -template struct overloaded : Ts... { using Ts::operator()...; }; -template overloaded(Ts...) -> overloaded; - -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 Binary files a/src/libutil/tests/libutil-tests and b/src/libutil/tests/libutil-tests 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); } -- cgit v1.2.3 From efcd30da891eccdb3518e9c07afc6f907e9ac5e6 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Tue, 2 Jun 2020 00:37:43 +0000 Subject: WIP --- src/libfetchers/tarball.cc | 5 ++++- src/libstore/build.cc | 12 +++++++++--- src/libstore/daemon.cc | 9 +++++++-- src/libstore/file-hash.cc | 12 ++++++++++-- src/libstore/file-hash.hh | 7 +++++++ src/libstore/legacy-ssh-store.cc | 8 ++++++-- src/libstore/local-store.cc | 23 ++++++++++++----------- src/libstore/nar-info-disk-cache.cc | 4 ++-- src/libstore/nar-info.cc | 9 +++++---- src/libstore/remote-store.cc | 6 ++++-- src/libstore/store-api.cc | 15 +++++++-------- src/libutil/tests/libutil-tests | Bin 14929616 -> 0 bytes src/nix-store/nix-store.cc | 6 +++++- src/nix/add-to-store.cc | 5 ++++- src/nix/make-content-addressable.cc | 5 ++++- src/nix/path-info.cc | 2 +- src/nix/verify.cc | 2 +- 17 files changed, 88 insertions(+), 42 deletions(-) delete mode 100755 src/libutil/tests/libutil-tests diff --git a/src/libfetchers/tarball.cc b/src/libfetchers/tarball.cc index 3e9004223..8efb8d68c 100644 --- a/src/libfetchers/tarball.cc +++ b/src/libfetchers/tarball.cc @@ -70,7 +70,10 @@ DownloadFileResult downloadFile( ValidPathInfo info(store->makeFixedOutputPath(FileIngestionMethod::Flat, hash, name)); info.narHash = hashString(HashType::SHA256, *sink.s); info.narSize = sink.s->size(); - info.ca = makeFixedOutputCA(FileIngestionMethod::Flat, hash); + info.ca = FileSystemHash { + .method = FileIngestionMethod::Flat, + .hash = hash, + }; store->addToStore(info, sink.s, NoRepair, NoCheckSigs); storePath = std::move(info.path); } diff --git a/src/libstore/build.cc b/src/libstore/build.cc index e35044532..7f79d6a2a 100644 --- a/src/libstore/build.cc +++ b/src/libstore/build.cc @@ -3708,7 +3708,7 @@ void DerivationGoal::registerOutputs() /* Check that fixed-output derivations produced the right outputs (i.e., the content hash should match the specified hash). */ - std::string ca; + std::optional ca; if (fixedOutput) { @@ -3757,7 +3757,10 @@ void DerivationGoal::registerOutputs() else assert(worker.store.parseStorePath(path) == dest); - ca = makeFixedOutputCA(i.second.hash->method, h2); + ca = FileSystemHash { + .method = i.second.hash->method, + .hash = h2, + }; } /* Get rid of all weird permissions. This also checks that @@ -3830,7 +3833,10 @@ void DerivationGoal::registerOutputs() info.ca = ca; worker.store.signPathInfo(info); - if (!info.references.empty()) info.ca.clear(); + if (!info.references.empty()) { + // FIXME don't we have an experimental feature for fixed output with references? + info.ca = {}; + } infos.emplace(i.first, std::move(info)); } diff --git a/src/libstore/daemon.cc b/src/libstore/daemon.cc index 1f950de63..45bfa6753 100644 --- a/src/libstore/daemon.cc +++ b/src/libstore/daemon.cc @@ -650,7 +650,7 @@ static void performOp(TunnelLogger * logger, ref store, if (GET_PROTOCOL_MINOR(clientVersion) >= 16) { to << info->ultimate << info->sigs - << info->ca; + << renderContentAddress(info->ca); } } else { assert(GET_PROTOCOL_MINOR(clientVersion) >= 17); @@ -708,7 +708,12 @@ static void performOp(TunnelLogger * logger, ref store, info.references = readStorePaths(*store, from); from >> info.registrationTime >> info.narSize >> info.ultimate; info.sigs = readStrings(from); - from >> info.ca >> repair >> dontCheckSigs; + { + string caOptRaw; + from >> caOptRaw; + info.ca = parseCaOpt(caOptRaw); + } + from >> repair >> dontCheckSigs; if (!trusted && dontCheckSigs) dontCheckSigs = false; if (!trusted) diff --git a/src/libstore/file-hash.cc b/src/libstore/file-hash.cc index ebd732759..494079c18 100644 --- a/src/libstore/file-hash.cc +++ b/src/libstore/file-hash.cc @@ -38,8 +38,16 @@ std::string renderContentAddress(ContentAddress ca) { }, ca); } -std::string renderContentAddress(std::optionalContent
ca) { - return ca ? renderContentAddress(*ca) else ""; +ContentAddress parseCa(std::string_view rawCa) { + throw Error("TODO"); +}; + +std::optional parseCaOpt(std::string_view rawCaOpt) { + return rawCaOpt == "" ? std::optional {} : parseCa(rawCaOpt); +}; + +std::string renderContentAddress(std::optional ca) { + return ca ? renderContentAddress(*ca) : ""; } } diff --git a/src/libstore/file-hash.hh b/src/libstore/file-hash.hh index e33878bf9..9d12f5fe7 100644 --- a/src/libstore/file-hash.hh +++ b/src/libstore/file-hash.hh @@ -12,6 +12,9 @@ enum struct FileIngestionMethod : uint8_t { struct TextHash { Hash hash; + TextHash(const TextHash &) = default; + TextHash(TextHash &&) = default; + TextHash & operator = (const TextHash &) = default; }; /// Pair of a hash, and how the file system was ingested @@ -56,4 +59,8 @@ std::string renderContentAddress(ContentAddress ca); std::string renderContentAddress(std::optional ca); +ContentAddress parseCa(std::string_view rawCa); + +std::optional parseCaOpt(std::string_view rawCaOpt); + } diff --git a/src/libstore/legacy-ssh-store.cc b/src/libstore/legacy-ssh-store.cc index 61e7603b7..8471ed073 100644 --- a/src/libstore/legacy-ssh-store.cc +++ b/src/libstore/legacy-ssh-store.cc @@ -114,7 +114,11 @@ struct LegacySSHStore : public Store if (GET_PROTOCOL_MINOR(conn->remoteVersion) >= 4) { auto s = readString(conn->from); info->narHash = s.empty() ? Hash() : Hash(s); - conn->from >> info->ca; + { + std::string rawCaOpt; + conn->from >> rawCaOpt; + info->ca = parseCaOpt(rawCaOpt); + } info->sigs = readStrings(conn->from); } @@ -146,7 +150,7 @@ struct LegacySSHStore : public Store << info.narSize << info.ultimate << info.sigs - << info.ca; + << renderContentAddress(info.ca); try { copyNAR(source, conn->to); } catch (...) { diff --git a/src/libstore/local-store.cc b/src/libstore/local-store.cc index 9b60bf887..fe346f96a 100644 --- a/src/libstore/local-store.cc +++ b/src/libstore/local-store.cc @@ -576,7 +576,7 @@ void LocalStore::checkDerivationOutputs(const StorePath & drvPath, const Derivat uint64_t LocalStore::addValidPath(State & state, const ValidPathInfo & info, bool checkOutputs) { - if (info.ca != "" && !info.isContentAddressed(*this)) + if (info.ca && !info.isContentAddressed(*this)) throw Error("cannot add path '%s' to the Nix store because it claims to be content-addressed but isn't", printStorePath(info.path)); @@ -588,7 +588,7 @@ uint64_t LocalStore::addValidPath(State & state, (info.narSize, info.narSize != 0) (info.ultimate ? 1 : 0, info.ultimate) (concatStringsSep(" ", info.sigs), !info.sigs.empty()) - (info.ca, !info.ca.empty()) + (renderContentAddress(info.ca), (bool) info.ca) .exec(); uint64_t id = sqlite3_last_insert_rowid(state.db); @@ -662,7 +662,7 @@ void LocalStore::queryPathInfoUncached(const StorePath & path, if (s) info->sigs = tokenizeString(s, " "); s = (const char *) sqlite3_column_text(state->stmtQueryPathInfo, 7); - if (s) info->ca = s; + if (s) info->ca = parseCaOpt(s); /* Get the references. */ auto useQueryReferences(state->stmtQueryReferences.use()(info->id)); @@ -685,7 +685,7 @@ void LocalStore::updatePathInfo(State & state, const ValidPathInfo & info) (info.narHash.to_string(Base::Base16)) (info.ultimate ? 1 : 0, info.ultimate) (concatStringsSep(" ", info.sigs), !info.sigs.empty()) - (info.ca, !info.ca.empty()) + (renderContentAddress(info.ca), (bool) info.ca) (printStorePath(info.path)) .exec(); } @@ -999,15 +999,13 @@ void LocalStore::addToStore(const ValidPathInfo & info, Source & source, deletePath(realPath); - if (info.ca != "" && - !((hasPrefix(info.ca, "text:") && !info.references.count(info.path)) - || info.references.empty())) + if (info.ca && !info.references.empty() && !std::holds_alternative(*info.ca)) settings.requireExperimentalFeature("ca-references"); /* While restoring the path from the NAR, compute the hash of the NAR. */ std::unique_ptr hashSink; - if (info.ca == "" || !info.references.count(info.path)) + if (info.ca || !info.references.count(info.path)) hashSink = std::make_unique(HashType::SHA256); else hashSink = std::make_unique(HashType::SHA256, storePathToHash(printStorePath(info.path))); @@ -1093,7 +1091,10 @@ StorePath LocalStore::addToStoreFromDump(const string & dump, const string & nam ValidPathInfo info(dstPath.clone()); info.narHash = hash.first; info.narSize = hash.second; - info.ca = makeFixedOutputCA(method, h); + info.ca = FileSystemHash { + .method = method, + .hash = h, + }; registerValidPath(info); } @@ -1157,7 +1158,7 @@ StorePath LocalStore::addTextToStore(const string & name, const string & s, info.narHash = narHash; info.narSize = sink.s->size(); info.references = cloneStorePathSet(references); - info.ca = "text:" + hash.to_string(); + info.ca = TextHash { .hash = hash }; registerValidPath(info); } @@ -1265,7 +1266,7 @@ bool LocalStore::verifyStore(bool checkContents, RepairFlag repair) printMsg(Verbosity::Talkative, "checking contents of '%s'", printStorePath(i)); std::unique_ptr hashSink; - if (info->ca == "" || !info->references.count(info->path)) + if (info->ca || !info->references.count(info->path)) hashSink = std::make_unique(info->narHash.type); else hashSink = std::make_unique(info->narHash.type, storePathToHash(printStorePath(info->path))); diff --git a/src/libstore/nar-info-disk-cache.cc b/src/libstore/nar-info-disk-cache.cc index 442541330..b4346d4d1 100644 --- a/src/libstore/nar-info-disk-cache.cc +++ b/src/libstore/nar-info-disk-cache.cc @@ -203,7 +203,7 @@ public: narInfo->deriver = StorePath::fromBaseName(queryNAR.getStr(9)); for (auto & sig : tokenizeString(queryNAR.getStr(10), " ")) narInfo->sigs.insert(sig); - narInfo->ca = queryNAR.getStr(11); + narInfo->ca = parseCaOpt(queryNAR.getStr(11)); return {oValid, narInfo}; }); @@ -237,7 +237,7 @@ public: (concatStringsSep(" ", info->shortRefs())) (info->deriver ? std::string(info->deriver->to_string()) : "", (bool) info->deriver) (concatStringsSep(" ", info->sigs)) - (info->ca) + (renderContentAddress(info->ca)) (time(0)).exec(); } else { diff --git a/src/libstore/nar-info.cc b/src/libstore/nar-info.cc index 8592ee968..4f7c732ce 100644 --- a/src/libstore/nar-info.cc +++ b/src/libstore/nar-info.cc @@ -67,8 +67,9 @@ NarInfo::NarInfo(const Store & store, const std::string & s, const std::string & else if (name == "Sig") sigs.insert(value); else if (name == "CA") { - if (!ca.empty()) corrupt(); - ca = value; + if (ca) corrupt(); + // FIXME: allow blank ca or require skipping field? + ca = parseCaOpt(value); } pos = eol + 1; @@ -104,8 +105,8 @@ std::string NarInfo::to_string(const Store & store) const for (auto sig : sigs) res += "Sig: " + sig + "\n"; - if (!ca.empty()) - res += "CA: " + ca + "\n"; + if (ca) + res += "CA: " + renderContentAddress(*ca) + "\n"; return res; } diff --git a/src/libstore/remote-store.cc b/src/libstore/remote-store.cc index 2037a55f4..2744245f3 100644 --- a/src/libstore/remote-store.cc +++ b/src/libstore/remote-store.cc @@ -381,7 +381,9 @@ void RemoteStore::queryPathInfoUncached(const StorePath & path, if (GET_PROTOCOL_MINOR(conn->daemonVersion) >= 16) { conn->from >> info->ultimate; info->sigs = readStrings(conn->from); - conn->from >> info->ca; + string caOptRaw; + conn->from >> caOptRaw; + info->ca = parseCaOpt(caOptRaw); } } callback(std::move(info)); @@ -474,7 +476,7 @@ void RemoteStore::addToStore(const ValidPathInfo & info, Source & source, << info.narHash.to_string(Base::Base16, false); writeStorePaths(*this, conn->to, info.references); conn->to << info.registrationTime << info.narSize - << info.ultimate << info.sigs << info.ca + << info.ultimate << info.sigs << renderContentAddress(info.ca) << repair << !checkSigs; bool tunnel = GET_PROTOCOL_MINOR(conn->daemonVersion) >= 21; if (!tunnel) copyNAR(source, conn->to); diff --git a/src/libstore/store-api.cc b/src/libstore/store-api.cc index 0a36dcb2b..0715f64f3 100644 --- a/src/libstore/store-api.cc +++ b/src/libstore/store-api.cc @@ -468,7 +468,7 @@ void Store::pathInfoToJSON(JSONPlaceholder & jsonOut, const StorePathSet & store } if (info->ca) - jsonPath.attr("ca", info->ca); + jsonPath.attr("ca", renderContentAddress(info->ca)); std::pair closureSizes; @@ -760,24 +760,23 @@ bool ValidPathInfo::isContentAddressed(const Store & store) const printError("warning: path '%s' claims to be content-addressed but isn't", store.printStorePath(path)); }; - if (hasPrefix(ca, "text:")) { - Hash hash(std::string(ca, 5)); - if (store.makeTextPath(path.name(), hash, references) == path) + if (! ca) {} + + else if (auto p = std::get_if(&*ca)) { + if (store.makeTextPath(path.name(), p->hash, references) == path) return true; else warn(); } - else if (hasPrefix(ca, "fixed:")) { - FileIngestionMethod recursive { ca.compare(6, 2, "r:") == 0 }; - Hash hash(std::string(ca, recursive == FileIngestionMethod::Recursive ? 8 : 6)); + else if (auto p = std::get_if(&*ca)) { auto refs = cloneStorePathSet(references); bool hasSelfReference = false; if (refs.count(path)) { hasSelfReference = true; refs.erase(path); } - if (store.makeFixedOutputPath(recursive, hash, path.name(), refs, hasSelfReference) == path) + if (store.makeFixedOutputPath(p->method, p->hash, path.name(), refs, hasSelfReference) == path) return true; else warn(); diff --git a/src/libutil/tests/libutil-tests b/src/libutil/tests/libutil-tests deleted file mode 100755 index a4f9bbbc1..000000000 Binary files a/src/libutil/tests/libutil-tests and /dev/null differ diff --git a/src/nix-store/nix-store.cc b/src/nix-store/nix-store.cc index 6f3a59002..64ee9fd45 100644 --- a/src/nix-store/nix-store.cc +++ b/src/nix-store/nix-store.cc @@ -944,7 +944,11 @@ static void opServe(Strings opFlags, Strings opArgs) info.references = readStorePaths(*store, in); in >> info.registrationTime >> info.narSize >> info.ultimate; info.sigs = readStrings(in); - in >> info.ca; + { + std::string rawCA; + in >> rawCA; + info.ca = parseCaOpt(rawCA); + } if (info.narSize == 0) throw Error("narInfo is too old and missing the narSize field"); diff --git a/src/nix/add-to-store.cc b/src/nix/add-to-store.cc index 39d49721a..dc34a83ca 100644 --- a/src/nix/add-to-store.cc +++ b/src/nix/add-to-store.cc @@ -48,7 +48,10 @@ struct CmdAddToStore : MixDryRun, StoreCommand ValidPathInfo info(store->makeFixedOutputPath(FileIngestionMethod::Recursive, narHash, *namePart)); info.narHash = narHash; info.narSize = sink.s->size(); - info.ca = makeFixedOutputCA(FileIngestionMethod::Recursive, info.narHash); + *info.ca = FileSystemHash { + .method = FileIngestionMethod::Recursive, + .hash = info.narHash + }; if (!dryRun) store->addToStore(info, sink.s); diff --git a/src/nix/make-content-addressable.cc b/src/nix/make-content-addressable.cc index bd948a983..5003ff459 100644 --- a/src/nix/make-content-addressable.cc +++ b/src/nix/make-content-addressable.cc @@ -82,7 +82,10 @@ struct CmdMakeContentAddressable : StorePathsCommand, MixJSON if (hasSelfReference) info.references.insert(info.path.clone()); info.narHash = narHash; info.narSize = sink.s->size(); - info.ca = makeFixedOutputCA(FileIngestionMethod::Recursive, info.narHash); + info.ca = FileSystemHash { + .method = FileIngestionMethod::Recursive, + .hash = info.narHash, + }; if (!json) printError("rewrote '%s' to '%s'", pathS, store->printStorePath(info.path)); diff --git a/src/nix/path-info.cc b/src/nix/path-info.cc index ffe07a3ee..cda371129 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:" + renderContentAddress(*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); } diff --git a/src/nix/verify.cc b/src/nix/verify.cc index 0c3478ff5..d8636435c 100644 --- a/src/nix/verify.cc +++ b/src/nix/verify.cc @@ -87,7 +87,7 @@ struct CmdVerify : StorePathsCommand if (!noContents) { std::unique_ptr hashSink; - if (info->ca == "") + if (info->ca) hashSink = std::make_unique(info->narHash.type); else hashSink = std::make_unique(info->narHash.type, storePathToHash(store->printStorePath(info->path))); -- cgit v1.2.3 From a5d820a0a396db01e6297dfcadaa3218a1e918c7 Mon Sep 17 00:00:00 2001 From: Carlo Nucera Date: Tue, 2 Jun 2020 11:00:10 -0400 Subject: Change parseCa(Opt) to parseContentAddress(Opt) --- src/libstore/daemon.cc | 2 +- src/libstore/file-hash.cc | 6 +++--- src/libstore/file-hash.hh | 4 ++-- src/libstore/legacy-ssh-store.cc | 2 +- src/libstore/local-store.cc | 2 +- src/libstore/nar-info-disk-cache.cc | 2 +- src/libstore/nar-info.cc | 2 +- src/libstore/remote-store.cc | 2 +- src/nix-store/nix-store.cc | 2 +- 9 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/libstore/daemon.cc b/src/libstore/daemon.cc index 45bfa6753..0734f990a 100644 --- a/src/libstore/daemon.cc +++ b/src/libstore/daemon.cc @@ -711,7 +711,7 @@ static void performOp(TunnelLogger * logger, ref store, { string caOptRaw; from >> caOptRaw; - info.ca = parseCaOpt(caOptRaw); + info.ca = parseContentAddressOpt(caOptRaw); } from >> repair >> dontCheckSigs; if (!trusted && dontCheckSigs) diff --git a/src/libstore/file-hash.cc b/src/libstore/file-hash.cc index 494079c18..26153a424 100644 --- a/src/libstore/file-hash.cc +++ b/src/libstore/file-hash.cc @@ -38,12 +38,12 @@ std::string renderContentAddress(ContentAddress ca) { }, ca); } -ContentAddress parseCa(std::string_view rawCa) { +ContentAddress parseContentAddress(std::string_view rawCa) { throw Error("TODO"); }; -std::optional parseCaOpt(std::string_view rawCaOpt) { - return rawCaOpt == "" ? std::optional {} : parseCa(rawCaOpt); +std::optional parseContentAddressOpt(std::string_view rawCaOpt) { + return rawCaOpt == "" ? std::optional {} : parseContentAddress(rawCaOpt); }; std::string renderContentAddress(std::optional ca) { diff --git a/src/libstore/file-hash.hh b/src/libstore/file-hash.hh index 9d12f5fe7..64d514751 100644 --- a/src/libstore/file-hash.hh +++ b/src/libstore/file-hash.hh @@ -59,8 +59,8 @@ std::string renderContentAddress(ContentAddress ca); std::string renderContentAddress(std::optional ca); -ContentAddress parseCa(std::string_view rawCa); +ContentAddress parseContentAddress(std::string_view rawCa); -std::optional parseCaOpt(std::string_view rawCaOpt); +std::optional parseContentAddressOpt(std::string_view rawCaOpt); } diff --git a/src/libstore/legacy-ssh-store.cc b/src/libstore/legacy-ssh-store.cc index 8471ed073..9b6e6e6d7 100644 --- a/src/libstore/legacy-ssh-store.cc +++ b/src/libstore/legacy-ssh-store.cc @@ -117,7 +117,7 @@ struct LegacySSHStore : public Store { std::string rawCaOpt; conn->from >> rawCaOpt; - info->ca = parseCaOpt(rawCaOpt); + info->ca = parseContentAddressOpt(rawCaOpt); } info->sigs = readStrings(conn->from); } diff --git a/src/libstore/local-store.cc b/src/libstore/local-store.cc index fe346f96a..2067343c7 100644 --- a/src/libstore/local-store.cc +++ b/src/libstore/local-store.cc @@ -662,7 +662,7 @@ void LocalStore::queryPathInfoUncached(const StorePath & path, if (s) info->sigs = tokenizeString(s, " "); s = (const char *) sqlite3_column_text(state->stmtQueryPathInfo, 7); - if (s) info->ca = parseCaOpt(s); + if (s) info->ca = parseContentAddressOpt(s); /* Get the references. */ auto useQueryReferences(state->stmtQueryReferences.use()(info->id)); diff --git a/src/libstore/nar-info-disk-cache.cc b/src/libstore/nar-info-disk-cache.cc index b4346d4d1..def514840 100644 --- a/src/libstore/nar-info-disk-cache.cc +++ b/src/libstore/nar-info-disk-cache.cc @@ -203,7 +203,7 @@ public: narInfo->deriver = StorePath::fromBaseName(queryNAR.getStr(9)); for (auto & sig : tokenizeString(queryNAR.getStr(10), " ")) narInfo->sigs.insert(sig); - narInfo->ca = parseCaOpt(queryNAR.getStr(11)); + narInfo->ca = parseContentAddressOpt(queryNAR.getStr(11)); return {oValid, narInfo}; }); diff --git a/src/libstore/nar-info.cc b/src/libstore/nar-info.cc index 4f7c732ce..fe37d67ec 100644 --- a/src/libstore/nar-info.cc +++ b/src/libstore/nar-info.cc @@ -69,7 +69,7 @@ NarInfo::NarInfo(const Store & store, const std::string & s, const std::string & else if (name == "CA") { if (ca) corrupt(); // FIXME: allow blank ca or require skipping field? - ca = parseCaOpt(value); + ca = parseContentAddressOpt(value); } pos = eol + 1; diff --git a/src/libstore/remote-store.cc b/src/libstore/remote-store.cc index 2744245f3..6dab9dc16 100644 --- a/src/libstore/remote-store.cc +++ b/src/libstore/remote-store.cc @@ -383,7 +383,7 @@ void RemoteStore::queryPathInfoUncached(const StorePath & path, info->sigs = readStrings(conn->from); string caOptRaw; conn->from >> caOptRaw; - info->ca = parseCaOpt(caOptRaw); + info->ca = parseContentAddressOpt(caOptRaw); } } callback(std::move(info)); diff --git a/src/nix-store/nix-store.cc b/src/nix-store/nix-store.cc index 64ee9fd45..5d8d04252 100644 --- a/src/nix-store/nix-store.cc +++ b/src/nix-store/nix-store.cc @@ -947,7 +947,7 @@ static void opServe(Strings opFlags, Strings opArgs) { std::string rawCA; in >> rawCA; - info.ca = parseCaOpt(rawCA); + info.ca = parseContentAddressOpt(rawCA); } if (info.narSize == 0) -- 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/libexpr/primops.cc | 16 ++++----- src/libstore/build.cc | 6 ++-- src/libstore/builtins/fetchurl.cc | 2 +- src/libstore/derivations.cc | 2 -- src/libstore/export-import.cc | 2 +- src/libstore/local-store.cc | 4 +-- src/libutil/args.cc | 2 -- src/libutil/hash.cc | 62 +++++++++++++++++++++----------- src/libutil/hash.hh | 15 +++++--- src/libutil/tests/hash.cc | 2 +- src/nix-prefetch-url/nix-prefetch-url.cc | 2 -- src/nix-store/nix-store.cc | 2 +- src/nix/hash.cc | 4 +-- src/nix/verify.cc | 4 +-- 14 files changed, 72 insertions(+), 53 deletions(-) diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc index 8fbcef8c8..63bc949a6 100644 --- a/src/libexpr/primops.cc +++ b/src/libexpr/primops.cc @@ -718,7 +718,7 @@ static void prim_derivationStrict(EvalState & state, const Pos & pos, Value * * if (outputs.size() != 1 || *(outputs.begin()) != "out") throw Error(format("multiple outputs are not supported in fixed-output derivations, at %1%") % posDrvName); - HashType ht = outputHashAlgo.empty() ? HashType::Unknown : parseHashType(outputHashAlgo); + std::optional ht = parseHashTypeOpt(outputHashAlgo); Hash h(*outputHash, ht); auto outPath = state.store->makeFixedOutputPath(ingestionMethod, h, drvName); @@ -726,7 +726,7 @@ static void prim_derivationStrict(EvalState & state, const Pos & pos, Value * * drv.outputs.insert_or_assign("out", DerivationOutput { std::move(outPath), (ingestionMethod == FileIngestionMethod::Recursive ? "r:" : "") - + printHashType(h.type), + + printHashType(*h.type), h.to_string(Base::Base16, false), }); } @@ -934,14 +934,14 @@ static void prim_findFile(EvalState & state, const Pos & pos, Value * * args, Va static void prim_hashFile(EvalState & state, const Pos & pos, Value * * args, Value & v) { string type = state.forceStringNoCtx(*args[0], pos); - HashType ht = parseHashType(type); - if (ht == HashType::Unknown) + std::optional ht = parseHashType(type); + if (!ht) throw Error(format("unknown hash type '%1%', at %2%") % type % pos); PathSet context; // discarded Path p = state.coerceToPath(pos, *args[1], context); - mkString(v, hashFile(ht, state.checkSourcePath(p)).to_string(Base::Base16, false), context); + mkString(v, hashFile(*ht, state.checkSourcePath(p)).to_string(Base::Base16, false), context); } /* Read a directory (without . or ..) */ @@ -1812,14 +1812,14 @@ static void prim_stringLength(EvalState & state, const Pos & pos, Value * * args static void prim_hashString(EvalState & state, const Pos & pos, Value * * args, Value & v) { string type = state.forceStringNoCtx(*args[0], pos); - HashType ht = parseHashType(type); - if (ht == HashType::Unknown) + std::optional ht = parseHashType(type); + if (!ht) throw Error(format("unknown hash type '%1%', at %2%") % type % pos); PathSet context; // discarded string s = state.forceString(*args[1], context, pos); - mkString(v, hashString(ht, s).to_string(Base::Base16, false), context); + mkString(v, hashString(*ht, s).to_string(Base::Base16, false), context); } diff --git a/src/libstore/build.cc b/src/libstore/build.cc index ae7ba6549..b93855f79 100644 --- a/src/libstore/build.cc +++ b/src/libstore/build.cc @@ -3726,8 +3726,8 @@ void DerivationGoal::registerOutputs() /* Check the hash. In hash mode, move the path produced by the derivation to its content-addressed location. */ Hash h2 = outputHashMode == FileIngestionMethod::Recursive - ? hashPath(h.type, actualPath).first - : hashFile(h.type, actualPath); + ? hashPath(*h.type, actualPath).first + : hashFile(*h.type, actualPath); auto dest = worker.store.makeFixedOutputPath(outputHashMode, h2, i.second.path.name()); @@ -4999,7 +4999,7 @@ bool Worker::pathContentsGood(const StorePath & path) if (!pathExists(store.printStorePath(path))) res = false; else { - HashResult current = hashPath(info->narHash.type, store.printStorePath(path)); + HashResult current = hashPath(*info->narHash.type, store.printStorePath(path)); Hash nullHash(HashType::SHA256); res = info->narHash == nullHash || info->narHash == current.first; } diff --git a/src/libstore/builtins/fetchurl.cc b/src/libstore/builtins/fetchurl.cc index b70e960f8..831431437 100644 --- a/src/libstore/builtins/fetchurl.cc +++ b/src/libstore/builtins/fetchurl.cc @@ -65,7 +65,7 @@ void builtinFetchurl(const BasicDerivation & drv, const std::string & netrcData) if (!hasSuffix(hashedMirror, "/")) hashedMirror += '/'; auto ht = parseHashType(getAttr("outputHashAlgo")); auto h = Hash(getAttr("outputHash"), ht); - fetch(hashedMirror + printHashType(h.type) + "/" + h.to_string(Base::Base16, false)); + fetch(hashedMirror + printHashType(*h.type) + "/" + h.to_string(Base::Base16, false)); return; } catch (Error & e) { debug(e.what()); diff --git a/src/libstore/derivations.cc b/src/libstore/derivations.cc index a90c9b86c..d7b677185 100644 --- a/src/libstore/derivations.cc +++ b/src/libstore/derivations.cc @@ -20,8 +20,6 @@ void DerivationOutput::parseHashInfo(FileIngestionMethod & recursive, Hash & has } HashType hashType = parseHashType(algo); - if (hashType == HashType::Unknown) - throw Error("unknown hash algorithm '%s'", algo); hash = Hash(this->hash, hashType); } diff --git a/src/libstore/export-import.cc b/src/libstore/export-import.cc index 8a5e9d08e..e96b5610a 100644 --- a/src/libstore/export-import.cc +++ b/src/libstore/export-import.cc @@ -54,7 +54,7 @@ void Store::exportPath(const StorePath & path, Sink & sink) filesystem corruption from spreading to other machines. Don't complain if the stored hash is zero (unknown). */ Hash hash = hashAndWriteSink.currentHash(); - if (hash != info->narHash && info->narHash != Hash(info->narHash.type)) + if (hash != info->narHash && info->narHash != Hash(*info->narHash.type)) throw Error("hash of path '%s' has changed from '%s' to '%s'!", printStorePath(path), info->narHash.to_string(), hash.to_string()); diff --git a/src/libstore/local-store.cc b/src/libstore/local-store.cc index 7f0d5af25..5b18ebf95 100644 --- a/src/libstore/local-store.cc +++ b/src/libstore/local-store.cc @@ -1264,9 +1264,9 @@ bool LocalStore::verifyStore(bool checkContents, RepairFlag repair) std::unique_ptr hashSink; if (info->ca == "" || !info->references.count(info->path)) - hashSink = std::make_unique(info->narHash.type); + hashSink = std::make_unique(*info->narHash.type); else - hashSink = std::make_unique(info->narHash.type, storePathToHash(printStorePath(info->path))); + hashSink = std::make_unique(*info->narHash.type, storePathToHash(printStorePath(info->path))); dumpPath(Store::toRealPath(i), *hashSink); auto current = hashSink->finish(); diff --git a/src/libutil/args.cc b/src/libutil/args.cc index 4a3f5aae8..c4035ab85 100644 --- a/src/libutil/args.cc +++ b/src/libutil/args.cc @@ -162,8 +162,6 @@ Args::Flag Args::Flag::mkHashTypeFlag(std::string && longName, HashType * ht) .labels = {"hash-algo"}, .handler = {[ht](std::string s) { *ht = parseHashType(s); - if (*ht == HashType::Unknown) - throw UsageError("unknown hash type '%1%'", s); }} }; } diff --git a/src/libutil/hash.cc b/src/libutil/hash.cc index 5e6edeec3..0c3de2fda 100644 --- a/src/libutil/hash.cc +++ b/src/libutil/hash.cc @@ -4,6 +4,7 @@ #include #include +#include "args.hh" #include "hash.hh" #include "archive.hh" #include "util.hh" @@ -18,11 +19,13 @@ namespace nix { void Hash::init() { - if (type == HashType::MD5) hashSize = md5HashSize; - else if (type == HashType::SHA1) hashSize = sha1HashSize; - else if (type == HashType::SHA256) hashSize = sha256HashSize; - else if (type == HashType::SHA512) hashSize = sha512HashSize; - else abort(); + if (!type) abort(); + switch (*type) { + case HashType::MD5: hashSize = md5HashSize; break; + case HashType::SHA1: hashSize = sha1HashSize; break; + case HashType::SHA256: hashSize = sha256HashSize; break; + case HashType::SHA512: hashSize = sha512HashSize; break; + } assert(hashSize <= maxHashSize); memset(hash, 0, maxHashSize); } @@ -102,11 +105,18 @@ string printHash16or32(const Hash & hash) } +HashType assertInitHashType(const Hash & h) { + if (h.type) + return *h.type; + else + abort(); +} + std::string Hash::to_string(Base base, bool includeType) const { std::string s; if (base == Base::SRI || includeType) { - s += printHashType(type); + s += printHashType(assertInitHashType(*this)); s += base == Base::SRI ? '-' : ':'; } switch (base) { @@ -124,8 +134,10 @@ std::string Hash::to_string(Base base, bool includeType) const return s; } +Hash::Hash(const std::string & s, HashType type) : Hash(s, std::optional { type }) { } +Hash::Hash(const std::string & s) : Hash(s, std::optional{}) { } -Hash::Hash(const std::string & s, HashType type) +Hash::Hash(const std::string & s, std::optional type) : type(type) { size_t pos = 0; @@ -136,17 +148,17 @@ Hash::Hash(const std::string & s, HashType type) sep = s.find('-'); if (sep != string::npos) { isSRI = true; - } else if (type == HashType::Unknown) + } else if (! type) throw BadHash("hash '%s' does not include a type", s); } if (sep != string::npos) { string hts = string(s, 0, sep); this->type = parseHashType(hts); - if (this->type == HashType::Unknown) + if (!this->type) throw BadHash("unknown hash type '%s'", hts); - if (type != HashType::Unknown && type != this->type) - throw BadHash("hash '%s' should have type '%s'", s, printHashType(type)); + if (type && type != this->type) + throw BadHash("hash '%s' should have type '%s'", s, printHashType(*type)); pos = sep + 1; } @@ -202,7 +214,7 @@ Hash::Hash(const std::string & s, HashType type) } else - throw BadHash("hash '%s' has wrong length for hash type '%s'", s, printHashType(type)); + throw BadHash("hash '%s' has wrong length for hash type '%s'", s, printHashType(*type)); } @@ -318,24 +330,34 @@ Hash compressHash(const Hash & hash, unsigned int newSize) } -HashType parseHashType(const string & s) +std::optional parseHashTypeOpt(const string & s) { if (s == "md5") return HashType::MD5; else if (s == "sha1") return HashType::SHA1; else if (s == "sha256") return HashType::SHA256; else if (s == "sha512") return HashType::SHA512; - else return HashType::Unknown; + else return std::optional {}; } +HashType parseHashType(const string & s) +{ + auto opt_h = parseHashTypeOpt(s); + if (opt_h) + return *opt_h; + else + throw UsageError("unknown hash algorithm '%1%'", s); +} string printHashType(HashType ht) { - if (ht == HashType::MD5) return "md5"; - else if (ht == HashType::SHA1) return "sha1"; - else if (ht == HashType::SHA256) return "sha256"; - else if (ht == HashType::SHA512) return "sha512"; - else abort(); + string ret; + switch (ht) { + case HashType::MD5: ret = "md5"; break; + case HashType::SHA1: ret = "sha1"; break; + case HashType::SHA256: ret = "sha256"; break; + case HashType::SHA512: ret = "sha512"; break; + } + return ret; } - } diff --git a/src/libutil/hash.hh b/src/libutil/hash.hh index 0fe6e7677..41322be67 100644 --- a/src/libutil/hash.hh +++ b/src/libutil/hash.hh @@ -11,7 +11,6 @@ MakeError(BadHash, Error); enum struct HashType : char { - Unknown, MD5, SHA1, SHA256, @@ -40,7 +39,7 @@ struct Hash unsigned int hashSize = 0; unsigned char hash[maxHashSize] = {}; - HashType type = HashType::Unknown; + std::optional type = {}; /* Create an unset hash object. */ Hash() { }; @@ -51,14 +50,18 @@ struct Hash /* Initialize the hash from a string representation, in the format "[:]" or "-" (a Subresource Integrity hash expression). If the 'type' argument - is HashType::Unknown, then the hash type must be specified in the + is not present, then the hash type must be specified in the string. */ - Hash(const std::string & s, HashType type = HashType::Unknown); + Hash(const std::string & s, std::optional type); + // type must be provided + Hash(const std::string & s, HashType type); + // hash type must be part of string + Hash(const std::string & s); void init(); /* Check whether a hash is set. */ - operator bool () const { return type != HashType::Unknown; } + operator bool () const { return (bool) type; } /* Check whether two hash are equal. */ bool operator == (const Hash & h2) const; @@ -127,6 +130,8 @@ Hash compressHash(const Hash & hash, unsigned int newSize); /* Parse a string representing a hash type. */ HashType parseHashType(const string & s); +/* Will return nothing on parse error */ +std::optional parseHashTypeOpt(const string & s); /* And the reverse. */ string printHashType(HashType ht); diff --git a/src/libutil/tests/hash.cc b/src/libutil/tests/hash.cc index c513ce4ac..5fd168be5 100644 --- a/src/libutil/tests/hash.cc +++ b/src/libutil/tests/hash.cc @@ -75,6 +75,6 @@ namespace nix { TEST(hashString, hashingWithUnknownAlgoExits) { auto s = "unknown"; - ASSERT_DEATH(hashString(HashType::Unknown, s), ""); + ASSERT_DEATH(hashString(HashType::SHA512, s), ""); } } diff --git a/src/nix-prefetch-url/nix-prefetch-url.cc b/src/nix-prefetch-url/nix-prefetch-url.cc index 29c32b39b..e60c6615d 100644 --- a/src/nix-prefetch-url/nix-prefetch-url.cc +++ b/src/nix-prefetch-url/nix-prefetch-url.cc @@ -72,8 +72,6 @@ static int _main(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 == "--print-path") printPath = true; diff --git a/src/nix-store/nix-store.cc b/src/nix-store/nix-store.cc index ace593cde..ce86a80b7 100644 --- a/src/nix-store/nix-store.cc +++ b/src/nix-store/nix-store.cc @@ -722,7 +722,7 @@ static void opVerifyPath(Strings opFlags, Strings opArgs) auto path = store->followLinksToStorePath(i); printMsg(Verbosity::Talkative, "checking path '%s'...", store->printStorePath(path)); auto info = store->queryPathInfo(path); - HashSink sink(info->narHash.type); + HashSink sink(*info->narHash.type); store->narFromPath(path, sink); auto current = sink.finish(); if (current.first != info->narHash) { 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 d73dbc8e4cfe7ad92f072f9ccc30e51df9a5e97b Mon Sep 17 00:00:00 2001 From: John Ericson Date: Tue, 2 Jun 2020 16:28:54 +0000 Subject: Remove `hashingWithUnknownAlgoExits` A valid hash type must be provided now. The hash itself can still be invalid, but that doesn't cause an `abort()`. --- src/libutil/tests/hash.cc | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/libutil/tests/hash.cc b/src/libutil/tests/hash.cc index 5fd168be5..ecc0d4a03 100644 --- a/src/libutil/tests/hash.cc +++ b/src/libutil/tests/hash.cc @@ -72,9 +72,4 @@ namespace nix { "7299aeadb6889018501d289e4900f7e4331b99dec4b5433a" "c7d329eeb6dd26545e96e55b874be909"); } - - TEST(hashString, hashingWithUnknownAlgoExits) { - auto s = "unknown"; - ASSERT_DEATH(hashString(HashType::SHA512, s), ""); - } } -- cgit v1.2.3 From 25e61812f341a4467ab4fdffb12f63b48a3d0272 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Tue, 2 Jun 2020 12:47:18 -0400 Subject: Apply suggestions from code review Co-authored-by: Matthew Bauer --- src/libstore/legacy-ssh-store.cc | 6 +----- src/libstore/local-store.cc | 4 +++- src/libstore/remote-store.cc | 4 +--- src/nix-store/nix-store.cc | 6 +----- src/nix/verify.cc | 2 +- 5 files changed, 7 insertions(+), 15 deletions(-) diff --git a/src/libstore/legacy-ssh-store.cc b/src/libstore/legacy-ssh-store.cc index 9b6e6e6d7..b43e34484 100644 --- a/src/libstore/legacy-ssh-store.cc +++ b/src/libstore/legacy-ssh-store.cc @@ -114,11 +114,7 @@ struct LegacySSHStore : public Store if (GET_PROTOCOL_MINOR(conn->remoteVersion) >= 4) { auto s = readString(conn->from); info->narHash = s.empty() ? Hash() : Hash(s); - { - std::string rawCaOpt; - conn->from >> rawCaOpt; - info->ca = parseContentAddressOpt(rawCaOpt); - } + info->ca = parseContentAddressOpt(readString(conn->from)); info->sigs = readStrings(conn->from); } diff --git a/src/libstore/local-store.cc b/src/libstore/local-store.cc index 2067343c7..93697ae47 100644 --- a/src/libstore/local-store.cc +++ b/src/libstore/local-store.cc @@ -999,7 +999,9 @@ void LocalStore::addToStore(const ValidPathInfo & info, Source & source, deletePath(realPath); - if (info.ca && !info.references.empty() && !std::holds_alternative(*info.ca)) + // text hashing has long been allowed to have non-self-references because it is used for drv files. + bool refersToSelf = info.references.count(info.path) > 0; + if (info.ca && !info.references.empty() && !(std::holds_alternative(*info.ca) && !refersToSelf)) settings.requireExperimentalFeature("ca-references"); /* While restoring the path from the NAR, compute the hash diff --git a/src/libstore/remote-store.cc b/src/libstore/remote-store.cc index 6dab9dc16..0faa4d824 100644 --- a/src/libstore/remote-store.cc +++ b/src/libstore/remote-store.cc @@ -381,9 +381,7 @@ void RemoteStore::queryPathInfoUncached(const StorePath & path, if (GET_PROTOCOL_MINOR(conn->daemonVersion) >= 16) { conn->from >> info->ultimate; info->sigs = readStrings(conn->from); - string caOptRaw; - conn->from >> caOptRaw; - info->ca = parseContentAddressOpt(caOptRaw); + info->ca = parseContentAddressOpt(readString(conn->from)); } } callback(std::move(info)); diff --git a/src/nix-store/nix-store.cc b/src/nix-store/nix-store.cc index 5d8d04252..c74847394 100644 --- a/src/nix-store/nix-store.cc +++ b/src/nix-store/nix-store.cc @@ -944,11 +944,7 @@ static void opServe(Strings opFlags, Strings opArgs) info.references = readStorePaths(*store, in); in >> info.registrationTime >> info.narSize >> info.ultimate; info.sigs = readStrings(in); - { - std::string rawCA; - in >> rawCA; - info.ca = parseContentAddressOpt(rawCA); - } + info.ca = parseContentAddressOpt(readString(in)); if (info.narSize == 0) throw Error("narInfo is too old and missing the narSize field"); diff --git a/src/nix/verify.cc b/src/nix/verify.cc index d8636435c..d9b200591 100644 --- a/src/nix/verify.cc +++ b/src/nix/verify.cc @@ -87,7 +87,7 @@ struct CmdVerify : StorePathsCommand if (!noContents) { std::unique_ptr hashSink; - if (info->ca) + if (!info->ca) hashSink = std::make_unique(info->narHash.type); else hashSink = std::make_unique(info->narHash.type, storePathToHash(store->printStorePath(info->path))); -- cgit v1.2.3 From a33270ce1d815069d3fec43225a10e33c8e94287 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Tue, 2 Jun 2020 17:04:21 +0000 Subject: Clean up `ValidPathInfo::isContentAddressed` with `std::visit` --- src/libstore/file-hash.cc | 1 + src/libstore/store-api.cc | 45 ++++++++++++++++++++++----------------------- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/libstore/file-hash.cc b/src/libstore/file-hash.cc index 26153a424..4a3280653 100644 --- a/src/libstore/file-hash.cc +++ b/src/libstore/file-hash.cc @@ -24,6 +24,7 @@ std::string makeFixedOutputCA(FileIngestionMethod method, const Hash & hash) + hash.to_string(); } +// FIXME Put this somewhere? template struct overloaded : Ts... { using Ts::operator()...; }; template overloaded(Ts...) -> overloaded; diff --git a/src/libstore/store-api.cc b/src/libstore/store-api.cc index ea30ed105..4bd3121ed 100644 --- a/src/libstore/store-api.cc +++ b/src/libstore/store-api.cc @@ -753,36 +753,35 @@ void ValidPathInfo::sign(const Store & store, const SecretKey & secretKey) sigs.insert(secretKey.signDetached(fingerprint(store))); } +// FIXME Put this somewhere? +template struct overloaded : Ts... { using Ts::operator()...; }; +template overloaded(Ts...) -> overloaded; bool ValidPathInfo::isContentAddressed(const Store & store) const { - auto warn = [&]() { - printError("warning: path '%s' claims to be content-addressed but isn't", store.printStorePath(path)); - }; + if (! ca) return false; - if (! ca) {} + auto caPath = std::visit(overloaded { + [&](TextHash th) { + return store.makeTextPath(path.name(), th.hash, references); + }, + [&](FileSystemHash fsh) { + auto refs = cloneStorePathSet(references); + bool hasSelfReference = false; + if (refs.count(path)) { + hasSelfReference = true; + refs.erase(path); + } + return store.makeFixedOutputPath(fsh.method, fsh.hash, path.name(), refs, hasSelfReference); + } + }, *ca); - else if (auto p = std::get_if(&*ca)) { - if (store.makeTextPath(path.name(), p->hash, references) == path) - return true; - else - warn(); - } + bool res = caPath == path; - else if (auto p = std::get_if(&*ca)) { - auto refs = cloneStorePathSet(references); - bool hasSelfReference = false; - if (refs.count(path)) { - hasSelfReference = true; - refs.erase(path); - } - if (store.makeFixedOutputPath(p->method, p->hash, path.name(), refs, hasSelfReference) == path) - return true; - else - warn(); - } + if (!res) + printError("warning: path '%s' claims to be content-addressed but isn't", store.printStorePath(path)); - return false; + return res; } -- 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(-) 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 390bf64858e03b948a9b65fe138b34dd2776f8ef Mon Sep 17 00:00:00 2001 From: Carlo Nucera Date: Tue, 2 Jun 2020 14:15:38 -0400 Subject: WIP --- src/libstore/derivations.hh | 1 - src/libstore/file-hash.cc | 55 ++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/src/libstore/derivations.hh b/src/libstore/derivations.hh index e314beac1..dba9318d9 100644 --- a/src/libstore/derivations.hh +++ b/src/libstore/derivations.hh @@ -24,7 +24,6 @@ struct DerivationOutput DerivationOutput(const DerivationOutput &) = default; DerivationOutput(DerivationOutput &&) = default; DerivationOutput & operator = (const DerivationOutput &) = default; - void parseHashInfo(FileIngestionMethod & recursive, Hash & hash) const; }; typedef std::map DerivationOutputs; diff --git a/src/libstore/file-hash.cc b/src/libstore/file-hash.cc index 4a3280653..9cae8f80e 100644 --- a/src/libstore/file-hash.cc +++ b/src/libstore/file-hash.cc @@ -40,7 +40,60 @@ std::string renderContentAddress(ContentAddress ca) { } ContentAddress parseContentAddress(std::string_view rawCa) { - throw Error("TODO"); + auto prefixSeparator = rawCa.find(':'); + if (prefixSeparator != string::npos) { + auto prefix = string(rawCa, 0, prefixSeparator); + if (prefix == "text") { + auto hashTypeAndHash = rawCa.substr(prefixSeparator+1, string::npos); + auto hashSeparator = hashTypeAndHash.find(':'); + if (hashSeparator != string::npos) { + std::string_view hashTypeRaw = hashTypeAndHash.substr(0, hashSeparator); + std::string_view hashRaw = hashTypeAndHash.substr(hashSeparator+1, string::npos); + auto hashType = parseHashType(string(hashTypeRaw)); + return TextHash { Hash(string(hashRaw), hashType) }; + } else { + throw "parseContentAddress: hash type not found"; + } + } else if (prefix == "fixed") { + auto methodAndHash = rawCa.substr(prefixSeparator+1, string::npos); + if (methodAndHash.substr(0,2) == "r:") { + std::string_view hashRaw = methodAndHash.substr(2,string::npos); + return FileSystemHash { FileIngestionMethod::Recursive, } + } + + + + // break; + // } else { + // throw "parseContentAddress: invalid prefix"; + } + + } else { + throw "Not a content address because it lacks an appropriate prefix"; + } + + + + // if (getString(rawCa, 5) == "text:") { + // auto hashTypeAndHash = string::substr(5, string::npos); + // auto sep = hashTypeAndHash.find(':'); + // if (sep != string::npos) { + // string hashTypeRaw = string(hashTypeAndHash, 0, sep); + // auto hashType = parseHashType(hashTypeRaw); + // } + // break; + + // // } else if (getString (rawCa, 6) = "fixed:") { + // } else if (true) { + // break; + // } + + // auto sep = rawCa.find(':'); + // if (sep == string::npos) + // if(string(rawCa, 5) == "text:") { + // break; + // } else if {} + // throw Error("TODO"); }; std::optional parseContentAddressOpt(std::string_view rawCaOpt) { -- 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/libutil/args.cc | 12 ++++++++++++ src/libutil/args.hh | 1 + src/nix/hash.cc | 2 +- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/libutil/args.cc b/src/libutil/args.cc index c4035ab85..4fe9539e4 100644 --- a/src/libutil/args.cc +++ b/src/libutil/args.cc @@ -166,6 +166,18 @@ Args::Flag Args::Flag::mkHashTypeFlag(std::string && longName, HashType * ht) }; } +Args::Flag Args::Flag::mkHashTypeOptFlag(std::string && longName, std::optional * oht) +{ + return Flag { + .longName = std::move(longName), + .description = "hash algorithm ('md5', 'sha1', 'sha256', or 'sha512'). Optional as can also be gotten from SRI hash itself.", + .labels = {"hash-algo"}, + .handler = {[oht](std::string s) { + *oht = std::optional { parseHashType(s) }; + }} + }; +} + Strings argvToStrings(int argc, char * * argv) { Strings args; diff --git a/src/libutil/args.hh b/src/libutil/args.hh index fc8f82af5..f2315f67a 100644 --- a/src/libutil/args.hh +++ b/src/libutil/args.hh @@ -85,6 +85,7 @@ protected: Handler handler; static Flag mkHashTypeFlag(std::string && longName, HashType * ht); + static Flag mkHashTypeOptFlag(std::string && longName, std::optional * oht); }; std::map longFlags; 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 343c20a404055d266227b7562f775f7fad37103f Mon Sep 17 00:00:00 2001 From: Carlo Nucera Date: Tue, 2 Jun 2020 15:18:05 -0400 Subject: WIP Completed implementation --- src/libstore/file-hash.cc | 48 ++++++++--------------------------------------- 1 file changed, 8 insertions(+), 40 deletions(-) diff --git a/src/libstore/file-hash.cc b/src/libstore/file-hash.cc index 9cae8f80e..caf9a83e9 100644 --- a/src/libstore/file-hash.cc +++ b/src/libstore/file-hash.cc @@ -45,55 +45,23 @@ ContentAddress parseContentAddress(std::string_view rawCa) { auto prefix = string(rawCa, 0, prefixSeparator); if (prefix == "text") { auto hashTypeAndHash = rawCa.substr(prefixSeparator+1, string::npos); - auto hashSeparator = hashTypeAndHash.find(':'); - if (hashSeparator != string::npos) { - std::string_view hashTypeRaw = hashTypeAndHash.substr(0, hashSeparator); - std::string_view hashRaw = hashTypeAndHash.substr(hashSeparator+1, string::npos); - auto hashType = parseHashType(string(hashTypeRaw)); - return TextHash { Hash(string(hashRaw), hashType) }; - } else { - throw "parseContentAddress: hash type not found"; - } + return TextHash { Hash(string(hashTypeAndHash)) }; } else if (prefix == "fixed") { + // This has to be an inverse to makeFixedOutputCA auto methodAndHash = rawCa.substr(prefixSeparator+1, string::npos); if (methodAndHash.substr(0,2) == "r:") { std::string_view hashRaw = methodAndHash.substr(2,string::npos); - return FileSystemHash { FileIngestionMethod::Recursive, } + return FileSystemHash { FileIngestionMethod::Recursive, Hash(string(hashRaw)) }; + } else { + std::string_view hashRaw = methodAndHash; + return FileSystemHash { FileIngestionMethod::Flat, Hash(string(hashRaw)) }; } - - - - // break; - // } else { - // throw "parseContentAddress: invalid prefix"; + } else { + throw "parseContentAddress: format not recognized; has to be text or fixed"; } - } else { throw "Not a content address because it lacks an appropriate prefix"; } - - - - // if (getString(rawCa, 5) == "text:") { - // auto hashTypeAndHash = string::substr(5, string::npos); - // auto sep = hashTypeAndHash.find(':'); - // if (sep != string::npos) { - // string hashTypeRaw = string(hashTypeAndHash, 0, sep); - // auto hashType = parseHashType(hashTypeRaw); - // } - // break; - - // // } else if (getString (rawCa, 6) = "fixed:") { - // } else if (true) { - // break; - // } - - // auto sep = rawCa.find(':'); - // if (sep == string::npos) - // if(string(rawCa, 5) == "text:") { - // break; - // } else if {} - // throw Error("TODO"); }; std::optional parseContentAddressOpt(std::string_view rawCaOpt) { -- cgit v1.2.3 From fd2eb41e6433e72516ae149949b8b0050305293d Mon Sep 17 00:00:00 2001 From: Carlo Nucera Date: Tue, 2 Jun 2020 15:44:58 -0400 Subject: Move file-hash to content-address --- src/libstore/content-address.cc | 75 +++++++++++++++++++++++++++++++++++++++++ src/libstore/content-address.hh | 66 ++++++++++++++++++++++++++++++++++++ src/libstore/derivations.hh | 2 +- src/libstore/file-hash.cc | 75 ----------------------------------------- src/libstore/file-hash.hh | 66 ------------------------------------ src/libstore/path.hh | 2 +- src/libstore/store-api.hh | 2 +- src/nix/hash.cc | 2 +- 8 files changed, 145 insertions(+), 145 deletions(-) create mode 100644 src/libstore/content-address.cc create mode 100644 src/libstore/content-address.hh delete mode 100644 src/libstore/file-hash.cc delete mode 100644 src/libstore/file-hash.hh diff --git a/src/libstore/content-address.cc b/src/libstore/content-address.cc new file mode 100644 index 000000000..421127f5a --- /dev/null +++ b/src/libstore/content-address.cc @@ -0,0 +1,75 @@ +#include "content-address.hh" + +namespace nix { + +std::string FileSystemHash::printMethodAlgo() const { + return makeFileIngestionPrefix(method) + printHashType(hash.type); +} + +std::string makeFileIngestionPrefix(const FileIngestionMethod m) { + switch (m) { + case FileIngestionMethod::Flat: + return ""; + case FileIngestionMethod::Recursive: + return "r:"; + default: + throw Error("impossible, caught both cases"); + } +} + +std::string makeFixedOutputCA(FileIngestionMethod method, const Hash & hash) +{ + return "fixed:" + + makeFileIngestionPrefix(method) + + hash.to_string(); +} + +// FIXME Put this somewhere? +template struct overloaded : Ts... { using Ts::operator()...; }; +template overloaded(Ts...) -> overloaded; + +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); +} + +ContentAddress parseContentAddress(std::string_view rawCa) { + auto prefixSeparator = rawCa.find(':'); + if (prefixSeparator != string::npos) { + auto prefix = string(rawCa, 0, prefixSeparator); + if (prefix == "text") { + auto hashTypeAndHash = rawCa.substr(prefixSeparator+1, string::npos); + return TextHash { Hash(string(hashTypeAndHash)) }; + } else if (prefix == "fixed") { + // This has to be an inverse to makeFixedOutputCA + auto methodAndHash = rawCa.substr(prefixSeparator+1, string::npos); + if (methodAndHash.substr(0,2) == "r:") { + std::string_view hashRaw = methodAndHash.substr(2,string::npos); + return FileSystemHash { FileIngestionMethod::Recursive, Hash(string(hashRaw)) }; + } else { + std::string_view hashRaw = methodAndHash; + return FileSystemHash { FileIngestionMethod::Flat, Hash(string(hashRaw)) }; + } + } else { + throw "parseContentAddress: format not recognized; has to be text or fixed"; + } + } else { + throw "Not a content address because it lacks an appropriate prefix"; + } +}; + +std::optional parseContentAddressOpt(std::string_view rawCaOpt) { + return rawCaOpt == "" ? std::optional {} : parseContentAddress(rawCaOpt); +}; + +std::string renderContentAddress(std::optional ca) { + return ca ? renderContentAddress(*ca) : ""; +} + +} diff --git a/src/libstore/content-address.hh b/src/libstore/content-address.hh new file mode 100644 index 000000000..64d514751 --- /dev/null +++ b/src/libstore/content-address.hh @@ -0,0 +1,66 @@ +#pragma once + +#include +#include "hash.hh" + +namespace nix { + +enum struct FileIngestionMethod : uint8_t { + Flat = false, + Recursive = true +}; + +struct TextHash { + Hash hash; + TextHash(const TextHash &) = default; + TextHash(TextHash &&) = default; + TextHash & operator = (const TextHash &) = default; +}; + +/// Pair of a hash, and how the file system was ingested +struct FileSystemHash { + FileIngestionMethod method; + Hash hash; + FileSystemHash(FileIngestionMethod method, Hash hash) + : method(std::move(method)) + , hash(std::move(hash)) + { } + FileSystemHash(const FileSystemHash &) = default; + FileSystemHash(FileSystemHash &&) = default; + FileSystemHash & operator = (const FileSystemHash &) = default; + std::string printMethodAlgo() const; +}; + +/* + We've accumulated several types of content-addressed paths over the years; + fixed-output derivations support multiple hash algorithms and serialisation + methods (flat file vs NAR). Thus, ‘ca’ has one of the following forms: + + * ‘text:sha256:’: For paths + computed by makeTextPath() / addTextToStore(). + + * ‘fixed:::’: For paths computed by + makeFixedOutputPath() / addToStore(). +*/ +typedef std::variant< + TextHash, // for paths computed by makeTextPath() / addTextToStore + FileSystemHash // for path computed by makeFixedOutputPath +> ContentAddress; + +/* Compute the prefix to the hash algorithm which indicates how the files were + ingested. */ +std::string makeFileIngestionPrefix(const FileIngestionMethod m); + +/* Compute the content-addressability assertion (ValidPathInfo::ca) + for paths created by makeFixedOutputPath() / addToStore(). */ +std::string makeFixedOutputCA(FileIngestionMethod method, const Hash & hash); + +std::string renderContentAddress(ContentAddress ca); + +std::string renderContentAddress(std::optional ca); + +ContentAddress parseContentAddress(std::string_view rawCa); + +std::optional parseContentAddressOpt(std::string_view rawCaOpt); + +} diff --git a/src/libstore/derivations.hh b/src/libstore/derivations.hh index dba9318d9..838b63358 100644 --- a/src/libstore/derivations.hh +++ b/src/libstore/derivations.hh @@ -3,7 +3,7 @@ #include "path.hh" #include "types.hh" #include "hash.hh" -#include "file-hash.hh" +#include "content-address.hh" #include diff --git a/src/libstore/file-hash.cc b/src/libstore/file-hash.cc deleted file mode 100644 index caf9a83e9..000000000 --- a/src/libstore/file-hash.cc +++ /dev/null @@ -1,75 +0,0 @@ -#include "file-hash.hh" - -namespace nix { - -std::string FileSystemHash::printMethodAlgo() const { - return makeFileIngestionPrefix(method) + printHashType(hash.type); -} - -std::string makeFileIngestionPrefix(const FileIngestionMethod m) { - switch (m) { - case FileIngestionMethod::Flat: - return ""; - case FileIngestionMethod::Recursive: - return "r:"; - default: - throw Error("impossible, caught both cases"); - } -} - -std::string makeFixedOutputCA(FileIngestionMethod method, const Hash & hash) -{ - return "fixed:" - + makeFileIngestionPrefix(method) - + hash.to_string(); -} - -// FIXME Put this somewhere? -template struct overloaded : Ts... { using Ts::operator()...; }; -template overloaded(Ts...) -> overloaded; - -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); -} - -ContentAddress parseContentAddress(std::string_view rawCa) { - auto prefixSeparator = rawCa.find(':'); - if (prefixSeparator != string::npos) { - auto prefix = string(rawCa, 0, prefixSeparator); - if (prefix == "text") { - auto hashTypeAndHash = rawCa.substr(prefixSeparator+1, string::npos); - return TextHash { Hash(string(hashTypeAndHash)) }; - } else if (prefix == "fixed") { - // This has to be an inverse to makeFixedOutputCA - auto methodAndHash = rawCa.substr(prefixSeparator+1, string::npos); - if (methodAndHash.substr(0,2) == "r:") { - std::string_view hashRaw = methodAndHash.substr(2,string::npos); - return FileSystemHash { FileIngestionMethod::Recursive, Hash(string(hashRaw)) }; - } else { - std::string_view hashRaw = methodAndHash; - return FileSystemHash { FileIngestionMethod::Flat, Hash(string(hashRaw)) }; - } - } else { - throw "parseContentAddress: format not recognized; has to be text or fixed"; - } - } else { - throw "Not a content address because it lacks an appropriate prefix"; - } -}; - -std::optional parseContentAddressOpt(std::string_view rawCaOpt) { - return rawCaOpt == "" ? std::optional {} : parseContentAddress(rawCaOpt); -}; - -std::string renderContentAddress(std::optional ca) { - return ca ? renderContentAddress(*ca) : ""; -} - -} diff --git a/src/libstore/file-hash.hh b/src/libstore/file-hash.hh deleted file mode 100644 index 64d514751..000000000 --- a/src/libstore/file-hash.hh +++ /dev/null @@ -1,66 +0,0 @@ -#pragma once - -#include -#include "hash.hh" - -namespace nix { - -enum struct FileIngestionMethod : uint8_t { - Flat = false, - Recursive = true -}; - -struct TextHash { - Hash hash; - TextHash(const TextHash &) = default; - TextHash(TextHash &&) = default; - TextHash & operator = (const TextHash &) = default; -}; - -/// Pair of a hash, and how the file system was ingested -struct FileSystemHash { - FileIngestionMethod method; - Hash hash; - FileSystemHash(FileIngestionMethod method, Hash hash) - : method(std::move(method)) - , hash(std::move(hash)) - { } - FileSystemHash(const FileSystemHash &) = default; - FileSystemHash(FileSystemHash &&) = default; - FileSystemHash & operator = (const FileSystemHash &) = default; - std::string printMethodAlgo() const; -}; - -/* - We've accumulated several types of content-addressed paths over the years; - fixed-output derivations support multiple hash algorithms and serialisation - methods (flat file vs NAR). Thus, ‘ca’ has one of the following forms: - - * ‘text:sha256:’: For paths - computed by makeTextPath() / addTextToStore(). - - * ‘fixed:::’: For paths computed by - makeFixedOutputPath() / addToStore(). -*/ -typedef std::variant< - TextHash, // for paths computed by makeTextPath() / addTextToStore - FileSystemHash // for path computed by makeFixedOutputPath -> ContentAddress; - -/* Compute the prefix to the hash algorithm which indicates how the files were - ingested. */ -std::string makeFileIngestionPrefix(const FileIngestionMethod m); - -/* Compute the content-addressability assertion (ValidPathInfo::ca) - for paths created by makeFixedOutputPath() / addToStore(). */ -std::string makeFixedOutputCA(FileIngestionMethod method, const Hash & hash); - -std::string renderContentAddress(ContentAddress ca); - -std::string renderContentAddress(std::optional ca); - -ContentAddress parseContentAddress(std::string_view rawCa); - -std::optional parseContentAddressOpt(std::string_view rawCaOpt); - -} diff --git a/src/libstore/path.hh b/src/libstore/path.hh index dfc0a9531..fdbc906ef 100644 --- a/src/libstore/path.hh +++ b/src/libstore/path.hh @@ -1,7 +1,7 @@ #pragma once #include "rust-ffi.hh" -#include "file-hash.hh" +#include "content-address.hh" namespace nix { diff --git a/src/libstore/store-api.hh b/src/libstore/store-api.hh index 7836c04dc..441e3efc5 100644 --- a/src/libstore/store-api.hh +++ b/src/libstore/store-api.hh @@ -2,7 +2,7 @@ #include "path.hh" #include "hash.hh" -#include "file-hash.hh" +#include "content-address.hh" #include "serialise.hh" #include "crypto.hh" #include "lru-cache.hh" diff --git a/src/nix/hash.cc b/src/nix/hash.cc index ec23b77bc..26bbcef1c 100644 --- a/src/nix/hash.cc +++ b/src/nix/hash.cc @@ -1,6 +1,6 @@ #include "command.hh" #include "hash.hh" -#include "file-hash.hh" +#include "content-address.hh" #include "legacy.hh" #include "shared.hh" #include "references.hh" -- cgit v1.2.3 From a5cdf1867efdf50f8cef324bbc36d1b840e13f8c Mon Sep 17 00:00:00 2001 From: Carlo Nucera Date: Tue, 2 Jun 2020 16:13:08 -0400 Subject: Add assertions for SHA256 in fixed case --- src/libstore/content-address.cc | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/libstore/content-address.cc b/src/libstore/content-address.cc index 421127f5a..4c3af18fd 100644 --- a/src/libstore/content-address.cc +++ b/src/libstore/content-address.cc @@ -51,10 +51,14 @@ ContentAddress parseContentAddress(std::string_view rawCa) { auto methodAndHash = rawCa.substr(prefixSeparator+1, string::npos); if (methodAndHash.substr(0,2) == "r:") { std::string_view hashRaw = methodAndHash.substr(2,string::npos); - return FileSystemHash { FileIngestionMethod::Recursive, Hash(string(hashRaw)) }; + Hash hash = Hash(string(hashRaw)); + assert(hash.type == HashType::SHA256); + return FileSystemHash { FileIngestionMethod::Recursive, hash }; } else { std::string_view hashRaw = methodAndHash; - return FileSystemHash { FileIngestionMethod::Flat, Hash(string(hashRaw)) }; + Hash hash = Hash(string(hashRaw)); + assert(hash.type == HashType::SHA256); + return FileSystemHash { FileIngestionMethod::Flat, hash }; } } else { throw "parseContentAddress: format not recognized; has to be text or fixed"; -- cgit v1.2.3 From 78f137e931eff3c5133fe0a58f5d469f50959556 Mon Sep 17 00:00:00 2001 From: Carlo Nucera Date: Tue, 2 Jun 2020 16:20:22 -0400 Subject: Validate text version instead, throw Errors --- src/libstore/content-address.cc | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/libstore/content-address.cc b/src/libstore/content-address.cc index 4c3af18fd..8a8112fd0 100644 --- a/src/libstore/content-address.cc +++ b/src/libstore/content-address.cc @@ -45,26 +45,26 @@ ContentAddress parseContentAddress(std::string_view rawCa) { auto prefix = string(rawCa, 0, prefixSeparator); if (prefix == "text") { auto hashTypeAndHash = rawCa.substr(prefixSeparator+1, string::npos); - return TextHash { Hash(string(hashTypeAndHash)) }; + Hash hash = Hash(string(hashTypeAndHash)); + if (hash.type != HashType::SHA256) { + throw Error("parseContentAddress: the text hash should have type SHA256"); + } + return TextHash { hash }; } else if (prefix == "fixed") { // This has to be an inverse to makeFixedOutputCA auto methodAndHash = rawCa.substr(prefixSeparator+1, string::npos); if (methodAndHash.substr(0,2) == "r:") { std::string_view hashRaw = methodAndHash.substr(2,string::npos); - Hash hash = Hash(string(hashRaw)); - assert(hash.type == HashType::SHA256); - return FileSystemHash { FileIngestionMethod::Recursive, hash }; + return FileSystemHash { FileIngestionMethod::Recursive, Hash(string(hashRaw)) }; } else { std::string_view hashRaw = methodAndHash; - Hash hash = Hash(string(hashRaw)); - assert(hash.type == HashType::SHA256); - return FileSystemHash { FileIngestionMethod::Flat, hash }; + return FileSystemHash { FileIngestionMethod::Flat, Hash(string(hashRaw)) }; } } else { - throw "parseContentAddress: format not recognized; has to be text or fixed"; + throw Error("parseContentAddress: format not recognized; has to be text or fixed"); } } else { - throw "Not a content address because it lacks an appropriate prefix"; + throw Error("Not a content address because it lacks an appropriate prefix"); } }; -- cgit v1.2.3 From 75d2581390e70c9f5820311ff25ae13521ad07e2 Mon Sep 17 00:00:00 2001 From: Carlo Nucera Date: Tue, 2 Jun 2020 16:21:18 -0400 Subject: Typo --- src/libstore/content-address.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libstore/content-address.cc b/src/libstore/content-address.cc index 8a8112fd0..718c7ffc3 100644 --- a/src/libstore/content-address.cc +++ b/src/libstore/content-address.cc @@ -51,7 +51,7 @@ ContentAddress parseContentAddress(std::string_view rawCa) { } return TextHash { hash }; } else if (prefix == "fixed") { - // This has to be an inverse to makeFixedOutputCA + // This has to be an inverse of makeFixedOutputCA auto methodAndHash = rawCa.substr(prefixSeparator+1, string::npos); if (methodAndHash.substr(0,2) == "r:") { std::string_view hashRaw = methodAndHash.substr(2,string::npos); -- cgit v1.2.3 From 1fcd3afc38ebc7ee98add0bf1b4bd643b25ccebf Mon Sep 17 00:00:00 2001 From: John Ericson Date: Tue, 2 Jun 2020 20:35:17 +0000 Subject: Fix hashes --- src/libutil/hash.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libutil/hash.cc b/src/libutil/hash.cc index 0c3de2fda..6b9effdd2 100644 --- a/src/libutil/hash.cc +++ b/src/libutil/hash.cc @@ -19,13 +19,13 @@ namespace nix { void Hash::init() { - if (!type) abort(); - switch (*type) { + if (!type) abort(); + switch (*type) { case HashType::MD5: hashSize = md5HashSize; break; case HashType::SHA1: hashSize = sha1HashSize; break; case HashType::SHA256: hashSize = sha256HashSize; break; case HashType::SHA512: hashSize = sha512HashSize; break; - } + } assert(hashSize <= maxHashSize); memset(hash, 0, maxHashSize); } -- cgit v1.2.3 From 406dbb7fce32f7d80b02f560d91c956698b58d6e Mon Sep 17 00:00:00 2001 From: John Ericson Date: Tue, 2 Jun 2020 21:09:15 +0000 Subject: `outputHashAlgo` can be blank so parse accordingly It is blank for SRI hashes. --- src/libstore/builtins/fetchurl.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libstore/builtins/fetchurl.cc b/src/libstore/builtins/fetchurl.cc index 831431437..770df2927 100644 --- a/src/libstore/builtins/fetchurl.cc +++ b/src/libstore/builtins/fetchurl.cc @@ -63,7 +63,7 @@ void builtinFetchurl(const BasicDerivation & drv, const std::string & netrcData) for (auto hashedMirror : settings.hashedMirrors.get()) try { if (!hasSuffix(hashedMirror, "/")) hashedMirror += '/'; - auto ht = parseHashType(getAttr("outputHashAlgo")); + auto ht = parseHashTypeOpt(getAttr("outputHashAlgo")); auto h = Hash(getAttr("outputHash"), ht); fetch(hashedMirror + printHashType(*h.type) + "/" + h.to_string(Base::Base16, false)); return; -- cgit v1.2.3 From 39ba87be9b426d75de50d35c9199661067218adc Mon Sep 17 00:00:00 2001 From: John Ericson Date: Tue, 2 Jun 2020 21:36:53 +0000 Subject: Missing `#include ` in `lru-cache.hh` This was a latent bug that just appeared because of the tests that were added. Remember to wait for CI! :) --- src/libutil/lru-cache.hh | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libutil/lru-cache.hh b/src/libutil/lru-cache.hh index 8b83f842c..6ef4a3e06 100644 --- a/src/libutil/lru-cache.hh +++ b/src/libutil/lru-cache.hh @@ -1,5 +1,6 @@ #pragma once +#include #include #include #include -- cgit v1.2.3 From 132d6f2c2419891b92870c61c599a5e6aa97c865 Mon Sep 17 00:00:00 2001 From: Carlo Nucera Date: Wed, 3 Jun 2020 16:08:32 -0400 Subject: Clarify the description of StorePath construction --- src/libstore/store-api.cc | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/libstore/store-api.cc b/src/libstore/store-api.cc index 095363d0c..e5492ce34 100644 --- a/src/libstore/store-api.cc +++ b/src/libstore/store-api.cc @@ -69,7 +69,7 @@ string storePathToHash(const Path & path) /* Store paths have the following form: - /- + = /- where @@ -93,11 +93,14 @@ string storePathToHash(const Path & path) = one of: "text:::..." for plain text files written to the store using - addTextToStore(); ... are the references of the - path. - "source" + addTextToStore(); ... are the store paths referenced + by this path, in the form described by + "source:::...::self" for paths copied to the store using addToStore() when recursive - = true and hashAlgo = "sha256" + = true and hashAlgo = "sha256". Just like in the text case, we + can have the store paths referenced by the path. + Additionally, we can have an optional :self label to denote self + reference. "output:" for either the outputs created by derivations, OR paths copied to the store using addToStore() with recursive != true or @@ -125,6 +128,12 @@ string storePathToHash(const Path & path) the contents of the path (or expected contents of the path for fixed-output derivations) + Note that since an output derivation has always type output, while + something added by addToStore can have type output or source depending + on the hash, this means that the same input can be hashed differently + if added to the store via addToStore or via a derivation, in the sha256 + recursive case. + It would have been nicer to handle fixed-output derivations under "source", e.g. have something like "source:", but we're stuck with this for now... -- cgit v1.2.3 From 53bc8ff152091173e11f2bead245541e3037d769 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Wed, 3 Jun 2020 20:35:14 -0400 Subject: No C++ designated initializers yet with Clang 7 --- src/libfetchers/tarball.cc | 4 ++-- src/libstore/build.cc | 5 +---- src/libstore/local-store.cc | 5 +---- src/nix/add-to-store.cc | 4 ++-- src/nix/make-content-addressable.cc | 4 ++-- 5 files changed, 8 insertions(+), 14 deletions(-) diff --git a/src/libfetchers/tarball.cc b/src/libfetchers/tarball.cc index e8e5231d2..f8813ea1a 100644 --- a/src/libfetchers/tarball.cc +++ b/src/libfetchers/tarball.cc @@ -71,8 +71,8 @@ DownloadFileResult downloadFile( info.narHash = hashString(HashType::SHA256, *sink.s); info.narSize = sink.s->size(); info.ca = FileSystemHash { - .method = FileIngestionMethod::Flat, - .hash = hash, + FileIngestionMethod::Flat, + hash, }; auto source = StringSource { *sink.s }; store->addToStore(info, source, NoRepair, NoCheckSigs); diff --git a/src/libstore/build.cc b/src/libstore/build.cc index ea7319150..3eb103e94 100644 --- a/src/libstore/build.cc +++ b/src/libstore/build.cc @@ -3757,10 +3757,7 @@ void DerivationGoal::registerOutputs() else assert(worker.store.parseStorePath(path) == dest); - ca = FileSystemHash { - .method = i.second.hash->method, - .hash = h2, - }; + ca = FileSystemHash { i.second.hash->method, h2 }; } /* Get rid of all weird permissions. This also checks that diff --git a/src/libstore/local-store.cc b/src/libstore/local-store.cc index 5f0053753..af6c6f390 100644 --- a/src/libstore/local-store.cc +++ b/src/libstore/local-store.cc @@ -1093,10 +1093,7 @@ StorePath LocalStore::addToStoreFromDump(const string & dump, const string & nam ValidPathInfo info(dstPath.clone()); info.narHash = hash.first; info.narSize = hash.second; - info.ca = FileSystemHash { - .method = method, - .hash = h, - }; + info.ca = FileSystemHash { method, h }; registerValidPath(info); } diff --git a/src/nix/add-to-store.cc b/src/nix/add-to-store.cc index b92597cc2..3162e0c62 100644 --- a/src/nix/add-to-store.cc +++ b/src/nix/add-to-store.cc @@ -49,8 +49,8 @@ struct CmdAddToStore : MixDryRun, StoreCommand info.narHash = narHash; info.narSize = sink.s->size(); *info.ca = FileSystemHash { - .method = FileIngestionMethod::Recursive, - .hash = info.narHash + FileIngestionMethod::Recursive, + info.narHash, }; if (!dryRun) { diff --git a/src/nix/make-content-addressable.cc b/src/nix/make-content-addressable.cc index 5003ff459..d19e681bd 100644 --- a/src/nix/make-content-addressable.cc +++ b/src/nix/make-content-addressable.cc @@ -83,8 +83,8 @@ struct CmdMakeContentAddressable : StorePathsCommand, MixJSON info.narHash = narHash; info.narSize = sink.s->size(); info.ca = FileSystemHash { - .method = FileIngestionMethod::Recursive, - .hash = info.narHash, + FileIngestionMethod::Recursive, + info.narHash, }; if (!json) -- cgit v1.2.3 From 574d5460f02c46e9e5bcca93a14ccf782cb2c8f8 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Thu, 4 Jun 2020 20:33:28 +0000 Subject: Make sure info.ca tag bit is set in `nix add-to-store` --- src/nix/add-to-store.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/nix/add-to-store.cc b/src/nix/add-to-store.cc index 3162e0c62..e6f6ef27b 100644 --- a/src/nix/add-to-store.cc +++ b/src/nix/add-to-store.cc @@ -48,10 +48,10 @@ struct CmdAddToStore : MixDryRun, StoreCommand ValidPathInfo info(store->makeFixedOutputPath(FileIngestionMethod::Recursive, narHash, *namePart)); info.narHash = narHash; info.narSize = sink.s->size(); - *info.ca = FileSystemHash { + info.ca = std::optional { FileSystemHash { FileIngestionMethod::Recursive, info.narHash, - }; + } }; if (!dryRun) { auto source = StringSource { *sink.s }; -- cgit v1.2.3 From ed86acf02aa5810044b995dc57744d7b51867bb0 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Thu, 4 Jun 2020 20:42:02 +0000 Subject: Use some `std::optional::has_value` for clarity --- src/libstore/local-store.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libstore/local-store.cc b/src/libstore/local-store.cc index af6c6f390..804d4c514 100644 --- a/src/libstore/local-store.cc +++ b/src/libstore/local-store.cc @@ -576,7 +576,7 @@ void LocalStore::checkDerivationOutputs(const StorePath & drvPath, const Derivat uint64_t LocalStore::addValidPath(State & state, const ValidPathInfo & info, bool checkOutputs) { - if (info.ca && !info.isContentAddressed(*this)) + if (info.ca.has_value() && !info.isContentAddressed(*this)) throw Error("cannot add path '%s' to the Nix store because it claims to be content-addressed but isn't", printStorePath(info.path)); @@ -1001,13 +1001,13 @@ void LocalStore::addToStore(const ValidPathInfo & info, Source & source, // text hashing has long been allowed to have non-self-references because it is used for drv files. bool refersToSelf = info.references.count(info.path) > 0; - if (info.ca && !info.references.empty() && !(std::holds_alternative(*info.ca) && !refersToSelf)) + if (info.ca.has_value() && !info.references.empty() && !(std::holds_alternative(*info.ca) && !refersToSelf)) settings.requireExperimentalFeature("ca-references"); /* While restoring the path from the NAR, compute the hash of the NAR. */ std::unique_ptr hashSink; - if (info.ca || !info.references.count(info.path)) + if (info.ca.has_value() || !info.references.count(info.path)) hashSink = std::make_unique(HashType::SHA256); else hashSink = std::make_unique(HashType::SHA256, storePathToHash(printStorePath(info.path))); -- cgit v1.2.3 From 2041499b5e62ab45b23c3f2ceee337cf8d2193bf Mon Sep 17 00:00:00 2001 From: John Ericson Date: Thu, 4 Jun 2020 20:42:25 +0000 Subject: Flip boolean Thanks Matt! --- src/libstore/local-store.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libstore/local-store.cc b/src/libstore/local-store.cc index 804d4c514..ba5436ca4 100644 --- a/src/libstore/local-store.cc +++ b/src/libstore/local-store.cc @@ -1007,7 +1007,7 @@ void LocalStore::addToStore(const ValidPathInfo & info, Source & source, /* While restoring the path from the NAR, compute the hash of the NAR. */ std::unique_ptr hashSink; - if (info.ca.has_value() || !info.references.count(info.path)) + if (!info.ca.has_value() || !info.references.count(info.path)) hashSink = std::make_unique(HashType::SHA256); else hashSink = std::make_unique(HashType::SHA256, storePathToHash(printStorePath(info.path))); -- cgit v1.2.3 From 94ddea9e2fffe2c0818653c509f881ae00f14d93 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Thu, 4 Jun 2020 20:54:55 +0000 Subject: Use `readString` rather than `>> temporary` Fixed the rest of these before, but this one slipped through. --- src/libstore/daemon.cc | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/libstore/daemon.cc b/src/libstore/daemon.cc index 0734f990a..63b8d4bfe 100644 --- a/src/libstore/daemon.cc +++ b/src/libstore/daemon.cc @@ -708,11 +708,7 @@ static void performOp(TunnelLogger * logger, ref store, info.references = readStorePaths(*store, from); from >> info.registrationTime >> info.narSize >> info.ultimate; info.sigs = readStrings(from); - { - string caOptRaw; - from >> caOptRaw; - info.ca = parseContentAddressOpt(caOptRaw); - } + info.ca = parseContentAddressOpt(readString(from)); from >> repair >> dontCheckSigs; if (!trusted && dontCheckSigs) dontCheckSigs = false; -- cgit v1.2.3 From a7b82fd006606dad591f8da88907e79b4c87b1f7 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Thu, 4 Jun 2020 21:04:20 +0000 Subject: Remove file which shouldn't be committed --- src/libutil/tests/libutil-tests | Bin 9399624 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100755 src/libutil/tests/libutil-tests diff --git a/src/libutil/tests/libutil-tests b/src/libutil/tests/libutil-tests deleted file mode 100755 index ae871b466..000000000 Binary files a/src/libutil/tests/libutil-tests and /dev/null differ -- cgit v1.2.3 From d614166cb6864f2448b9e03f8dccccf301dc541e Mon Sep 17 00:00:00 2001 From: Carlo Nucera Date: Thu, 4 Jun 2020 17:21:21 -0400 Subject: Fix condition error and make test suite pass --- src/libstore/local-store.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libstore/local-store.cc b/src/libstore/local-store.cc index ba5436ca4..37c9a2bc3 100644 --- a/src/libstore/local-store.cc +++ b/src/libstore/local-store.cc @@ -1265,7 +1265,7 @@ bool LocalStore::verifyStore(bool checkContents, RepairFlag repair) printMsg(Verbosity::Talkative, "checking contents of '%s'", printStorePath(i)); std::unique_ptr hashSink; - if (info->ca || !info->references.count(info->path)) + if (!info->ca || !info->references.count(info->path)) hashSink = std::make_unique(*info->narHash.type); else hashSink = std::make_unique(*info->narHash.type, storePathToHash(printStorePath(info->path))); -- cgit v1.2.3 From cd6dbf951a0ea903d0e9f2671fb127ae419e5ed2 Mon Sep 17 00:00:00 2001 From: Tobias Pflug Date: Mon, 8 Jun 2020 11:34:37 +0200 Subject: Add compression unit tests --- src/libutil/tests/compression.cc | 78 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 src/libutil/tests/compression.cc diff --git a/src/libutil/tests/compression.cc b/src/libutil/tests/compression.cc new file mode 100644 index 000000000..5b7a2c5b9 --- /dev/null +++ b/src/libutil/tests/compression.cc @@ -0,0 +1,78 @@ +#include "compression.hh" +#include + +namespace nix { + + /* ---------------------------------------------------------------------------- + * compress / decompress + * --------------------------------------------------------------------------*/ + + TEST(compress, compressWithUnknownMethod) { + ASSERT_THROW(compress("invalid-method", "something-to-compress"), UnknownCompressionMethod); + } + + TEST(compress, noneMethodDoesNothingToTheInput) { + ref o = compress("none", "this-is-a-test"); + + ASSERT_EQ(*o, "this-is-a-test"); + } + + TEST(decompress, decompressXzCompressed) { + auto method = "xz"; + auto str = "slfja;sljfklsa;jfklsjfkl;sdjfkl;sadjfkl;sdjf;lsdfjsadlf"; + ref o = decompress(method, *compress(method, str)); + + ASSERT_EQ(*o, str); + } + + TEST(decompress, decompressBzip2Compressed) { + auto method = "bzip2"; + auto str = "slfja;sljfklsa;jfklsjfkl;sdjfkl;sadjfkl;sdjf;lsdfjsadlf"; + ref o = decompress(method, *compress(method, str)); + + ASSERT_EQ(*o, str); + } + + TEST(decompress, decompressBrCompressed) { + auto method = "br"; + auto str = "slfja;sljfklsa;jfklsjfkl;sdjfkl;sadjfkl;sdjf;lsdfjsadlf"; + ref o = decompress(method, *compress(method, str)); + + ASSERT_EQ(*o, str); + } + + TEST(decompress, decompressInvalidInputThrowsCompressionError) { + auto method = "bzip2"; + auto str = "this is a string that does not qualify as valid bzip2 data"; + + ASSERT_THROW(decompress(method, str), CompressionError); + } + + /* ---------------------------------------------------------------------------- + * compression sinks + * --------------------------------------------------------------------------*/ + + TEST(makeCompressionSink, noneSinkDoesNothingToInput) { + StringSink strSink; + auto inputString = "slfja;sljfklsa;jfklsjfkl;sdjfkl;sadjfkl;sdjf;lsdfjsadlf"; + auto sink = makeCompressionSink("none", strSink); + (*sink)(inputString); + sink->finish(); + + ASSERT_STREQ((*strSink.s).c_str(), inputString); + } + + TEST(makeCompressionSink, compressAndDecompress) { + StringSink strSink; + auto inputString = "slfja;sljfklsa;jfklsjfkl;sdjfkl;sadjfkl;sdjf;lsdfjsadlf"; + auto decompressionSink = makeDecompressionSink("bzip2", strSink); + auto sink = makeCompressionSink("bzip2", *decompressionSink); + + (*sink)(inputString); + sink->finish(); + decompressionSink->finish(); + + ASSERT_STREQ((*strSink.s).c_str(), inputString); + } + +} -- cgit v1.2.3 From c9d06558b6cfb30cb6ad7d872ec1046434645b3b Mon Sep 17 00:00:00 2001 From: p01arst0rm Date: Wed, 17 Jun 2020 03:15:47 +0100 Subject: replaced uncaught_exception with uncaught_exceptions --- src/libstore/remote-store.cc | 2 +- src/libutil/json.cc | 2 +- src/libutil/util.cc | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libstore/remote-store.cc b/src/libstore/remote-store.cc index fc5ab5865..f5f2ab7fd 100644 --- a/src/libstore/remote-store.cc +++ b/src/libstore/remote-store.cc @@ -228,7 +228,7 @@ struct ConnectionHandle ~ConnectionHandle() { - if (!daemonException && std::uncaught_exception()) { + if (!daemonException && std::uncaught_exceptions()) { handle.markBad(); debug("closing daemon connection because of an exception"); } diff --git a/src/libutil/json.cc b/src/libutil/json.cc index 74e37b4c4..01331947e 100644 --- a/src/libutil/json.cc +++ b/src/libutil/json.cc @@ -173,7 +173,7 @@ JSONObject JSONPlaceholder::object() JSONPlaceholder::~JSONPlaceholder() { - assert(!first || std::uncaught_exception()); + assert(!first || std::uncaught_exceptions()); } } diff --git a/src/libutil/util.cc b/src/libutil/util.cc index 667dd2edb..6ca9013a4 100644 --- a/src/libutil/util.cc +++ b/src/libutil/util.cc @@ -1199,7 +1199,7 @@ void _interrupted() /* Block user interrupts while an exception is being handled. Throwing an exception while another exception is being handled kills the program! */ - if (!interruptThrown && !std::uncaught_exception()) { + if (!interruptThrown && !std::uncaught_exceptions()) { interruptThrown = true; throw Interrupted("interrupted by the user"); } -- cgit v1.2.3 From e9970a34e8841faaecd39ba18e0913101beca592 Mon Sep 17 00:00:00 2001 From: p01arst0rm Date: Wed, 17 Jun 2020 03:19:15 +0100 Subject: appended ' __attribute__((weak)); ' to 'extern char * * environ ' --- src/libutil/util.cc | 2 +- src/nix-build/nix-build.cc | 2 +- src/nix/command.cc | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libutil/util.cc b/src/libutil/util.cc index 667dd2edb..85246ced6 100644 --- a/src/libutil/util.cc +++ b/src/libutil/util.cc @@ -35,7 +35,7 @@ #endif -extern char * * environ; +extern char * * environ __attribute__((weak)); namespace nix { diff --git a/src/nix-build/nix-build.cc b/src/nix-build/nix-build.cc index a224d635d..f77de56ea 100755 --- a/src/nix-build/nix-build.cc +++ b/src/nix-build/nix-build.cc @@ -21,7 +21,7 @@ using namespace nix; using namespace std::string_literals; -extern char * * environ; +extern char * * environ __attribute__((weak)); /* Recreate the effect of the perl shellwords function, breaking up a * string into arguments like a shell word, including escapes diff --git a/src/nix/command.cc b/src/nix/command.cc index d62626c26..3651a9e9c 100644 --- a/src/nix/command.cc +++ b/src/nix/command.cc @@ -4,7 +4,7 @@ #include "nixexpr.hh" #include "profiles.hh" -extern char * * environ; +extern char * * environ __attribute__((weak)); namespace nix { -- cgit v1.2.3 From 9ce994d45eab1f89c2e3d485d7486a10fa219479 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 17 Jun 2020 10:02:33 +0200 Subject: Remove rustfmt --- shell.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shell.nix b/shell.nix index e3b422c7c..17aaa05ed 100644 --- a/shell.nix +++ b/shell.nix @@ -7,7 +7,7 @@ with import ./release-common.nix { inherit pkgs; }; (if useClang then clangStdenv else stdenv).mkDerivation { name = "nix"; - buildInputs = buildDeps ++ propagatedDeps ++ perlDeps ++ [ pkgs.rustfmt ]; + buildInputs = buildDeps ++ propagatedDeps ++ perlDeps; inherit configureFlags; -- cgit v1.2.3 From da8aac6ce8a73a7c9dc6d3cdfa27ab074f0bc976 Mon Sep 17 00:00:00 2001 From: Joe Hermaszewski Date: Wed, 17 Jun 2020 13:41:25 +0800 Subject: Mention number of derivations to be build/fetched in output Also correct grammar for the case of a single derivation. --- doc/manual/advanced-topics/diff-hook.xml | 6 +++--- doc/manual/advanced-topics/post-build-hook.xml | 2 +- doc/manual/command-ref/nix-env.xml | 2 +- src/libmain/shared.cc | 20 ++++++++++++++++---- 4 files changed, 21 insertions(+), 9 deletions(-) diff --git a/doc/manual/advanced-topics/diff-hook.xml b/doc/manual/advanced-topics/diff-hook.xml index fb4bf819f..f01ab71b3 100644 --- a/doc/manual/advanced-topics/diff-hook.xml +++ b/doc/manual/advanced-topics/diff-hook.xml @@ -70,7 +70,7 @@ path just built. $ nix-build ./deterministic.nix -A stable -these derivations will be built: +this derivation will be built: /nix/store/z98fasz2jqy9gs0xbvdj939p27jwda38-stable.drv building '/nix/store/z98fasz2jqy9gs0xbvdj939p27jwda38-stable.drv'... /nix/store/yyxlzw3vqaas7wfp04g0b1xg51f2czgq-stable @@ -85,7 +85,7 @@ checking outputs of '/nix/store/z98fasz2jqy9gs0xbvdj939p27jwda38-stable.drv'... $ nix-build ./deterministic.nix -A unstable -these derivations will be built: +this derivation will be built: /nix/store/cgl13lbj1w368r5z8gywipl1ifli7dhk-unstable.drv building '/nix/store/cgl13lbj1w368r5z8gywipl1ifli7dhk-unstable.drv'... /nix/store/krpqk0l9ib0ibi1d2w52z293zw455cap-unstable @@ -193,7 +193,7 @@ repeat = 1 An example output of this configuration: $ nix-build ./test.nix -A unstable -these derivations will be built: +this derivation will be built: /nix/store/ch6llwpr2h8c3jmnf3f2ghkhx59aa97f-unstable.drv building '/nix/store/ch6llwpr2h8c3jmnf3f2ghkhx59aa97f-unstable.drv' (round 1/2)... building '/nix/store/ch6llwpr2h8c3jmnf3f2ghkhx59aa97f-unstable.drv' (round 2/2)... diff --git a/doc/manual/advanced-topics/post-build-hook.xml b/doc/manual/advanced-topics/post-build-hook.xml index acfe9e3cc..6cc286ee1 100644 --- a/doc/manual/advanced-topics/post-build-hook.xml +++ b/doc/manual/advanced-topics/post-build-hook.xml @@ -122,7 +122,7 @@ post-build-hook = /etc/nix/upload-to-cache.sh $ nix-build -E '(import <nixpkgs> {}).writeText "example" (builtins.toString builtins.currentTime)' -these derivations will be built: +this derivation will be built: /nix/store/s4pnfbkalzy5qz57qs6yybna8wylkig6-example.drv building '/nix/store/s4pnfbkalzy5qz57qs6yybna8wylkig6-example.drv'... running post-build-hook '/home/grahamc/projects/github.com/NixOS/nix/post-hook.sh'... diff --git a/doc/manual/command-ref/nix-env.xml b/doc/manual/command-ref/nix-env.xml index 2b95b6819..55f25d959 100644 --- a/doc/manual/command-ref/nix-env.xml +++ b/doc/manual/command-ref/nix-env.xml @@ -516,7 +516,7 @@ source: $ nix-env -f '<nixpkgs>' -iA hello --dry-run (dry run; not doing anything) installing ‘hello-2.10’ -these paths will be fetched (0.04 MiB download, 0.19 MiB unpacked): +this path will be fetched (0.04 MiB download, 0.19 MiB unpacked): /nix/store/wkhdf9jinag5750mqlax6z2zbwhqb76n-hello-2.10 ... diff --git a/src/libmain/shared.cc b/src/libmain/shared.cc index dc6d5e413..1cb422967 100644 --- a/src/libmain/shared.cc +++ b/src/libmain/shared.cc @@ -48,7 +48,10 @@ void printMissing(ref store, const StorePathSet & willBuild, unsigned long long downloadSize, unsigned long long narSize, Verbosity lvl) { if (!willBuild.empty()) { - printMsg(lvl, "these derivations will be built:"); + if (willBuild.size() == 1) + printMsg(lvl, fmt("this derivation will be built:")); + else + printMsg(lvl, fmt("these %d derivations will be built:", willBuild.size())); auto sorted = store->topoSortPaths(willBuild); reverse(sorted.begin(), sorted.end()); for (auto & i : sorted) @@ -56,9 +59,18 @@ void printMissing(ref store, const StorePathSet & willBuild, } if (!willSubstitute.empty()) { - printMsg(lvl, fmt("these paths will be fetched (%.2f MiB download, %.2f MiB unpacked):", - downloadSize / (1024.0 * 1024.0), - narSize / (1024.0 * 1024.0))); + const float downloadSizeMiB = downloadSize / (1024.f * 1024.f); + const float narSizeMiB = narSize / (1024.f * 1024.f); + if (willSubstitute.size() == 1) { + printMsg(lvl, fmt("this path will be fetched (%.2f MiB download, %.2f MiB unpacked):", + downloadSizeMiB, + narSizeMiB)); + } else { + printMsg(lvl, fmt("these %d paths will be fetched (%.2f MiB download, %.2f MiB unpacked):", + willSubstitute.size(), + downloadSizeMiB, + narSizeMiB)); + } for (auto & i : willSubstitute) printMsg(lvl, fmt(" %s", store->printStorePath(i))); } -- cgit v1.2.3 From 56d75bf4fcb06da1a577c6e381f4afef57f30243 Mon Sep 17 00:00:00 2001 From: regnat Date: Wed, 17 Jun 2020 15:39:10 +0200 Subject: Reserve the `__contentAddressed` derivation parameter Not implementing anything here, just throwing an error if a derivation sets `__contentAddressed = true` without `--experimental-features content-addressed-paths` (and also with it as there's nothing implemented yet) --- src/libstore/build.cc | 11 +++++++++++ src/libstore/parsed-derivations.cc | 5 +++++ src/libstore/parsed-derivations.hh | 2 ++ 3 files changed, 18 insertions(+) diff --git a/src/libstore/build.cc b/src/libstore/build.cc index 53a0958aa..9b72175c7 100644 --- a/src/libstore/build.cc +++ b/src/libstore/build.cc @@ -809,6 +809,9 @@ private: /* Whether this is a fixed-output derivation. */ bool fixedOutput; + /* Whether this is a content adressed derivation */ + bool contentAddressed = false; + /* Whether to run the build in a private network namespace. */ bool privateNetwork = false; @@ -1195,6 +1198,14 @@ void DerivationGoal::haveDerivation() parsedDrv = std::make_unique(drvPath, *drv); + contentAddressed = parsedDrv->contentAddressed(); + + if (this->contentAddressed) { + settings.requireExperimentalFeature("content-addressed-paths"); + throw Error("content-addressed-paths isn't implemented yet"); + } + + /* We are first going to try to create the invalid output paths through substitutes. If that doesn't work, we'll build them. */ diff --git a/src/libstore/parsed-derivations.cc b/src/libstore/parsed-derivations.cc index 24f848e46..c7797b730 100644 --- a/src/libstore/parsed-derivations.cc +++ b/src/libstore/parsed-derivations.cc @@ -117,4 +117,9 @@ bool ParsedDerivation::substitutesAllowed() const return getBoolAttr("allowSubstitutes", true); } +bool ParsedDerivation::contentAddressed() const +{ + return getBoolAttr("__contentAddressed", false); +} + } diff --git a/src/libstore/parsed-derivations.hh b/src/libstore/parsed-derivations.hh index 7621342d7..d24d1eb4f 100644 --- a/src/libstore/parsed-derivations.hh +++ b/src/libstore/parsed-derivations.hh @@ -34,6 +34,8 @@ public: bool willBuildLocally() const; bool substitutesAllowed() const; + + bool contentAddressed() const; }; } -- cgit v1.2.3 From 6403508f5a2fcf073b2a0d4e5fcf5f5ebb890384 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Wed, 17 Jun 2020 15:13:00 +0000 Subject: Use `ansicolor.hh` in `nix repl` rather than duplicates --- src/libutil/ansicolor.hh | 2 ++ src/nix/repl.cc | 33 +++++++++++++-------------------- 2 files changed, 15 insertions(+), 20 deletions(-) diff --git a/src/libutil/ansicolor.hh b/src/libutil/ansicolor.hh index 8ae07b092..a38c2d798 100644 --- a/src/libutil/ansicolor.hh +++ b/src/libutil/ansicolor.hh @@ -11,5 +11,7 @@ namespace nix { #define ANSI_GREEN "\e[32;1m" #define ANSI_YELLOW "\e[33;1m" #define ANSI_BLUE "\e[34;1m" +#define ANSI_MAGENTA "\e[35m;1m" +#define ANSI_CYAN "\e[36m;1m" } diff --git a/src/nix/repl.cc b/src/nix/repl.cc index 4bcaaeebf..617d49614 100644 --- a/src/nix/repl.cc +++ b/src/nix/repl.cc @@ -19,6 +19,7 @@ extern "C" { } #endif +#include "ansicolor.hh" #include "shared.hh" #include "eval.hh" #include "eval-inline.hh" @@ -37,14 +38,6 @@ extern "C" { namespace nix { -#define ESC_RED "\033[31m" -#define ESC_GRE "\033[32m" -#define ESC_YEL "\033[33m" -#define ESC_BLU "\033[34;1m" -#define ESC_MAG "\033[35m" -#define ESC_CYA "\033[36m" -#define ESC_END "\033[0m" - struct NixRepl : gc { string curDir; @@ -645,25 +638,25 @@ std::ostream & NixRepl::printValue(std::ostream & str, Value & v, unsigned int m switch (v.type) { case tInt: - str << ESC_CYA << v.integer << ESC_END; + str << ANSI_CYAN << v.integer << ANSI_NORMAL; break; case tBool: - str << ESC_CYA << (v.boolean ? "true" : "false") << ESC_END; + str << ANSI_CYAN << (v.boolean ? "true" : "false") << ANSI_NORMAL; break; case tString: - str << ESC_YEL; + str << ANSI_YELLOW; printStringValue(str, v.string.s); - str << ESC_END; + str << ANSI_NORMAL; break; case tPath: - str << ESC_GRE << v.path << ESC_END; // !!! escaping? + str << ANSI_GREEN << v.path << ANSI_NORMAL; // !!! escaping? break; case tNull: - str << ESC_CYA "null" ESC_END; + str << ANSI_CYAN "null" ANSI_NORMAL; break; case tAttrs: { @@ -699,7 +692,7 @@ std::ostream & NixRepl::printValue(std::ostream & str, Value & v, unsigned int m try { printValue(str, *i.second, maxDepth - 1, seen); } catch (AssertionError & e) { - str << ESC_RED "«error: " << e.msg() << "»" ESC_END; + str << ANSI_RED "«error: " << e.msg() << "»" ANSI_NORMAL; } str << "; "; } @@ -725,7 +718,7 @@ std::ostream & NixRepl::printValue(std::ostream & str, Value & v, unsigned int m try { printValue(str, *v.listElems()[n], maxDepth - 1, seen); } catch (AssertionError & e) { - str << ESC_RED "«error: " << e.msg() << "»" ESC_END; + str << ANSI_RED "«error: " << e.msg() << "»" ANSI_NORMAL; } str << " "; } @@ -737,16 +730,16 @@ std::ostream & NixRepl::printValue(std::ostream & str, Value & v, unsigned int m case tLambda: { std::ostringstream s; s << v.lambda.fun->pos; - str << ESC_BLU "«lambda @ " << filterANSIEscapes(s.str()) << "»" ESC_END; + str << ANSI_BLUE "«lambda @ " << filterANSIEscapes(s.str()) << "»" ANSI_NORMAL; break; } case tPrimOp: - str << ESC_MAG "«primop»" ESC_END; + str << ANSI_MAGENTA "«primop»" ANSI_NORMAL; break; case tPrimOpApp: - str << ESC_BLU "«primop-app»" ESC_END; + str << ANSI_BLUE "«primop-app»" ANSI_NORMAL; break; case tFloat: @@ -754,7 +747,7 @@ std::ostream & NixRepl::printValue(std::ostream & str, Value & v, unsigned int m break; default: - str << ESC_RED "«unknown»" ESC_END; + str << ANSI_RED "«unknown»" ANSI_NORMAL; break; } -- cgit v1.2.3 From 079c6e87deb100bf21f35150736f9662557e698e Mon Sep 17 00:00:00 2001 From: Carlo Nucera Date: Wed, 17 Jun 2020 11:16:16 -0400 Subject: Make successful states coherent The successful states used in these two places in the code were slightly different. Should they be the same list? --- src/libstore/filetransfer.cc | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/libstore/filetransfer.cc b/src/libstore/filetransfer.cc index c954ace7f..081960912 100644 --- a/src/libstore/filetransfer.cc +++ b/src/libstore/filetransfer.cc @@ -72,6 +72,8 @@ struct curlFileTransfer : public FileTransfer curl_off_t writtenToSink = 0; + inline static const std::set successfulStatuses; + /* Get the HTTP status code, or 0 for other protocols. */ long getHTTPStatus() { @@ -98,7 +100,7 @@ struct curlFileTransfer : public FileTransfer /* Only write data to the sink if this is a successful response. */ - if (httpStatus == 0 || httpStatus == 200 || httpStatus == 201 || httpStatus == 206) { + if (successfulStatuses.find(httpStatus) != successfulStatuses.end()) { writtenToSink += len; this->request.dataCallback((char *) data, len); } @@ -352,8 +354,7 @@ struct curlFileTransfer : public FileTransfer if (writeException) failEx(writeException); - else if (code == CURLE_OK && - (httpStatus == 200 || httpStatus == 201 || httpStatus == 204 || httpStatus == 206 || httpStatus == 304 || httpStatus == 0 /* other protocol */)) + else if (code == CURLE_OK && successfulStatuses.find(httpStatus) != successfulStatuses.end()) { result.cached = httpStatus == 304; act.progress(result.bodySize, result.bodySize); -- cgit v1.2.3 From 480b54e1c6a200a2d4a39c1fa24fa195db12953f Mon Sep 17 00:00:00 2001 From: regnat Date: Wed, 17 Jun 2020 17:36:33 +0200 Subject: fixup! Reserve the `__contentAddressed` derivation parameter --- src/libstore/build.cc | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/libstore/build.cc b/src/libstore/build.cc index 9b72175c7..e1d812b09 100644 --- a/src/libstore/build.cc +++ b/src/libstore/build.cc @@ -809,9 +809,6 @@ private: /* Whether this is a fixed-output derivation. */ bool fixedOutput; - /* Whether this is a content adressed derivation */ - bool contentAddressed = false; - /* Whether to run the build in a private network namespace. */ bool privateNetwork = false; @@ -1198,9 +1195,7 @@ void DerivationGoal::haveDerivation() parsedDrv = std::make_unique(drvPath, *drv); - contentAddressed = parsedDrv->contentAddressed(); - - if (this->contentAddressed) { + if (parsedDrv->contentAddressed()) { settings.requireExperimentalFeature("content-addressed-paths"); throw Error("content-addressed-paths isn't implemented yet"); } -- cgit v1.2.3 From 4930cb48a258b0a69a8669602964e3956592ae5c Mon Sep 17 00:00:00 2001 From: Carlo Nucera Date: Wed, 17 Jun 2020 12:58:59 -0400 Subject: Include review comments --- src/libstore/filetransfer.cc | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/libstore/filetransfer.cc b/src/libstore/filetransfer.cc index 081960912..531b85af8 100644 --- a/src/libstore/filetransfer.cc +++ b/src/libstore/filetransfer.cc @@ -72,8 +72,7 @@ struct curlFileTransfer : public FileTransfer curl_off_t writtenToSink = 0; - inline static const std::set successfulStatuses; - + inline static const std::set successfulStatuses {200, 201, 204, 206, 304, 0 /* other protocol */}; /* Get the HTTP status code, or 0 for other protocols. */ long getHTTPStatus() { @@ -100,7 +99,7 @@ struct curlFileTransfer : public FileTransfer /* Only write data to the sink if this is a successful response. */ - if (successfulStatuses.find(httpStatus) != successfulStatuses.end()) { + if (successfulStatuses.count(httpStatus)) { writtenToSink += len; this->request.dataCallback((char *) data, len); } @@ -354,7 +353,7 @@ struct curlFileTransfer : public FileTransfer if (writeException) failEx(writeException); - else if (code == CURLE_OK && successfulStatuses.find(httpStatus) != successfulStatuses.end()) + else if (code == CURLE_OK && successfulStatuses.count(httpStatus)) { result.cached = httpStatus == 304; act.progress(result.bodySize, result.bodySize); -- cgit v1.2.3 From f767bedfac66bff297499f68b234ac63b02c8f62 Mon Sep 17 00:00:00 2001 From: Matthew Bauer Date: Wed, 17 Jun 2020 13:26:37 -0400 Subject: Replace struct StorePath with class StorePath also a similar case with struct Goal --- src/libexpr/eval.hh | 2 +- src/libstore/build.cc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libexpr/eval.hh b/src/libexpr/eval.hh index 1485dc7fe..064b1a623 100644 --- a/src/libexpr/eval.hh +++ b/src/libexpr/eval.hh @@ -18,7 +18,7 @@ namespace nix { class Store; class EvalState; -struct StorePath; +class StorePath; enum RepairFlag : bool; diff --git a/src/libstore/build.cc b/src/libstore/build.cc index e1d812b09..3afebfcf4 100644 --- a/src/libstore/build.cc +++ b/src/libstore/build.cc @@ -86,7 +86,7 @@ struct HookInstance; /* A pointer to a goal. */ -class Goal; +struct Goal; class DerivationGoal; typedef std::shared_ptr GoalPtr; typedef std::weak_ptr WeakGoalPtr; -- cgit v1.2.3 From 22d7d36703df637980d0dcbe3ad030114662840e Mon Sep 17 00:00:00 2001 From: Matthew Bauer Date: Wed, 17 Jun 2020 13:27:10 -0400 Subject: Remove unused narInfoFile in binary-cache-store --- src/libstore/binary-cache-store.cc | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/libstore/binary-cache-store.cc b/src/libstore/binary-cache-store.cc index f8eff508c..9f52ddafa 100644 --- a/src/libstore/binary-cache-store.cc +++ b/src/libstore/binary-cache-store.cc @@ -388,8 +388,6 @@ void BinaryCacheStore::addSignatures(const StorePath & storePath, const StringSe narInfo->sigs.insert(sigs.begin(), sigs.end()); - auto narInfoFile = narInfoFileFor(narInfo->path); - writeNarInfo(narInfo); } -- cgit v1.2.3 From 4fef2ba7e4f344eec32cdf02821d32036fbbc21b Mon Sep 17 00:00:00 2001 From: regnat Date: Thu, 18 Jun 2020 09:25:55 +0200 Subject: Rename content-addressed-paths into ca-derivations See --- src/libstore/build.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libstore/build.cc b/src/libstore/build.cc index 3afebfcf4..3b0efa1a5 100644 --- a/src/libstore/build.cc +++ b/src/libstore/build.cc @@ -1196,8 +1196,8 @@ void DerivationGoal::haveDerivation() parsedDrv = std::make_unique(drvPath, *drv); if (parsedDrv->contentAddressed()) { - settings.requireExperimentalFeature("content-addressed-paths"); - throw Error("content-addressed-paths isn't implemented yet"); + settings.requireExperimentalFeature("ca-derivations"); + throw Error("ca-derivations isn't implemented yet"); } -- cgit v1.2.3 From 9069759767cf1821578be8006cda52ee53ecd427 Mon Sep 17 00:00:00 2001 From: Samir Talwar Date: Thu, 18 Jun 2020 10:29:24 +0200 Subject: Instruct the user to follow redirects when installing Nix. Nix installation now requires following redirects using `curl -L`. This is currently represented on the [Nix download page][] but not in the manual. This change updates the manual to reflect this. Using `curl` without the `-L` flag results in an empty body, making installation a no-op. [Nix download page]: https://nixos.org/download.html --- doc/manual/installation/env-variables.xml | 2 +- doc/manual/installation/installing-binary.xml | 4 ++-- doc/manual/introduction/quick-start.xml | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/doc/manual/installation/env-variables.xml b/doc/manual/installation/env-variables.xml index e2b8fc867..cc52f5b4a 100644 --- a/doc/manual/installation/env-variables.xml +++ b/doc/manual/installation/env-variables.xml @@ -39,7 +39,7 @@ bundle. Set the environment variable and install Nix $ export NIX_SSL_CERT_FILE=/etc/ssl/my-certificate-bundle.crt -$ sh <(curl https://nixos.org/nix/install) +$ sh <(curl -L https://nixos.org/nix/install) In the shell profile and rc files (for example, diff --git a/doc/manual/installation/installing-binary.xml b/doc/manual/installation/installing-binary.xml index 8d548f0ea..d25c46b85 100644 --- a/doc/manual/installation/installing-binary.xml +++ b/doc/manual/installation/installing-binary.xml @@ -12,7 +12,7 @@ - $ sh <(curl https://nixos.org/nix/install) + $ sh <(curl -L https://nixos.org/nix/install) @@ -39,7 +39,7 @@ To explicitly select a single-user installation on your system: - sh <(curl https://nixos.org/nix/install) --no-daemon + sh <(curl -L https://nixos.org/nix/install) --no-daemon diff --git a/doc/manual/introduction/quick-start.xml b/doc/manual/introduction/quick-start.xml index 1ce6c8d50..1992c14ed 100644 --- a/doc/manual/introduction/quick-start.xml +++ b/doc/manual/introduction/quick-start.xml @@ -15,7 +15,7 @@ to subsequent chapters. Install single-user Nix by running the following: -$ bash <(curl https://nixos.org/nix/install) +$ bash <(curl -L https://nixos.org/nix/install) This will install Nix in /nix. The install script -- cgit v1.2.3 From 7083d33efee2b4782c52dc04d90f7c08e96b79d1 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 29 Nov 2018 16:28:43 +0100 Subject: Make constant primops lazy (cherry picked from commit aa0e2a2e70a3519a9dcb9b1da000a13c01aa6cc1) --- src/libexpr/eval.cc | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc index 8e71db2b8..66f03fe1a 100644 --- a/src/libexpr/eval.cc +++ b/src/libexpr/eval.cc @@ -471,14 +471,21 @@ Value * EvalState::addConstant(const string & name, Value & v) Value * EvalState::addPrimOp(const string & name, size_t arity, PrimOpFun primOp) { + auto name2 = string(name, 0, 2) == "__" ? string(name, 2) : name; + Symbol sym = symbols.create(name2); + + /* Hack to make constants lazy: turn them into a application of + the primop to a dummy value. */ if (arity == 0) { + auto vPrimOp = allocValue(); + vPrimOp->type = tPrimOp; + vPrimOp->primOp = new PrimOp(primOp, 1, sym); Value v; - primOp(*this, noPos, nullptr, v); + mkApp(v, *vPrimOp, *vPrimOp); return addConstant(name, v); } + Value * v = allocValue(); - string name2 = string(name, 0, 2) == "__" ? string(name, 2) : name; - Symbol sym = symbols.create(name2); v->type = tPrimOp; v->primOp = new PrimOp(primOp, arity, sym); staticBaseEnv.vars[symbols.create(name)] = baseEnvDispl; -- cgit v1.2.3 From 2a61bbf77fd1b4bd518912b4923265b91a8f9d67 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 18 Jun 2020 13:44:40 +0200 Subject: Some backports from the flakes branch --- src/libexpr/attr-path.cc | 13 +++++++++++-- src/libexpr/attr-path.hh | 2 ++ src/libexpr/eval.cc | 26 ++++++++++++++++++++------ src/libexpr/eval.hh | 4 +++- src/libexpr/get-drvs.cc | 2 +- src/libexpr/primops.cc | 15 ++++++++------- 6 files changed, 45 insertions(+), 17 deletions(-) diff --git a/src/libexpr/attr-path.cc b/src/libexpr/attr-path.cc index 8980bc09d..2e2a17b14 100644 --- a/src/libexpr/attr-path.cc +++ b/src/libexpr/attr-path.cc @@ -6,11 +6,11 @@ namespace nix { -static Strings parseAttrPath(const string & s) +static Strings parseAttrPath(std::string_view s) { Strings res; string cur; - string::const_iterator i = s.begin(); + auto i = s.begin(); while (i != s.end()) { if (*i == '.') { res.push_back(cur); @@ -32,6 +32,15 @@ static Strings parseAttrPath(const string & s) } +std::vector parseAttrPath(EvalState & state, std::string_view s) +{ + std::vector res; + for (auto & a : parseAttrPath(s)) + res.push_back(state.symbols.create(a)); + return res; +} + + std::pair findAlongAttrPath(EvalState & state, const string & attrPath, Bindings & autoArgs, Value & vIn) { diff --git a/src/libexpr/attr-path.hh b/src/libexpr/attr-path.hh index fce160da7..d9d74ab2d 100644 --- a/src/libexpr/attr-path.hh +++ b/src/libexpr/attr-path.hh @@ -16,4 +16,6 @@ std::pair findAlongAttrPath(EvalState & state, const string & attr /* Heuristic to find the filename and lineno or a nix value. */ Pos findDerivationFilename(EvalState & state, Value & v, std::string what); +std::vector parseAttrPath(EvalState & state, std::string_view s); + } diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc index 66f03fe1a..b90a64357 100644 --- a/src/libexpr/eval.cc +++ b/src/libexpr/eval.cc @@ -161,12 +161,12 @@ const Value *getPrimOp(const Value &v) { } -string showType(const Value & v) +string showType(ValueType type) { - switch (v.type) { + switch (type) { case tInt: return "an integer"; - case tBool: return "a boolean"; - case tString: return v.string.context ? "a string with context" : "a string"; + case tBool: return "a Boolean"; + case tString: return "a string"; case tPath: return "a path"; case tNull: return "null"; case tAttrs: return "a set"; @@ -175,14 +175,27 @@ string showType(const Value & v) case tApp: return "a function application"; case tLambda: return "a function"; case tBlackhole: return "a black hole"; + case tPrimOp: return "a built-in function"; + case tPrimOpApp: return "a partially applied built-in function"; + case tExternal: return "an external value"; + case tFloat: return "a float"; + } + abort(); +} + + +string showType(const Value & v) +{ + switch (v.type) { + case tString: return v.string.context ? "a string with context" : "a string"; case tPrimOp: return fmt("the built-in function '%s'", string(v.primOp->name)); case tPrimOpApp: return fmt("the partially applied built-in function '%s'", string(getPrimOp(v)->primOp->name)); case tExternal: return v.external->showType(); - case tFloat: return "a float"; + default: + return showType(v.type); } - abort(); } @@ -323,6 +336,7 @@ EvalState::EvalState(const Strings & _searchPath, ref store) , sOutputHash(symbols.create("outputHash")) , sOutputHashAlgo(symbols.create("outputHashAlgo")) , sOutputHashMode(symbols.create("outputHashMode")) + , sRecurseForDerivations(symbols.create("recurseForDerivations")) , repair(NoRepair) , store(store) , baseEnv(allocEnv(128)) diff --git a/src/libexpr/eval.hh b/src/libexpr/eval.hh index 064b1a623..863365259 100644 --- a/src/libexpr/eval.hh +++ b/src/libexpr/eval.hh @@ -74,7 +74,8 @@ public: sSystem, sOverrides, sOutputs, sOutputName, sIgnoreNulls, sFile, sLine, sColumn, sFunctor, sToString, sRight, sWrong, sStructuredAttrs, sBuilder, sArgs, - sOutputHash, sOutputHashAlgo, sOutputHashMode; + sOutputHash, sOutputHashAlgo, sOutputHashMode, + sRecurseForDerivations; Symbol sDerivationNix; /* If set, force copying files to the Nix store even if they @@ -324,6 +325,7 @@ private: /* Return a string representing the type of the value `v'. */ +string showType(ValueType type); string showType(const Value & v); /* Decode a context string ‘!!’ into a pair Only if it has a `recurseForDerivations = true' attribute. */ if (i->value->type == tAttrs) { - Bindings::iterator j = i->value->attrs->find(state.symbols.create("recurseForDerivations")); + Bindings::iterator j = i->value->attrs->find(state.sRecurseForDerivations); if (j != i->value->attrs->end() && state.forceBool(*j->value, *j->pos)) getDerivations(state, *i->value, pathPrefix2, autoArgs, drvs, done, ignoreAssertionFailures); } diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc index 907f15246..bb1926282 100644 --- a/src/libexpr/primops.cc +++ b/src/libexpr/primops.cc @@ -50,20 +50,20 @@ void EvalState::realiseContext(const PathSet & context) std::vector drvs; for (auto & i : context) { - std::pair decoded = decodeContext(i); - auto ctx = store->parseStorePath(decoded.first); + auto [ctxS, outputName] = decodeContext(i); + auto ctx = store->parseStorePath(ctxS); if (!store->isValidPath(ctx)) throw InvalidPathError(store->printStorePath(ctx)); - if (!decoded.second.empty() && ctx.isDerivation()) { - drvs.push_back(StorePathWithOutputs{ctx, {decoded.second}}); + if (!outputName.empty() && ctx.isDerivation()) { + drvs.push_back(StorePathWithOutputs{ctx, {outputName}}); /* Add the output of this derivation to the allowed paths. */ if (allowedPaths) { - auto drv = store->derivationFromPath(store->parseStorePath(decoded.first)); - DerivationOutputs::iterator i = drv.outputs.find(decoded.second); + auto drv = store->derivationFromPath(ctx); + DerivationOutputs::iterator i = drv.outputs.find(outputName); if (i == drv.outputs.end()) - throw Error("derivation '%s' does not have an output named '%s'", decoded.first, decoded.second); + throw Error("derivation '%s' does not have an output named '%s'", ctxS, outputName); allowedPaths->insert(store->printStorePath(i->second.path)); } } @@ -79,6 +79,7 @@ void EvalState::realiseContext(const PathSet & context) StorePathSet willBuild, willSubstitute, unknown; unsigned long long downloadSize, narSize; store->queryMissing(drvs, willBuild, willSubstitute, unknown, downloadSize, narSize); + store->buildPaths(drvs); } -- cgit v1.2.3 From 5771c8bbf29325c24e55c75743194612228f4e07 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 17 Jun 2020 16:54:32 +0200 Subject: Don't provide 'getFlake' if the 'flakes' feature is not enabled (cherry picked from commit 0a1d3c1dd311f94e9d1f56e1aa7fe1ab34314ec1) --- src/libexpr/primops.cc | 8 +++++--- src/libexpr/primops.hh | 17 +++++++++++++++-- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc index bb1926282..2f1a41a64 100644 --- a/src/libexpr/primops.cc +++ b/src/libexpr/primops.cc @@ -2202,10 +2202,11 @@ static void prim_splitVersion(EvalState & state, const Pos & pos, Value * * args RegisterPrimOp::PrimOps * RegisterPrimOp::primOps; -RegisterPrimOp::RegisterPrimOp(std::string name, size_t arity, PrimOpFun fun) +RegisterPrimOp::RegisterPrimOp(std::string name, size_t arity, PrimOpFun fun, + std::optional requiredFeature) { if (!primOps) primOps = new PrimOps; - primOps->emplace_back(name, arity, fun); + primOps->push_back({name, arity, fun, requiredFeature}); } @@ -2397,7 +2398,8 @@ void EvalState::createBaseEnv() if (RegisterPrimOp::primOps) for (auto & primOp : *RegisterPrimOp::primOps) - addPrimOp(std::get<0>(primOp), std::get<1>(primOp), std::get<2>(primOp)); + if (!primOp.requiredFeature || settings.isExperimentalFeatureEnabled(*primOp.requiredFeature)) + addPrimOp(primOp.name, primOp.arity, primOp.primOp); /* Now that we've added all primops, sort the `builtins' set, because attribute lookups expect it to be sorted. */ diff --git a/src/libexpr/primops.hh b/src/libexpr/primops.hh index 05d0792ef..75c460ecf 100644 --- a/src/libexpr/primops.hh +++ b/src/libexpr/primops.hh @@ -7,12 +7,25 @@ namespace nix { struct RegisterPrimOp { - typedef std::vector> PrimOps; + struct Info + { + std::string name; + size_t arity; + PrimOpFun primOp; + std::optional requiredFeature; + }; + + typedef std::vector PrimOps; static PrimOps * primOps; + /* You can register a constant by passing an arity of 0. fun will get called during EvalState initialization, so there may be primops not yet added and builtins is not yet sorted. */ - RegisterPrimOp(std::string name, size_t arity, PrimOpFun fun); + RegisterPrimOp( + std::string name, + size_t arity, + PrimOpFun fun, + std::optional requiredFeature = {}); }; /* These primops are disabled without enableNativeCode, but plugins -- 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. --- perl/lib/Nix/Store.xs | 10 +-- src/build-remote/build-remote.cc | 8 +-- src/cpptoml/cpptoml.h | 6 +- src/libexpr/eval.cc | 4 +- src/libexpr/function-trace.cc | 4 +- src/libexpr/parser.y | 2 +- src/libexpr/primops.cc | 14 ++-- src/libexpr/primops/fetchGit.cc | 4 +- src/libexpr/primops/fetchMercurial.cc | 4 +- src/libexpr/primops/fetchTree.cc | 8 +-- src/libfetchers/fetchers.cc | 4 +- src/libfetchers/git.cc | 18 ++--- src/libfetchers/github.cc | 12 ++-- src/libfetchers/mercurial.cc | 12 ++-- src/libfetchers/path.cc | 4 +- src/libfetchers/tarball.cc | 12 ++-- src/libmain/common-args.cc | 8 +-- src/libmain/progress-bar.cc | 48 ++++++------- src/libmain/shared.cc | 2 +- src/libmain/shared.hh | 4 +- src/libstore/binary-cache-store.cc | 12 ++-- src/libstore/build.cc | 112 +++++++++++++------------------ src/libstore/builtins/fetchurl.cc | 2 +- src/libstore/daemon.cc | 23 ++----- src/libstore/derivations.cc | 8 +-- src/libstore/export-import.cc | 10 +-- src/libstore/filetransfer.cc | 6 +- src/libstore/gc.cc | 6 +- src/libstore/legacy-ssh-store.cc | 2 +- src/libstore/local-store.cc | 32 ++++----- src/libstore/local-store.hh | 2 +- src/libstore/misc.cc | 2 +- src/libstore/nar-info-disk-cache.cc | 4 +- src/libstore/nar-info.cc | 8 +-- src/libstore/optimise-store.cc | 16 ++--- src/libstore/path.cc | 2 +- src/libstore/references.cc | 4 +- src/libstore/remote-store.cc | 10 +-- src/libstore/remote-store.hh | 2 +- src/libstore/s3-binary-cache-store.cc | 4 +- src/libstore/ssh.cc | 4 +- src/libstore/store-api.cc | 34 +++++----- src/libstore/store-api.hh | 8 +-- src/libutil/args.hh | 2 +- src/libutil/compression.cc | 2 +- src/libutil/error.cc | 16 ++--- src/libutil/error.hh | 24 +++---- src/libutil/hash.cc | 67 +++++++++--------- src/libutil/hash.hh | 22 ++---- src/libutil/logging.cc | 22 +++--- src/libutil/logging.hh | 76 ++++++++++----------- src/libutil/tests/hash.cc | 16 ++--- src/libutil/tests/logging.cc | 18 ++--- src/libutil/util.cc | 4 +- src/nix-copy-closure/nix-copy-closure.cc | 4 +- src/nix-env/nix-env.cc | 6 +- src/nix-prefetch-url/nix-prefetch-url.cc | 2 +- src/nix-store/nix-store.cc | 18 ++--- 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 ++-- 68 files changed, 419 insertions(+), 458 deletions(-) diff --git a/perl/lib/Nix/Store.xs b/perl/lib/Nix/Store.xs index 619782d93..945ed49c7 100644 --- a/perl/lib/Nix/Store.xs +++ b/perl/lib/Nix/Store.xs @@ -106,7 +106,7 @@ SV * queryPathInfo(char * path, int base32) XPUSHs(&PL_sv_undef); else XPUSHs(sv_2mortal(newSVpv(store()->printStorePath(*info->deriver).c_str(), 0))); - auto s = info->narHash.to_string(base32 ? Base::Base32 : Base::Base16, true); + auto s = info->narHash.to_string(base32 ? Base32 : Base16, true); XPUSHs(sv_2mortal(newSVpv(s.c_str(), 0))); mXPUSHi(info->registrationTime); mXPUSHi(info->narSize); @@ -192,7 +192,7 @@ SV * hashPath(char * algo, int base32, char * path) PPCODE: try { Hash h = hashPath(parseHashType(algo), path).first; - auto s = h.to_string(base32 ? Base::Base32 : Base::Base16, false); + auto s = h.to_string(base32 ? Base32 : Base16, false); XPUSHs(sv_2mortal(newSVpv(s.c_str(), 0))); } catch (Error & e) { croak("%s", e.what()); @@ -203,7 +203,7 @@ SV * hashFile(char * algo, int base32, char * path) PPCODE: try { Hash h = hashFile(parseHashType(algo), path); - auto s = h.to_string(base32 ? Base::Base32 : Base::Base16, false); + auto s = h.to_string(base32 ? Base32 : Base16, false); XPUSHs(sv_2mortal(newSVpv(s.c_str(), 0))); } catch (Error & e) { croak("%s", e.what()); @@ -214,7 +214,7 @@ SV * hashString(char * algo, int base32, char * s) PPCODE: try { Hash h = hashString(parseHashType(algo), s); - auto s = h.to_string(base32 ? Base::Base32 : Base::Base16, false); + auto s = h.to_string(base32 ? Base32 : Base16, false); XPUSHs(sv_2mortal(newSVpv(s.c_str(), 0))); } catch (Error & e) { croak("%s", e.what()); @@ -225,7 +225,7 @@ SV * convertHash(char * algo, char * s, int toBase32) PPCODE: try { Hash h(s, parseHashType(algo)); - string s = h.to_string(toBase32 ? Base::Base32 : Base::Base16, false); + string s = h.to_string(toBase32 ? Base32 : Base16, false); XPUSHs(sv_2mortal(newSVpv(s.c_str(), 0))); } catch (Error & e) { croak("%s", e.what()); diff --git a/src/build-remote/build-remote.cc b/src/build-remote/build-remote.cc index e60d6736b..e07117496 100644 --- a/src/build-remote/build-remote.cc +++ b/src/build-remote/build-remote.cc @@ -184,7 +184,7 @@ static int _main(int argc, char * * argv) try { - Activity act(*logger, Verbosity::Talkative, ActivityType::Unknown, fmt("connecting to '%s'", bestMachine->storeUri)); + Activity act(*logger, lvlTalkative, actUnknown, fmt("connecting to '%s'", bestMachine->storeUri)); Store::Params storeParams; if (hasPrefix(bestMachine->storeUri, "ssh://")) { @@ -225,7 +225,7 @@ connected: AutoCloseFD uploadLock = openLockFile(currentLoad + "/" + escapeUri(storeUri) + ".upload-lock", true); { - Activity act(*logger, Verbosity::Talkative, ActivityType::Unknown, fmt("waiting for the upload lock to '%s'", storeUri)); + Activity act(*logger, lvlTalkative, actUnknown, fmt("waiting for the upload lock to '%s'", storeUri)); auto old = signal(SIGALRM, handleAlarm); alarm(15 * 60); @@ -238,7 +238,7 @@ connected: auto substitute = settings.buildersUseSubstitutes ? Substitute : NoSubstitute; { - Activity act(*logger, Verbosity::Talkative, ActivityType::Unknown, fmt("copying dependencies to '%s'", storeUri)); + Activity act(*logger, lvlTalkative, actUnknown, fmt("copying dependencies to '%s'", storeUri)); copyPaths(store, ref(sshStore), store->parseStorePathSet(inputs), NoRepair, NoCheckSigs, substitute); } @@ -257,7 +257,7 @@ connected: if (!store->isValidPath(store->parseStorePath(path))) missing.insert(store->parseStorePath(path)); if (!missing.empty()) { - Activity act(*logger, Verbosity::Talkative, ActivityType::Unknown, fmt("copying outputs from '%s'", storeUri)); + Activity act(*logger, lvlTalkative, actUnknown, fmt("copying outputs from '%s'", storeUri)); for (auto & i : missing) store->locksHeld.insert(store->printStorePath(i)); /* FIXME: ugly */ copyPaths(ref(sshStore), store, missing, NoRepair, NoCheckSigs, NoSubstitute); diff --git a/src/cpptoml/cpptoml.h b/src/cpptoml/cpptoml.h index fae1f0bc9..5a00da3b4 100644 --- a/src/cpptoml/cpptoml.h +++ b/src/cpptoml/cpptoml.h @@ -51,7 +51,7 @@ using string_to_base_map = std::unordered_map>; #endif -// if defined, `base` will retain type information in form of an enum struct +// if defined, `base` will retain type information in form of an enum class // such that static_cast can be used instead of dynamic_cast // #define CPPTOML_NO_RTTI @@ -405,7 +405,7 @@ inline std::shared_ptr make_table_array(bool is_inline = false); #if defined(CPPTOML_NO_RTTI) /// Base type used to store underlying data type explicitly if RTTI is disabled -enum struct base_type +enum class base_type { NONE, STRING, @@ -2268,7 +2268,7 @@ class parser return key; } - enum struct parse_type + enum class parse_type { STRING = 1, LOCAL_TIME, diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc index 64de248ca..b90a64357 100644 --- a/src/libexpr/eval.cc +++ b/src/libexpr/eval.cc @@ -1712,10 +1712,10 @@ string EvalState::copyPathToStore(PathSet & context, const Path & path) else { auto p = settings.readOnlyMode ? store->computeStorePathForPath(std::string(baseNameOf(path)), checkSourcePath(path)).first - : store->addToStore(std::string(baseNameOf(path)), checkSourcePath(path), FileIngestionMethod::Recursive, HashType::SHA256, defaultPathFilter, repair); + : store->addToStore(std::string(baseNameOf(path)), checkSourcePath(path), FileIngestionMethod::Recursive, htSHA256, defaultPathFilter, repair); dstPath = store->printStorePath(p); srcToStore.insert_or_assign(path, std::move(p)); - printMsg(Verbosity::Chatty, "copied source '%1%' -> '%2%'", path, dstPath); + printMsg(lvlChatty, "copied source '%1%' -> '%2%'", path, dstPath); } context.insert(dstPath); diff --git a/src/libexpr/function-trace.cc b/src/libexpr/function-trace.cc index 882da9937..c6057b384 100644 --- a/src/libexpr/function-trace.cc +++ b/src/libexpr/function-trace.cc @@ -6,13 +6,13 @@ namespace nix { FunctionCallTrace::FunctionCallTrace(const Pos & pos) : pos(pos) { auto duration = std::chrono::high_resolution_clock::now().time_since_epoch(); auto ns = std::chrono::duration_cast(duration); - printMsg(Verbosity::Info, "function-trace entered %1% at %2%", pos, ns.count()); + printMsg(lvlInfo, "function-trace entered %1% at %2%", pos, ns.count()); } FunctionCallTrace::~FunctionCallTrace() { auto duration = std::chrono::high_resolution_clock::now().time_since_epoch(); auto ns = std::chrono::duration_cast(duration); - printMsg(Verbosity::Info, "function-trace exited %1% at %2%", pos, ns.count()); + printMsg(lvlInfo, "function-trace exited %1% at %2%", pos, ns.count()); } } diff --git a/src/libexpr/parser.y b/src/libexpr/parser.y index 03097eaad..a639be64e 100644 --- a/src/libexpr/parser.y +++ b/src/libexpr/parser.y @@ -643,7 +643,7 @@ Expr * EvalState::parseExprFromString(std::string_view s, const Path & basePath) Expr * EvalState::parseStdin() { - //Activity act(*logger, Verbosity::Talkative, format("parsing standard input")); + //Activity act(*logger, lvlTalkative, format("parsing standard input")); return parseExprFromString(drainFD(0), absPath(".")); } diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc index 570f1848a..ea19a1cf0 100644 --- a/src/libexpr/primops.cc +++ b/src/libexpr/primops.cc @@ -778,7 +778,7 @@ static void prim_derivationStrict(EvalState & state, const Pos & pos, Value * * std::move(outPath), (ingestionMethod == FileIngestionMethod::Recursive ? "r:" : "") + printHashType(*h.type), - h.to_string(Base::Base16, false), + h.to_string(Base16, false), }); } @@ -809,7 +809,7 @@ static void prim_derivationStrict(EvalState & state, const Pos & pos, Value * * auto drvPath = writeDerivation(state.store, drv, drvName, state.repair); auto drvPathS = state.store->printStorePath(drvPath); - printMsg(Verbosity::Chatty, "instantiated '%1%' -> '%2%'", drvName, drvPathS); + printMsg(lvlChatty, "instantiated '%1%' -> '%2%'", drvName, drvPathS); /* Optimisation, but required in read-only mode! because in that case we don't actually write store derivations, so we can't @@ -1008,7 +1008,7 @@ static void prim_hashFile(EvalState & state, const Pos & pos, Value * * args, Va PathSet context; // discarded Path p = state.coerceToPath(pos, *args[1], context); - mkString(v, hashFile(*ht, state.checkSourcePath(p)).to_string(Base::Base16, false), context); + mkString(v, hashFile(*ht, state.checkSourcePath(p)).to_string(Base16, false), context); } /* Read a directory (without . or ..) */ @@ -1150,8 +1150,8 @@ static void addPath(EvalState & state, const Pos & pos, const string & name, con Path dstPath; if (!expectedHash || !state.store->isValidPath(*expectedStorePath)) { dstPath = state.store->printStorePath(settings.readOnlyMode - ? state.store->computeStorePathForPath(name, path, method, HashType::SHA256, filter).first - : state.store->addToStore(name, path, method, HashType::SHA256, filter, state.repair)); + ? state.store->computeStorePathForPath(name, path, method, htSHA256, filter).first + : state.store->addToStore(name, path, method, htSHA256, filter, state.repair)); if (expectedHash && expectedStorePath != state.store->parseStorePath(dstPath)) throw Error("store path mismatch in (possibly filtered) path added from '%s'", path); } else @@ -1210,7 +1210,7 @@ static void prim_path(EvalState & state, const Pos & pos, Value * * args, Value } else if (n == "recursive") method = FileIngestionMethod { state.forceBool(*attr.value, *attr.pos) }; else if (n == "sha256") - expectedHash = newHashAllowEmpty(state.forceStringNoCtx(*attr.value, *attr.pos), HashType::SHA256); + expectedHash = newHashAllowEmpty(state.forceStringNoCtx(*attr.value, *attr.pos), htSHA256); else throw EvalError({ .hint = hintfmt("unsupported argument '%1%' to 'addPath'", attr.name), @@ -1945,7 +1945,7 @@ static void prim_hashString(EvalState & state, const Pos & pos, Value * * args, PathSet context; // discarded string s = state.forceString(*args[1], context, pos); - mkString(v, hashString(*ht, s).to_string(Base::Base16, false), context); + mkString(v, hashString(*ht, s).to_string(Base16, false), context); } diff --git a/src/libexpr/primops/fetchGit.cc b/src/libexpr/primops/fetchGit.cc index 4d085c9a0..dd7229a3d 100644 --- a/src/libexpr/primops/fetchGit.cc +++ b/src/libexpr/primops/fetchGit.cc @@ -29,7 +29,7 @@ static void prim_fetchGit(EvalState & state, const Pos & pos, Value * * args, Va else if (n == "ref") ref = state.forceStringNoCtx(*attr.value, *attr.pos); else if (n == "rev") - rev = Hash(state.forceStringNoCtx(*attr.value, *attr.pos), HashType::SHA1); + rev = Hash(state.forceStringNoCtx(*attr.value, *attr.pos), htSHA1); else if (n == "name") name = state.forceStringNoCtx(*attr.value, *attr.pos); else if (n == "submodules") @@ -73,7 +73,7 @@ static void prim_fetchGit(EvalState & state, const Pos & pos, Value * * args, Va mkString(*state.allocAttr(v, state.sOutPath), storePath, PathSet({storePath})); // Backward compatibility: set 'rev' to // 0000000000000000000000000000000000000000 for a dirty tree. - auto rev2 = input2->getRev().value_or(Hash(HashType::SHA1)); + auto rev2 = input2->getRev().value_or(Hash(htSHA1)); mkString(*state.allocAttr(v, state.symbols.create("rev")), rev2.gitRev()); mkString(*state.allocAttr(v, state.symbols.create("shortRev")), rev2.gitShortRev()); // Backward compatibility: set 'revCount' to 0 for a dirty tree. diff --git a/src/libexpr/primops/fetchMercurial.cc b/src/libexpr/primops/fetchMercurial.cc index 12f62e5ee..9bace8f89 100644 --- a/src/libexpr/primops/fetchMercurial.cc +++ b/src/libexpr/primops/fetchMercurial.cc @@ -31,7 +31,7 @@ static void prim_fetchMercurial(EvalState & state, const Pos & pos, Value * * ar // be both a revision or a branch/tag name. auto value = state.forceStringNoCtx(*attr.value, *attr.pos); if (std::regex_match(value, revRegex)) - rev = Hash(value, HashType::SHA1); + rev = Hash(value, htSHA1); else ref = value; } @@ -77,7 +77,7 @@ static void prim_fetchMercurial(EvalState & state, const Pos & pos, Value * * ar mkString(*state.allocAttr(v, state.symbols.create("branch")), *input2->getRef()); // Backward compatibility: set 'rev' to // 0000000000000000000000000000000000000000 for a dirty tree. - auto rev2 = input2->getRev().value_or(Hash(HashType::SHA1)); + auto rev2 = input2->getRev().value_or(Hash(htSHA1)); mkString(*state.allocAttr(v, state.symbols.create("rev")), rev2.gitRev()); mkString(*state.allocAttr(v, state.symbols.create("shortRev")), std::string(rev2.gitRev(), 0, 12)); if (tree.info.revCount) diff --git a/src/libexpr/primops/fetchTree.cc b/src/libexpr/primops/fetchTree.cc index f527b3f86..9be93710a 100644 --- a/src/libexpr/primops/fetchTree.cc +++ b/src/libexpr/primops/fetchTree.cc @@ -23,7 +23,7 @@ void emitTreeAttrs( assert(tree.info.narHash); mkString(*state.allocAttr(v, state.symbols.create("narHash")), - tree.info.narHash.to_string(Base::SRI, true)); + tree.info.narHash.to_string(SRI, true)); if (input->getRev()) { mkString(*state.allocAttr(v, state.symbols.create("rev")), input->getRev()->gitRev()); @@ -106,7 +106,7 @@ static void fetch(EvalState & state, const Pos & pos, Value * * args, Value & v, if (n == "url") url = state.forceStringNoCtx(*attr.value, *attr.pos); else if (n == "sha256") - expectedHash = newHashAllowEmpty(state.forceStringNoCtx(*attr.value, *attr.pos), HashType::SHA256); + expectedHash = newHashAllowEmpty(state.forceStringNoCtx(*attr.value, *attr.pos), htSHA256); else if (n == "name") name = state.forceStringNoCtx(*attr.value, *attr.pos); else @@ -144,10 +144,10 @@ static void fetch(EvalState & state, const Pos & pos, Value * * args, Value & v, if (expectedHash) { auto hash = unpack ? state.store->queryPathInfo(storePath)->narHash - : hashFile(HashType::SHA256, path); + : hashFile(htSHA256, path); if (hash != *expectedHash) throw Error((unsigned int) 102, "hash mismatch in file downloaded from '%s':\n wanted: %s\n got: %s", - *url, expectedHash->to_string(Base::Base32, true), hash.to_string(Base::Base32, true)); + *url, expectedHash->to_string(Base32, true), hash.to_string(Base32, true)); } if (state.allowedPaths) diff --git a/src/libfetchers/fetchers.cc b/src/libfetchers/fetchers.cc index 02fafc65b..9174c3de4 100644 --- a/src/libfetchers/fetchers.cc +++ b/src/libfetchers/fetchers.cc @@ -47,7 +47,7 @@ Attrs Input::toAttrs() const { auto attrs = toAttrsInternal(); if (narHash) - attrs.emplace("narHash", narHash->to_string(Base::SRI, true)); + attrs.emplace("narHash", narHash->to_string(SRI, true)); attrs.emplace("type", type()); return attrs; } @@ -67,7 +67,7 @@ std::pair> Input::fetchTree(ref store) if (narHash && narHash != input->narHash) throw Error("NAR hash mismatch in input '%s' (%s), expected '%s', got '%s'", - to_string(), tree.actualPath, narHash->to_string(Base::SRI, true), input->narHash->to_string(Base::SRI, true)); + to_string(), tree.actualPath, narHash->to_string(SRI, true), input->narHash->to_string(SRI, true)); return {std::move(tree), input}; } diff --git a/src/libfetchers/git.cc b/src/libfetchers/git.cc index 75d70c1b4..75ce5ee8b 100644 --- a/src/libfetchers/git.cc +++ b/src/libfetchers/git.cc @@ -95,7 +95,7 @@ struct GitInput : Input auto input = std::make_shared(*this); - assert(!rev || rev->type == HashType::SHA1); + assert(!rev || rev->type == htSHA1); std::string cacheType = "git"; if (shallow) cacheType += "-shallow"; @@ -195,7 +195,7 @@ struct GitInput : Input return files.count(file); }; - auto storePath = store->addToStore("source", actualUrl, FileIngestionMethod::Recursive, HashType::SHA256, filter); + auto storePath = store->addToStore("source", actualUrl, FileIngestionMethod::Recursive, htSHA256, filter); auto tree = Tree { .actualPath = store->printStorePath(storePath), @@ -225,21 +225,21 @@ struct GitInput : Input if (isLocal) { if (!input->rev) - input->rev = Hash(chomp(runProgram("git", true, { "-C", actualUrl, "rev-parse", *input->ref })), HashType::SHA1); + input->rev = Hash(chomp(runProgram("git", true, { "-C", actualUrl, "rev-parse", *input->ref })), htSHA1); repoDir = actualUrl; } else { if (auto res = getCache()->lookup(store, mutableAttrs)) { - auto rev2 = Hash(getStrAttr(res->first, "rev"), HashType::SHA1); + auto rev2 = Hash(getStrAttr(res->first, "rev"), htSHA1); if (!rev || rev == rev2) { input->rev = rev2; return makeResult(res->first, std::move(res->second)); } } - Path cacheDir = getCacheDir() + "/nix/gitv3/" + hashString(HashType::SHA256, actualUrl).to_string(Base::Base32, false); + Path cacheDir = getCacheDir() + "/nix/gitv3/" + hashString(htSHA256, actualUrl).to_string(Base32, false); repoDir = cacheDir; if (!pathExists(cacheDir)) { @@ -277,7 +277,7 @@ struct GitInput : Input } if (doFetch) { - Activity act(*logger, Verbosity::Talkative, ActivityType::Unknown, fmt("fetching Git repository '%s'", actualUrl)); + Activity act(*logger, lvlTalkative, actUnknown, fmt("fetching Git repository '%s'", actualUrl)); // FIXME: git stderr messes up our progress indicator, so // we're using --quiet for now. Should process its stderr. @@ -301,7 +301,7 @@ struct GitInput : Input } if (!input->rev) - input->rev = Hash(chomp(readFile(localRefFile)), HashType::SHA1); + input->rev = Hash(chomp(readFile(localRefFile)), htSHA1); } bool isShallow = chomp(runProgram("git", true, { "-C", repoDir, "rev-parse", "--is-shallow-repository" })) == "true"; @@ -350,7 +350,7 @@ struct GitInput : Input unpackTarfile(*source, tmpDir); } - auto storePath = store->addToStore(name, tmpDir, FileIngestionMethod::Recursive, HashType::SHA256, filter); + auto storePath = store->addToStore(name, tmpDir, FileIngestionMethod::Recursive, htSHA256, filter); auto lastModified = std::stoull(runProgram("git", true, { "-C", repoDir, "log", "-1", "--format=%ct", input->rev->gitRev() })); @@ -426,7 +426,7 @@ struct GitInputScheme : InputScheme input->ref = *ref; } if (auto rev = maybeGetStrAttr(attrs, "rev")) - input->rev = Hash(*rev, HashType::SHA1); + input->rev = Hash(*rev, htSHA1); input->shallow = maybeGetBoolAttr(attrs, "shallow").value_or(false); diff --git a/src/libfetchers/github.cc b/src/libfetchers/github.cc index ec0573ca3..0bee1d6b3 100644 --- a/src/libfetchers/github.cc +++ b/src/libfetchers/github.cc @@ -45,7 +45,7 @@ struct GitHubInput : Input auto path = owner + "/" + repo; assert(!(ref && rev)); if (ref) path += "/" + *ref; - if (rev) path += "/" + rev->to_string(Base::Base16, false); + if (rev) path += "/" + rev->to_string(Base16, false); return ParsedURL { .scheme = "github", .path = path, @@ -76,7 +76,7 @@ struct GitHubInput : Input readFile( store->toRealPath( downloadFile(store, url, "source", false).storePath))); - rev = Hash(std::string { json["sha"] }, HashType::SHA1); + rev = Hash(std::string { json["sha"] }, htSHA1); debug("HEAD revision for '%s' is %s", url, rev->gitRev()); } @@ -106,7 +106,7 @@ struct GitHubInput : Input // might have stricter rate limits. auto url = fmt("https://api.github.com/repos/%s/%s/tarball/%s", - owner, repo, rev->to_string(Base::Base16, false)); + owner, repo, rev->to_string(Base16, false)); std::string accessToken = settings.githubAccessToken.get(); if (accessToken != "") @@ -140,7 +140,7 @@ struct GitHubInputScheme : InputScheme if (path.size() == 2) { } else if (path.size() == 3) { if (std::regex_match(path[2], revRegex)) - input->rev = Hash(path[2], HashType::SHA1); + input->rev = Hash(path[2], htSHA1); else if (std::regex_match(path[2], refRegex)) input->ref = path[2]; else @@ -152,7 +152,7 @@ struct GitHubInputScheme : InputScheme if (name == "rev") { if (input->rev) throw BadURL("GitHub URL '%s' contains multiple commit hashes", url.url); - input->rev = Hash(value, HashType::SHA1); + input->rev = Hash(value, htSHA1); } else if (name == "ref") { if (!std::regex_match(value, refRegex)) @@ -185,7 +185,7 @@ struct GitHubInputScheme : InputScheme input->repo = getStrAttr(attrs, "repo"); input->ref = maybeGetStrAttr(attrs, "ref"); if (auto rev = maybeGetStrAttr(attrs, "rev")) - input->rev = Hash(*rev, HashType::SHA1); + input->rev = Hash(*rev, htSHA1); return input; } }; diff --git a/src/libfetchers/mercurial.cc b/src/libfetchers/mercurial.cc index feffc48d6..2e0d4bf4d 100644 --- a/src/libfetchers/mercurial.cc +++ b/src/libfetchers/mercurial.cc @@ -114,7 +114,7 @@ struct MercurialInput : Input return files.count(file); }; - auto storePath = store->addToStore("source", actualUrl, FileIngestionMethod::Recursive, HashType::SHA256, filter); + auto storePath = store->addToStore("source", actualUrl, FileIngestionMethod::Recursive, htSHA256, filter); return {Tree { .actualPath = store->printStorePath(storePath), @@ -167,14 +167,14 @@ struct MercurialInput : Input }); if (auto res = getCache()->lookup(store, mutableAttrs)) { - auto rev2 = Hash(getStrAttr(res->first, "rev"), HashType::SHA1); + auto rev2 = Hash(getStrAttr(res->first, "rev"), htSHA1); if (!rev || rev == rev2) { input->rev = rev2; return makeResult(res->first, std::move(res->second)); } } - Path cacheDir = fmt("%s/nix/hg/%s", getCacheDir(), hashString(HashType::SHA256, actualUrl).to_string(Base::Base32, false)); + Path cacheDir = fmt("%s/nix/hg/%s", getCacheDir(), hashString(htSHA256, actualUrl).to_string(Base32, false)); /* If this is a commit hash that we already have, we don't have to pull again. */ @@ -184,7 +184,7 @@ struct MercurialInput : Input RunOptions("hg", { "log", "-R", cacheDir, "-r", input->rev->gitRev(), "--template", "1" }) .killStderr(true)).second == "1")) { - Activity act(*logger, Verbosity::Talkative, ActivityType::Unknown, fmt("fetching Mercurial repository '%s'", actualUrl)); + Activity act(*logger, lvlTalkative, actUnknown, fmt("fetching Mercurial repository '%s'", actualUrl)); if (pathExists(cacheDir)) { try { @@ -210,7 +210,7 @@ struct MercurialInput : Input runProgram("hg", true, { "log", "-R", cacheDir, "-r", revOrRef, "--template", "{node} {rev} {branch}" })); assert(tokens.size() == 3); - input->rev = Hash(tokens[0], HashType::SHA1); + input->rev = Hash(tokens[0], htSHA1); auto revCount = std::stoull(tokens[1]); input->ref = tokens[2]; @@ -293,7 +293,7 @@ struct MercurialInputScheme : InputScheme input->ref = *ref; } if (auto rev = maybeGetStrAttr(attrs, "rev")) - input->rev = Hash(*rev, HashType::SHA1); + input->rev = Hash(*rev, htSHA1); return input; } }; diff --git a/src/libfetchers/path.cc b/src/libfetchers/path.cc index 3f50addd8..ba2cc192e 100644 --- a/src/libfetchers/path.cc +++ b/src/libfetchers/path.cc @@ -101,7 +101,7 @@ struct PathInputScheme : InputScheme for (auto & [name, value] : url.query) if (name == "rev") - input->rev = Hash(value, HashType::SHA1); + input->rev = Hash(value, htSHA1); else if (name == "revCount") { uint64_t revCount; if (!string2Int(value, revCount)) @@ -129,7 +129,7 @@ struct PathInputScheme : InputScheme for (auto & [name, value] : attrs) if (name == "rev") - input->rev = Hash(getStrAttr(attrs, "rev"), HashType::SHA1); + input->rev = Hash(getStrAttr(attrs, "rev"), htSHA1); else if (name == "revCount") input->revCount = getIntAttr(attrs, "revCount"); else if (name == "lastModified") diff --git a/src/libfetchers/tarball.cc b/src/libfetchers/tarball.cc index c82b6dd09..ac83d52b9 100644 --- a/src/libfetchers/tarball.cc +++ b/src/libfetchers/tarball.cc @@ -66,9 +66,9 @@ DownloadFileResult downloadFile( } else { StringSink sink; dumpString(*res.data, sink); - auto hash = hashString(HashType::SHA256, *res.data); + auto hash = hashString(htSHA256, *res.data); ValidPathInfo info(store->makeFixedOutputPath(FileIngestionMethod::Flat, hash, name)); - info.narHash = hashString(HashType::SHA256, *sink.s); + info.narHash = hashString(htSHA256, *sink.s); info.narSize = sink.s->size(); info.ca = makeFixedOutputCA(FileIngestionMethod::Flat, hash); auto source = StringSource { *sink.s }; @@ -142,7 +142,7 @@ Tree downloadTarball( throw nix::Error("tarball '%s' contains an unexpected number of top-level files", url); auto topDir = tmpDir + "/" + members.begin()->name; lastModified = lstat(topDir).st_mtime; - unpackedStorePath = store->addToStore(name, topDir, FileIngestionMethod::Recursive, HashType::SHA256, defaultPathFilter, NoRepair); + unpackedStorePath = store->addToStore(name, topDir, FileIngestionMethod::Recursive, htSHA256, defaultPathFilter, NoRepair); } Attrs infoAttrs({ @@ -196,9 +196,9 @@ struct TarballInput : Input // NAR hashes are preferred over file hashes since tar/zip files // don't have a canonical representation. if (narHash) - url2.query.insert_or_assign("narHash", narHash->to_string(Base::SRI, true)); + url2.query.insert_or_assign("narHash", narHash->to_string(SRI, true)); else if (hash) - url2.query.insert_or_assign("hash", hash->to_string(Base::SRI, true)); + url2.query.insert_or_assign("hash", hash->to_string(SRI, true)); return url2; } @@ -207,7 +207,7 @@ struct TarballInput : Input Attrs attrs; attrs.emplace("url", url.to_string()); if (hash) - attrs.emplace("hash", hash->to_string(Base::SRI, true)); + attrs.emplace("hash", hash->to_string(SRI, true)); return attrs; } diff --git a/src/libmain/common-args.cc b/src/libmain/common-args.cc index eb3319c59..051668e53 100644 --- a/src/libmain/common-args.cc +++ b/src/libmain/common-args.cc @@ -11,21 +11,19 @@ MixCommonArgs::MixCommonArgs(const string & programName) .longName = "verbose", .shortName = 'v', .description = "increase verbosity level", - .handler = {[]() { verbosity = (Verbosity) ((uint64_t) verbosity + 1); }}, + .handler = {[]() { verbosity = (Verbosity) (verbosity + 1); }}, }); addFlag({ .longName = "quiet", .description = "decrease verbosity level", - .handler = {[]() { verbosity = verbosity > Verbosity::Error - ? (Verbosity) ((uint64_t) verbosity - 1) - : Verbosity::Error; }}, + .handler = {[]() { verbosity = verbosity > lvlError ? (Verbosity) (verbosity - 1) : lvlError; }}, }); addFlag({ .longName = "debug", .description = "enable debug output", - .handler = {[]() { verbosity = Verbosity::Debug; }}, + .handler = {[]() { verbosity = lvlDebug; }}, }); addFlag({ diff --git a/src/libmain/progress-bar.cc b/src/libmain/progress-bar.cc index c2c8cac6b..95a9187de 100644 --- a/src/libmain/progress-bar.cc +++ b/src/libmain/progress-bar.cc @@ -39,7 +39,7 @@ private: struct ActInfo { std::string s, lastLine, phase; - ActivityType type = ActivityType::Unknown; + ActivityType type = actUnknown; uint64_t done = 0; uint64_t expected = 0; uint64_t running = 0; @@ -153,7 +153,7 @@ public: { auto state(state_.lock()); - if (lvl <= verbosity && !s.empty() && type != ActivityType::BuildWaiting) + if (lvl <= verbosity && !s.empty() && type != actBuildWaiting) log(*state, lvl, s + "..."); state->activities.emplace_back(ActInfo()); @@ -164,7 +164,7 @@ public: state->its.emplace(act, i); state->activitiesByType[type].its.emplace(act, i); - if (type == ActivityType::Build) { + if (type == actBuild) { std::string name(storePathToName(getS(fields, 0))); if (hasSuffix(name, ".drv")) name = name.substr(0, name.size() - 4); @@ -179,7 +179,7 @@ public: i->name = DrvName(name).name; } - if (type == ActivityType::Substitute) { + if (type == actSubstitute) { auto name = storePathToName(getS(fields, 0)); auto sub = getS(fields, 1); i->s = fmt( @@ -189,7 +189,7 @@ public: name, sub); } - if (type == ActivityType::PostBuildHook) { + if (type == actPostBuildHook) { auto name = storePathToName(getS(fields, 0)); if (hasSuffix(name, ".drv")) name = name.substr(0, name.size() - 4); @@ -197,14 +197,14 @@ public: i->name = DrvName(name).name; } - if (type == ActivityType::QueryPathInfo) { + if (type == actQueryPathInfo) { auto name = storePathToName(getS(fields, 0)); i->s = fmt("querying " ANSI_BOLD "%s" ANSI_NORMAL " on %s", name, getS(fields, 1)); } - 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))) + if ((type == actFileTransfer && hasAncestor(*state, actCopyPath, parent)) + || (type == actFileTransfer && hasAncestor(*state, actQueryPathInfo, parent)) + || (type == actCopyPath && hasAncestor(*state, actSubstitute, parent))) i->visible = false; update(*state); @@ -249,13 +249,13 @@ public: { auto state(state_.lock()); - if (type == ResultType::FileLinked) { + if (type == resFileLinked) { state->filesLinked++; state->bytesLinked += getI(fields, 0); update(*state); } - else if (type == ResultType::BuildLogLine || type == ResultType::PostBuildLogLine) { + else if (type == resBuildLogLine || type == resPostBuildLogLine) { auto lastLine = trim(getS(fields, 0)); if (!lastLine.empty()) { auto i = state->its.find(act); @@ -263,10 +263,10 @@ public: ActInfo info = *i->second; if (printBuildLogs) { auto suffix = "> "; - if (type == ResultType::PostBuildLogLine) { + if (type == resPostBuildLogLine) { suffix = " (post)> "; } - log(*state, Verbosity::Info, ANSI_FAINT + info.name.value_or("unnamed") + suffix + ANSI_NORMAL + lastLine); + log(*state, lvlInfo, ANSI_FAINT + info.name.value_or("unnamed") + suffix + ANSI_NORMAL + lastLine); } else { state->activities.erase(i->second); info.lastLine = lastLine; @@ -277,24 +277,24 @@ public: } } - else if (type == ResultType::UntrustedPath) { + else if (type == resUntrustedPath) { state->untrustedPaths++; update(*state); } - else if (type == ResultType::CorruptedPath) { + else if (type == resCorruptedPath) { state->corruptedPaths++; update(*state); } - else if (type == ResultType::SetPhase) { + else if (type == resSetPhase) { auto i = state->its.find(act); assert(i != state->its.end()); i->second->phase = getS(fields, 0); update(*state); } - else if (type == ResultType::Progress) { + else if (type == resProgress) { auto i = state->its.find(act); assert(i != state->its.end()); ActInfo & actInfo = *i->second; @@ -305,7 +305,7 @@ public: update(*state); } - else if (type == ResultType::SetExpected) { + else if (type == resSetExpected) { auto i = state->its.find(act); assert(i != state->its.end()); ActInfo & actInfo = *i->second; @@ -417,10 +417,10 @@ public: res += s; }; - showActivity(ActivityType::Builds, "%s built"); + showActivity(actBuilds, "%s built"); - auto s1 = renderActivity(ActivityType::CopyPaths, "%s copied"); - auto s2 = renderActivity(ActivityType::CopyPath, "%s MiB", "%.1f", MiB); + auto s1 = renderActivity(actCopyPaths, "%s copied"); + auto s2 = renderActivity(actCopyPath, "%s MiB", "%.1f", MiB); if (!s1.empty() || !s2.empty()) { if (!res.empty()) res += ", "; @@ -428,10 +428,10 @@ public: if (!s2.empty()) { res += " ("; res += s2; res += ')'; } } - showActivity(ActivityType::Download, "%s MiB DL", "%.1f", MiB); + showActivity(actFileTransfer, "%s MiB DL", "%.1f", MiB); { - auto s = renderActivity(ActivityType::OptimiseStore, "%s paths optimised"); + auto s = renderActivity(actOptimiseStore, "%s paths optimised"); if (s != "") { s += fmt(", %.1f MiB / %d inodes freed", state.bytesLinked / MiB, state.filesLinked); if (!res.empty()) res += ", "; @@ -440,7 +440,7 @@ public: } // FIXME: don't show "done" paths in green. - showActivity(ActivityType::VerifyPaths, "%s paths verified"); + showActivity(actVerifyPaths, "%s paths verified"); if (state.corruptedPaths) { if (!res.empty()) res += ", "; diff --git a/src/libmain/shared.cc b/src/libmain/shared.cc index 3e6b44ee7..1cb422967 100644 --- a/src/libmain/shared.cc +++ b/src/libmain/shared.cc @@ -269,7 +269,7 @@ void parseCmdLine(const string & programName, const Strings & args, void printVersion(const string & programName) { std::cout << format("%1% (Nix) %2%") % programName % nixVersion << std::endl; - if (verbosity > Verbosity::Info) { + if (verbosity > lvlInfo) { Strings cfg; #if HAVE_BOEHMGC cfg.push_back("gc"); diff --git a/src/libmain/shared.hh b/src/libmain/shared.hh index 3e3a73278..f558247c0 100644 --- a/src/libmain/shared.hh +++ b/src/libmain/shared.hh @@ -43,11 +43,11 @@ struct StorePathWithOutputs; void printMissing( ref store, const std::vector & paths, - Verbosity lvl = Verbosity::Info); + Verbosity lvl = lvlInfo); void printMissing(ref store, const StorePathSet & willBuild, const StorePathSet & willSubstitute, const StorePathSet & unknown, - unsigned long long downloadSize, unsigned long long narSize, Verbosity lvl = Verbosity::Info); + unsigned long long downloadSize, unsigned long long narSize, Verbosity lvl = lvlInfo); string getArg(const string & opt, Strings::iterator & i, const Strings::iterator & end); diff --git a/src/libstore/binary-cache-store.cc b/src/libstore/binary-cache-store.cc index fbc466e2e..9f52ddafa 100644 --- a/src/libstore/binary-cache-store.cc +++ b/src/libstore/binary-cache-store.cc @@ -137,7 +137,7 @@ void BinaryCacheStore::addToStore(const ValidPathInfo & info, Source & narSource auto narInfo = make_ref(info); narInfo->narSize = nar->size(); - narInfo->narHash = hashString(HashType::SHA256, *nar); + narInfo->narHash = hashString(htSHA256, *nar); if (info.narHash && info.narHash != narInfo->narHash) throw Error("refusing to copy corrupted path '%1%' to binary cache", printStorePath(info.path)); @@ -172,16 +172,16 @@ void BinaryCacheStore::addToStore(const ValidPathInfo & info, Source & narSource auto now1 = std::chrono::steady_clock::now(); auto narCompressed = compress(compression, *nar, parallelCompression); auto now2 = std::chrono::steady_clock::now(); - narInfo->fileHash = hashString(HashType::SHA256, *narCompressed); + narInfo->fileHash = hashString(htSHA256, *narCompressed); narInfo->fileSize = narCompressed->size(); auto duration = std::chrono::duration_cast(now2 - now1).count(); - printMsg(Verbosity::Talkative, "copying path '%1%' (%2% bytes, compressed %3$.1f%% in %4% ms) to binary cache", + printMsg(lvlTalkative, "copying path '%1%' (%2% bytes, compressed %3$.1f%% in %4% ms) to binary cache", printStorePath(narInfo->path), narInfo->narSize, ((1.0 - (double) narCompressed->size() / nar->size()) * 100.0), duration); - narInfo->url = "nar/" + narInfo->fileHash.to_string(Base::Base32, false) + ".nar" + narInfo->url = "nar/" + narInfo->fileHash.to_string(Base32, false) + ".nar" + (compression == "xz" ? ".xz" : compression == "bzip2" ? ".bz2" : compression == "br" ? ".br" : @@ -209,7 +209,7 @@ void BinaryCacheStore::addToStore(const ValidPathInfo & info, Source & narSource // to a GC'ed file, so overwriting might be useful... if (fileExists(key)) return; - printMsg(Verbosity::Talkative, "creating debuginfo link from '%s' to '%s'", key, target); + printMsg(lvlTalkative, "creating debuginfo link from '%s' to '%s'", key, target); upsertFile(key, json.dump(), "application/json"); }; @@ -302,7 +302,7 @@ void BinaryCacheStore::queryPathInfoUncached(const StorePath & storePath, { auto uri = getUri(); auto storePathS = printStorePath(storePath); - auto act = std::make_shared(*logger, Verbosity::Talkative, ActivityType::QueryPathInfo, + auto act = std::make_shared(*logger, lvlTalkative, actQueryPathInfo, fmt("querying info about '%s' on '%s'", storePathS, uri), Logger::Fields{storePathS, uri}); PushActivity pact(act->id); diff --git a/src/libstore/build.cc b/src/libstore/build.cc index dda84d536..47a153bbc 100644 --- a/src/libstore/build.cc +++ b/src/libstore/build.cc @@ -106,13 +106,7 @@ typedef std::map WeakGoalMap; struct Goal : public std::enable_shared_from_this { - enum struct ExitCode { - Busy, - Success, - Failed, - NoSubstituters, - IncompleteClosure, - }; + typedef enum {ecBusy, ecSuccess, ecFailed, ecNoSubstituters, ecIncompleteClosure} ExitCode; /* Backlink to the worker. */ Worker & worker; @@ -147,7 +141,7 @@ struct Goal : public std::enable_shared_from_this Goal(Worker & worker) : worker(worker) { nrFailed = nrNoSubstituters = nrIncompleteClosure = 0; - exitCode = ExitCode::Busy; + exitCode = ecBusy; } virtual ~Goal() @@ -359,8 +353,8 @@ public: { actDerivations.progress(doneBuilds, expectedBuilds + doneBuilds, runningBuilds, failedBuilds); actSubstitutions.progress(doneSubstitutions, expectedSubstitutions + doneSubstitutions, runningSubstitutions, failedSubstitutions); - act.setExpected(ActivityType::Download, expectedDownloadSize + doneDownloadSize); - act.setExpected(ActivityType::CopyPath, expectedNarSize + doneNarSize); + act.setExpected(actFileTransfer, expectedDownloadSize + doneDownloadSize); + act.setExpected(actCopyPath, expectedNarSize + doneNarSize); } }; @@ -392,13 +386,13 @@ void Goal::waiteeDone(GoalPtr waitee, ExitCode result) trace(fmt("waitee '%s' done; %d left", waitee->name, waitees.size())); - if (result == ExitCode::Failed || result == ExitCode::NoSubstituters || result == ExitCode::IncompleteClosure) ++nrFailed; + if (result == ecFailed || result == ecNoSubstituters || result == ecIncompleteClosure) ++nrFailed; - if (result == ExitCode::NoSubstituters) ++nrNoSubstituters; + if (result == ecNoSubstituters) ++nrNoSubstituters; - if (result == ExitCode::IncompleteClosure) ++nrIncompleteClosure; + if (result == ecIncompleteClosure) ++nrIncompleteClosure; - if (waitees.empty() || (result == ExitCode::Failed && !settings.keepGoing)) { + if (waitees.empty() || (result == ecFailed && !settings.keepGoing)) { /* If we failed and keepGoing is not set, we remove all remaining waitees. */ @@ -418,8 +412,8 @@ void Goal::waiteeDone(GoalPtr waitee, ExitCode result) void Goal::amDone(ExitCode result, std::optional ex) { trace("done"); - assert(exitCode == ExitCode::Busy); - assert(result == ExitCode::Success || result == ExitCode::Failed || result == ExitCode::NoSubstituters || result == ExitCode::IncompleteClosure); + assert(exitCode == ecBusy); + assert(result == ecSuccess || result == ecFailed || result == ecNoSubstituters || result == ecIncompleteClosure); exitCode = result; if (ex) { @@ -684,7 +678,7 @@ HookInstance::HookInstance() Strings args = { std::string(baseNameOf(settings.buildHook.get())), - std::to_string((uint64_t)verbosity), + std::to_string(verbosity), }; execv(settings.buildHook.get().c_str(), stringsToCharPtrs(args).data()); @@ -1422,7 +1416,7 @@ void DerivationGoal::started() { "building '%s'", worker.store.printStorePath(drvPath), curRound, nrRounds); fmt("building '%s'", worker.store.printStorePath(drvPath)); if (hook) msg += fmt(" on '%s'", machineName); - act = std::make_unique(*logger, Verbosity::Info, ActivityType::Build, msg, + act = std::make_unique(*logger, lvlInfo, actBuild, msg, Logger::Fields{worker.store.printStorePath(drvPath), hook ? machineName : "", curRound, nrRounds}); mcRunningBuilds = std::make_unique>(worker.runningBuilds); worker.updateProgress(); @@ -1443,7 +1437,7 @@ void DerivationGoal::tryToBuild() if (!outputLocks.lockPaths(lockFiles, "", false)) { if (!actLock) - actLock = std::make_unique(*logger, Verbosity::Warn, ActivityType::BuildWaiting, + actLock = std::make_unique(*logger, lvlWarn, actBuildWaiting, fmt("waiting for lock on %s", yellowtxt(showPaths(lockFiles)))); worker.waitForAWhile(shared_from_this()); return; @@ -1483,20 +1477,6 @@ void DerivationGoal::tryToBuild() supported for local builds. */ bool buildLocally = buildMode != bmNormal || parsedDrv->willBuildLocally(); - auto started = [&]() { - auto msg = fmt( - buildMode == bmRepair ? "repairing outputs of '%s'" : - buildMode == bmCheck ? "checking outputs of '%s'" : - nrRounds > 1 ? "building '%s' (round %d/%d)" : - "building '%s'", worker.store.printStorePath(drvPath), curRound, nrRounds); - fmt("building '%s'", worker.store.printStorePath(drvPath)); - if (hook) msg += fmt(" on '%s'", machineName); - act = std::make_unique(*logger, Verbosity::Info, ActivityType::Build, msg, - Logger::Fields{worker.store.printStorePath(drvPath), hook ? machineName : "", curRound, nrRounds}); - mcRunningBuilds = std::make_unique>(worker.runningBuilds); - worker.updateProgress(); - }; - /* Is the build hook willing to accept this job? */ if (!buildLocally) { switch (tryBuildHook()) { @@ -1512,7 +1492,7 @@ void DerivationGoal::tryToBuild() /* Not now; wait until at least one child finishes or the wake-up timeout expires. */ if (!actLock) - actLock = std::make_unique(*logger, Verbosity::Warn, ActivityType::BuildWaiting, + actLock = std::make_unique(*logger, lvlWarn, actBuildWaiting, fmt("waiting for a machine to build '%s'", yellowtxt(worker.store.printStorePath(drvPath)))); worker.waitForAWhile(shared_from_this()); outputLocks.unlock(); @@ -1553,7 +1533,7 @@ void DerivationGoal::tryLocalBuild() { buildUser->kill(); } else { if (!actLock) - actLock = std::make_unique(*logger, Verbosity::Warn, ActivityType::BuildWaiting, + actLock = std::make_unique(*logger, lvlWarn, actBuildWaiting, fmt("waiting for UID to build '%s'", yellowtxt(worker.store.printStorePath(drvPath)))); worker.waitForAWhile(shared_from_this()); return; @@ -1708,7 +1688,7 @@ void DerivationGoal::buildDone() registerOutputs(); if (settings.postBuildHook != "") { - Activity act(*logger, Verbosity::Info, ActivityType::PostBuildHook, + Activity act(*logger, lvlInfo, actPostBuildHook, fmt("running post-build-hook '%s'", settings.postBuildHook), Logger::Fields{worker.store.printStorePath(drvPath)}); PushActivity pact(act.id); @@ -1740,7 +1720,7 @@ void DerivationGoal::buildDone() } void flushLine() { - act.result(ResultType::PostBuildLogLine, currentLine); + act.result(resPostBuildLogLine, currentLine); currentLine.clear(); } @@ -2144,7 +2124,7 @@ void DerivationGoal::startBuilder() /* Clean up the chroot directory automatically. */ autoDelChroot = std::make_shared(chrootRootDir); - printMsg(Verbosity::Chatty, format("setting up chroot environment in '%1%'") % chrootRootDir); + printMsg(lvlChatty, format("setting up chroot environment in '%1%'") % chrootRootDir); if (mkdir(chrootRootDir.c_str(), 0750) == -1) throw SysError("cannot create '%1%'", chrootRootDir); @@ -2253,7 +2233,7 @@ void DerivationGoal::startBuilder() } if (useChroot && settings.preBuildHook != "" && dynamic_cast(drv.get())) { - printMsg(Verbosity::Chatty, format("executing pre-build hook '%1%'") + printMsg(lvlChatty, format("executing pre-build hook '%1%'") % settings.preBuildHook); auto args = useChroot ? Strings({worker.store.printStorePath(drvPath), chrootRootDir}) : Strings({ worker.store.printStorePath(drvPath) }); @@ -2294,7 +2274,7 @@ void DerivationGoal::startBuilder() startDaemon(); /* Run the builder. */ - printMsg(Verbosity::Chatty, "executing builder '%1%'", drv->builder); + printMsg(lvlChatty, "executing builder '%1%'", drv->builder); /* Create the log file. */ Path logFile = openLogFile(); @@ -2530,8 +2510,8 @@ void DerivationGoal::initTmpDir() { if (passAsFile.find(i.first) == passAsFile.end()) { env[i.first] = i.second; } else { - auto hash = hashString(HashType::SHA256, i.first); - string fn = ".attr-" + hash.to_string(Base::Base32, false); + auto hash = hashString(htSHA256, i.first); + string fn = ".attr-" + hash.to_string(Base32, false); Path p = tmpDir + "/" + fn; writeFile(p, rewriteStrings(i.second, inputRewrites)); chownToBuilder(p); @@ -2777,7 +2757,7 @@ struct RestrictedStore : public LocalFSStore { throw Error("queryPathFromHashPart"); } StorePath addToStore(const string & name, const Path & srcPath, - FileIngestionMethod method = FileIngestionMethod::Recursive, HashType hashAlgo = HashType::SHA256, + FileIngestionMethod method = FileIngestionMethod::Recursive, HashType hashAlgo = htSHA256, PathFilter & filter = defaultPathFilter, RepairFlag repair = NoRepair) override { throw Error("addToStore"); } @@ -2790,7 +2770,7 @@ struct RestrictedStore : public LocalFSStore } StorePath addToStoreFromDump(const string & dump, const string & name, - FileIngestionMethod method = FileIngestionMethod::Recursive, HashType hashAlgo = HashType::SHA256, RepairFlag repair = NoRepair) override + FileIngestionMethod method = FileIngestionMethod::Recursive, HashType hashAlgo = htSHA256, RepairFlag repair = NoRepair) override { auto path = next->addToStoreFromDump(dump, name, method, hashAlgo, repair); goal.addDependency(path); @@ -3765,7 +3745,7 @@ void DerivationGoal::registerOutputs() worker.hashMismatch = true; delayedException = std::make_exception_ptr( BuildError("hash mismatch in fixed-output derivation '%s':\n wanted: %s\n got: %s", - worker.store.printStorePath(dest), h.to_string(Base::SRI, true), h2.to_string(Base::SRI, true))); + worker.store.printStorePath(dest), h.to_string(SRI, true), h2.to_string(SRI, true))); Path actualDest = worker.store.Store::toRealPath(dest); @@ -4209,7 +4189,7 @@ void DerivationGoal::flushLine() logTail.push_back(currentLogLine); if (logTail.size() > settings.logLines) logTail.pop_front(); - act->result(ResultType::BuildLogLine, currentLogLine); + act->result(resBuildLogLine, currentLogLine); } currentLogLine = ""; @@ -4236,7 +4216,7 @@ void DerivationGoal::addHashRewrite(const StorePath & path) auto h1 = std::string(((std::string_view) path.to_string()).substr(0, 32)); auto p = worker.store.makeStorePath( "rewrite:" + std::string(drvPath.to_string()) + ":" + std::string(path.to_string()), - Hash(HashType::SHA256), path.name()); + Hash(htSHA256), path.name()); auto h2 = std::string(((std::string_view) p.to_string()).substr(0, 32)); deletePath(worker.store.printStorePath(p)); inputRewrites[h1] = h2; @@ -4250,7 +4230,7 @@ void DerivationGoal::done(BuildResult::Status status, std::optional ex) result.status = status; if (ex) result.errorMsg = ex->what(); - amDone(result.success() ? ExitCode::Success : ExitCode::Failed, ex); + amDone(result.success() ? ecSuccess : ecFailed, ex); if (result.status == BuildResult::TimedOut) worker.timedOut = true; if (result.status == BuildResult::PermanentFailure) @@ -4386,7 +4366,7 @@ void SubstitutionGoal::init() /* If the path already exists we're done. */ if (!repair && worker.store.isValidPath(storePath)) { - amDone(ExitCode::Success); + amDone(ecSuccess); return; } @@ -4411,7 +4391,7 @@ void SubstitutionGoal::tryNext() /* Hack: don't indicate failure if there were no substituters. In that case the calling derivation should just do a build. */ - amDone(substituterFailed ? ExitCode::Failed : ExitCode::NoSubstituters); + amDone(substituterFailed ? ecFailed : ecNoSubstituters); if (substituterFailed) { worker.failedSubstitutions++; @@ -4497,7 +4477,7 @@ void SubstitutionGoal::referencesValid() if (nrFailed > 0) { debug("some references of path '%s' could not be realised", worker.store.printStorePath(storePath)); - amDone(nrNoSubstituters > 0 || nrIncompleteClosure > 0 ? ExitCode::IncompleteClosure : ExitCode::Failed); + amDone(nrNoSubstituters > 0 || nrIncompleteClosure > 0 ? ecIncompleteClosure : ecFailed); return; } @@ -4535,7 +4515,7 @@ void SubstitutionGoal::tryToRun() /* Wake up the worker loop when we're done. */ Finally updateStats([this]() { outPipe.writeSide = -1; }); - Activity act(*logger, ActivityType::Substitute, Logger::Fields{worker.store.printStorePath(storePath), sub->getUri()}); + Activity act(*logger, actSubstitute, Logger::Fields{worker.store.printStorePath(storePath), sub->getUri()}); PushActivity pact(act.id); copyStorePath(ref(sub), ref(worker.store.shared_from_this()), @@ -4584,7 +4564,7 @@ void SubstitutionGoal::finished() worker.markContentsGood(storePath); - printMsg(Verbosity::Chatty, "substitution of path '%s' succeeded", worker.store.printStorePath(storePath)); + printMsg(lvlChatty, "substitution of path '%s' succeeded", worker.store.printStorePath(storePath)); maintainRunningSubstitutions.reset(); @@ -4602,7 +4582,7 @@ void SubstitutionGoal::finished() worker.updateProgress(); - amDone(ExitCode::Success); + amDone(ecSuccess); } @@ -4620,9 +4600,9 @@ void SubstitutionGoal::handleEOF(int fd) Worker::Worker(LocalStore & store) - : act(*logger, ActivityType::Realise) - , actDerivations(*logger, ActivityType::Builds) - , actSubstitutions(*logger, ActivityType::CopyPaths) + : act(*logger, actRealise) + , actDerivations(*logger, actBuilds) + , actSubstitutions(*logger, actCopyPaths) , store(store) { /* Debugging: prevent recursive workers. */ @@ -4706,7 +4686,7 @@ void Worker::removeGoal(GoalPtr goal) topGoals.erase(goal); /* If a top-level goal failed, then kill all other goals (unless keepGoing was set). */ - if (goal->exitCode == Goal::ExitCode::Failed && !settings.keepGoing) + if (goal->exitCode == Goal::ecFailed && !settings.keepGoing) topGoals.clear(); } @@ -4849,7 +4829,7 @@ void Worker::run(const Goals & _topGoals) void Worker::waitForInput() { - printMsg(Verbosity::Vomit, "waiting for children"); + printMsg(lvlVomit, "waiting for children"); /* Process output from the file descriptors attached to the children, namely log output and output path creation commands. @@ -4939,7 +4919,7 @@ void Worker::waitForInput() if (errno != EINTR) throw SysError("%s: read failed", goal->getName()); } else { - printMsg(Verbosity::Vomit, "%1%: read %2% bytes", + printMsg(lvlVomit, "%1%: read %2% bytes", goal->getName(), rd); string data((char *) buffer.data(), rd); j->lastOutput = after; @@ -4948,7 +4928,7 @@ void Worker::waitForInput() } } - if (goal->exitCode == Goal::ExitCode::Busy && + if (goal->exitCode == Goal::ecBusy && 0 != settings.maxSilentTime && j->respectTimeouts && after - j->lastOutput >= std::chrono::seconds(settings.maxSilentTime)) @@ -4958,7 +4938,7 @@ void Worker::waitForInput() goal->getName(), settings.maxSilentTime)); } - else if (goal->exitCode == Goal::ExitCode::Busy && + else if (goal->exitCode == Goal::ecBusy && 0 != settings.buildTimeout && j->respectTimeouts && after - j->timeStarted >= std::chrono::seconds(settings.buildTimeout)) @@ -5019,7 +4999,7 @@ bool Worker::pathContentsGood(const StorePath & path) res = false; else { HashResult current = hashPath(*info->narHash.type, store.printStorePath(path)); - Hash nullHash(HashType::SHA256); + Hash nullHash(htSHA256); res = info->narHash == nullHash || info->narHash == current.first; } pathContentsGoodCache.insert_or_assign(path, res); @@ -5079,7 +5059,7 @@ void LocalStore::buildPaths(const std::vector & drvPaths, else ex = i->ex; } - if (i->exitCode != Goal::ExitCode::Success) { + if (i->exitCode != Goal::ecSuccess) { DerivationGoal * i2 = dynamic_cast(i.get()); if (i2) failed.insert(i2->getDrvPath()); else failed.insert(dynamic_cast(i.get())->getStorePath()); @@ -5128,7 +5108,7 @@ void LocalStore::ensurePath(const StorePath & path) worker.run(goals); - if (goal->exitCode != Goal::ExitCode::Success) { + if (goal->exitCode != Goal::ecSuccess) { if (goal->ex) { goal->ex->status = worker.exitStatus(); throw *goal->ex; @@ -5146,7 +5126,7 @@ void LocalStore::repairPath(const StorePath & path) worker.run(goals); - if (goal->exitCode != Goal::ExitCode::Success) { + if (goal->exitCode != Goal::ecSuccess) { /* Since substituting the path didn't work, if we have a valid deriver, then rebuild the deriver. */ auto info = queryPathInfo(path); diff --git a/src/libstore/builtins/fetchurl.cc b/src/libstore/builtins/fetchurl.cc index 3a8d30e80..1cfe4a46a 100644 --- a/src/libstore/builtins/fetchurl.cc +++ b/src/libstore/builtins/fetchurl.cc @@ -65,7 +65,7 @@ void builtinFetchurl(const BasicDerivation & drv, const std::string & netrcData) if (!hasSuffix(hashedMirror, "/")) hashedMirror += '/'; auto ht = parseHashTypeOpt(getAttr("outputHashAlgo")); auto h = Hash(getAttr("outputHash"), ht); - fetch(hashedMirror + printHashType(*h.type) + "/" + h.to_string(Base::Base16, false)); + fetch(hashedMirror + printHashType(*h.type) + "/" + h.to_string(Base16, false)); return; } catch (Error & e) { debug(e.what()); diff --git a/src/libstore/daemon.cc b/src/libstore/daemon.cc index 356479f5a..e370e278c 100644 --- a/src/libstore/daemon.cc +++ b/src/libstore/daemon.cc @@ -126,13 +126,7 @@ struct TunnelLogger : public Logger } StringSink buf; - buf << STDERR_START_ACTIVITY - << act - << (uint64_t) lvl - << (uint64_t) type - << s - << fields - << parent; + buf << STDERR_START_ACTIVITY << act << lvl << type << s << fields << parent; enqueueMsg(*buf.s); } @@ -148,10 +142,7 @@ struct TunnelLogger : public Logger { if (GET_PROTOCOL_MINOR(clientVersion) < 20) return; StringSink buf; - buf << STDERR_RESULT - << act - << (uint64_t) type - << fields; + buf << STDERR_RESULT << act << type << fields; enqueueMsg(*buf.s); } }; @@ -323,7 +314,7 @@ static void performOp(TunnelLogger * logger, ref store, logger->startWork(); auto hash = store->queryPathInfo(path)->narHash; logger->stopWork(); - to << hash.to_string(Base::Base16, false); + to << hash.to_string(Base16, false); break; } @@ -572,7 +563,7 @@ static void performOp(TunnelLogger * logger, ref store, clientSettings.maxBuildJobs = readInt(from); clientSettings.maxSilentTime = readInt(from); readInt(from); // obsolete useBuildHook - clientSettings.verboseBuild = Verbosity::Error == (Verbosity) readInt(from); + clientSettings.verboseBuild = lvlError == (Verbosity) readInt(from); readInt(from); // obsolete logType readInt(from); // obsolete printBuildTrace clientSettings.buildCores = readInt(from); @@ -655,7 +646,7 @@ static void performOp(TunnelLogger * logger, ref store, if (GET_PROTOCOL_MINOR(clientVersion) >= 17) to << 1; to << (info->deriver ? store->printStorePath(*info->deriver) : "") - << info->narHash.to_string(Base::Base16, false); + << info->narHash.to_string(Base16, false); writeStorePaths(*store, to, info->references); to << info->registrationTime << info->narSize; if (GET_PROTOCOL_MINOR(clientVersion) >= 16) { @@ -715,7 +706,7 @@ static void performOp(TunnelLogger * logger, ref store, auto deriver = readString(from); if (deriver != "") info.deriver = store->parseStorePath(deriver); - info.narHash = Hash(readString(from), HashType::SHA256); + info.narHash = Hash(readString(from), htSHA256); info.references = readStorePaths(*store, from); from >> info.registrationTime >> info.narSize >> info.ultimate; info.sigs = readStrings(from); @@ -798,7 +789,7 @@ void processConnection( Finally finally([&]() { _isInterrupted = false; - prevLogger->log(Verbosity::Debug, fmt("%d operations", opCount)); + prevLogger->log(lvlDebug, fmt("%d operations", opCount)); }); if (GET_PROTOCOL_MINOR(clientVersion) >= 14 && readInt(from)) { diff --git a/src/libstore/derivations.cc b/src/libstore/derivations.cc index 5dc8605df..5882a7411 100644 --- a/src/libstore/derivations.cc +++ b/src/libstore/derivations.cc @@ -350,7 +350,7 @@ Hash hashDerivationModulo(Store & store, const Derivation & drv, bool maskOutput /* Return a fixed hash for fixed-output derivations. */ if (drv.isFixedOutput()) { DerivationOutputs::const_iterator i = drv.outputs.begin(); - return hashString(HashType::SHA256, "fixed:out:" + return hashString(htSHA256, "fixed:out:" + i->second.hashAlgo + ":" + i->second.hash + ":" + store.printStorePath(i->second.path)); @@ -366,10 +366,10 @@ Hash hashDerivationModulo(Store & store, const Derivation & drv, bool maskOutput h = drvHashes.insert_or_assign(i.first, hashDerivationModulo(store, store.readDerivation(i.first), false)).first; } - inputs2.insert_or_assign(h->second.to_string(Base::Base16, false), i.second); + inputs2.insert_or_assign(h->second.to_string(Base16, false), i.second); } - return hashString(HashType::SHA256, drv.unparse(store, maskOutputs, &inputs2)); + return hashString(htSHA256, drv.unparse(store, maskOutputs, &inputs2)); } @@ -452,7 +452,7 @@ void writeDerivation(Sink & out, const Store & store, const BasicDerivation & dr std::string hashPlaceholder(const std::string & outputName) { // FIXME: memoize? - return "/" + hashString(HashType::SHA256, "nix-output:" + outputName).to_string(Base::Base32, false); + return "/" + hashString(htSHA256, "nix-output:" + outputName).to_string(Base32, false); } diff --git a/src/libstore/export-import.cc b/src/libstore/export-import.cc index f948d0f9a..57b7e9590 100644 --- a/src/libstore/export-import.cc +++ b/src/libstore/export-import.cc @@ -11,7 +11,7 @@ struct HashAndWriteSink : Sink { Sink & writeSink; HashSink hashSink; - HashAndWriteSink(Sink & writeSink) : writeSink(writeSink), hashSink(HashType::SHA256) + HashAndWriteSink(Sink & writeSink) : writeSink(writeSink), hashSink(htSHA256) { } virtual void operator () (const unsigned char * data, size_t len) @@ -34,7 +34,7 @@ void Store::exportPaths(const StorePathSet & paths, Sink & sink) //logger->incExpected(doneLabel, sorted.size()); for (auto & path : sorted) { - //Activity act(*logger, Verbosity::Info, format("exporting path '%s'") % path); + //Activity act(*logger, lvlInfo, format("exporting path '%s'") % path); sink << 1; exportPath(path, sink); //logger->incProgress(doneLabel); @@ -57,7 +57,7 @@ void Store::exportPath(const StorePath & path, Sink & sink) Hash hash = hashAndWriteSink.currentHash(); if (hash != info->narHash && info->narHash != Hash(*info->narHash.type)) throw Error("hash of path '%s' has changed from '%s' to '%s'!", - printStorePath(path), info->narHash.to_string(Base::Base32, true), hash.to_string(Base::Base32, true)); + printStorePath(path), info->narHash.to_string(Base32, true), hash.to_string(Base32, true)); hashAndWriteSink << exportMagic @@ -86,7 +86,7 @@ StorePaths Store::importPaths(Source & source, std::shared_ptr acces ValidPathInfo info(parseStorePath(readString(source))); - //Activity act(*logger, Verbosity::Info, format("importing path '%s'") % info.path); + //Activity act(*logger, lvlInfo, format("importing path '%s'") % info.path); info.references = readStorePaths(*this, source); @@ -94,7 +94,7 @@ StorePaths Store::importPaths(Source & source, std::shared_ptr acces if (deriver != "") info.deriver = parseStorePath(deriver); - info.narHash = hashString(HashType::SHA256, *tee.source.data); + info.narHash = hashString(htSHA256, *tee.source.data); info.narSize = tee.source.data->size(); // Ignore optional legacy signature. diff --git a/src/libstore/filetransfer.cc b/src/libstore/filetransfer.cc index f27d0c647..531b85af8 100644 --- a/src/libstore/filetransfer.cc +++ b/src/libstore/filetransfer.cc @@ -89,7 +89,7 @@ struct curlFileTransfer : public FileTransfer Callback && callback) : fileTransfer(fileTransfer) , request(request) - , act(*logger, Verbosity::Talkative, ActivityType::Download, + , act(*logger, lvlTalkative, actFileTransfer, fmt(request.data ? "uploading '%s'" : "downloading '%s'", request.uri), {request.uri}, request.parentAct) , callback(std::move(callback)) @@ -174,7 +174,7 @@ struct curlFileTransfer : public FileTransfer { size_t realSize = size * nmemb; std::string line((char *) contents, realSize); - printMsg(Verbosity::Vomit, format("got header for '%s': %s") % request.uri % trim(line)); + printMsg(lvlVomit, format("got header for '%s': %s") % request.uri % trim(line)); if (line.compare(0, 5, "HTTP/") == 0) { // new response starts result.etag = ""; auto ss = tokenizeString>(line, " "); @@ -257,7 +257,7 @@ struct curlFileTransfer : public FileTransfer curl_easy_reset(req); - if (verbosity >= Verbosity::Vomit) { + if (verbosity >= lvlVomit) { curl_easy_setopt(req, CURLOPT_VERBOSE, 1); curl_easy_setopt(req, CURLOPT_DEBUGFUNCTION, TransferItem::debugCallback); } diff --git a/src/libstore/gc.cc b/src/libstore/gc.cc index 31565c78e..57fb20845 100644 --- a/src/libstore/gc.cc +++ b/src/libstore/gc.cc @@ -78,7 +78,7 @@ void LocalStore::syncWithGC() void LocalStore::addIndirectRoot(const Path & path) { - string hash = hashString(HashType::SHA1, path).to_string(Base::Base32, false); + string hash = hashString(htSHA1, path).to_string(Base32, false); Path realRoot = canonPath((format("%1%/%2%/auto/%3%") % stateDir % gcRootsDir % hash).str()); makeSymlink(realRoot, path); @@ -639,7 +639,7 @@ void LocalStore::tryToDelete(GCState & state, const Path & path) auto realPath = realStoreDir + "/" + std::string(baseNameOf(path)); if (realPath == linksDir || realPath == trashDir) return; - //Activity act(*logger, Verbosity::Debug, format("considering whether to delete '%1%'") % path); + //Activity act(*logger, lvlDebug, format("considering whether to delete '%1%'") % path); auto storePath = maybeParseStorePath(path); @@ -704,7 +704,7 @@ void LocalStore::removeUnusedLinks(const GCState & state) continue; } - printMsg(Verbosity::Talkative, format("deleting unused link '%1%'") % path); + printMsg(lvlTalkative, format("deleting unused link '%1%'") % path); if (unlink(path.c_str()) == -1) throw SysError("deleting '%1%'", path); diff --git a/src/libstore/legacy-ssh-store.cc b/src/libstore/legacy-ssh-store.cc index a7bcc0031..45c70fad6 100644 --- a/src/libstore/legacy-ssh-store.cc +++ b/src/libstore/legacy-ssh-store.cc @@ -139,7 +139,7 @@ struct LegacySSHStore : public Store << cmdAddToStoreNar << printStorePath(info.path) << (info.deriver ? printStorePath(*info.deriver) : "") - << info.narHash.to_string(Base::Base16, false); + << info.narHash.to_string(Base16, false); writeStorePaths(*this, conn->to, info.references); conn->to << info.registrationTime diff --git a/src/libstore/local-store.cc b/src/libstore/local-store.cc index 60ad138a3..df4edbbca 100644 --- a/src/libstore/local-store.cc +++ b/src/libstore/local-store.cc @@ -584,7 +584,7 @@ uint64_t LocalStore::addValidPath(State & state, state.stmtRegisterValidPath.use() (printStorePath(info.path)) - (info.narHash.to_string(Base::Base16, true)) + (info.narHash.to_string(Base16, true)) (info.registrationTime == 0 ? time(0) : info.registrationTime) (info.deriver ? printStorePath(*info.deriver) : "", (bool) info.deriver) (info.narSize, info.narSize != 0) @@ -684,7 +684,7 @@ void LocalStore::updatePathInfo(State & state, const ValidPathInfo & info) { state.stmtUpdatePathInfo.use() (info.narSize, info.narSize != 0) - (info.narHash.to_string(Base::Base16, true)) + (info.narHash.to_string(Base16, true)) (info.ultimate ? 1 : 0, info.ultimate) (concatStringsSep(" ", info.sigs), !info.sigs.empty()) (info.ca, !info.ca.empty()) @@ -895,7 +895,7 @@ void LocalStore::registerValidPaths(const ValidPathInfos & infos) StorePathSet paths; for (auto & i : infos) { - assert(i.narHash.type == HashType::SHA256); + assert(i.narHash.type == htSHA256); if (isValidPath_(*state, i.path)) updatePathInfo(*state, i); else @@ -992,9 +992,9 @@ void LocalStore::addToStore(const ValidPathInfo & info, Source & source, of the NAR. */ std::unique_ptr hashSink; if (info.ca == "" || !info.references.count(info.path)) - hashSink = std::make_unique(HashType::SHA256); + hashSink = std::make_unique(htSHA256); else - hashSink = std::make_unique(HashType::SHA256, std::string(info.path.hashPart())); + hashSink = std::make_unique(htSHA256, std::string(info.path.hashPart())); LambdaSource wrapperSource([&](unsigned char * data, size_t len) -> size_t { size_t n = source.read(data, len); @@ -1008,7 +1008,7 @@ void LocalStore::addToStore(const ValidPathInfo & info, Source & source, if (hashResult.first != info.narHash) throw Error("hash mismatch importing path '%s';\n wanted: %s\n got: %s", - printStorePath(info.path), info.narHash.to_string(Base::Base32, true), hashResult.first.to_string(Base::Base32, true)); + printStorePath(info.path), info.narHash.to_string(Base32, true), hashResult.first.to_string(Base32, true)); if (hashResult.second != info.narSize) throw Error("size mismatch importing path '%s';\n wanted: %s\n got: %s", @@ -1067,10 +1067,10 @@ StorePath LocalStore::addToStoreFromDump(const string & dump, const string & nam sha256); otherwise, compute it here. */ HashResult hash; if (method == FileIngestionMethod::Recursive) { - hash.first = hashAlgo == HashType::SHA256 ? h : hashString(HashType::SHA256, dump); + hash.first = hashAlgo == htSHA256 ? h : hashString(htSHA256, dump); hash.second = dump.size(); } else - hash = hashPath(HashType::SHA256, realPath); + hash = hashPath(htSHA256, realPath); optimisePath(realPath); // FIXME: combine with hashPath() @@ -1109,7 +1109,7 @@ StorePath LocalStore::addToStore(const string & name, const Path & _srcPath, StorePath LocalStore::addTextToStore(const string & name, const string & s, const StorePathSet & references, RepairFlag repair) { - auto hash = hashString(HashType::SHA256, s); + auto hash = hashString(htSHA256, s); auto dstPath = makeTextPath(name, hash, references); addTempRoot(dstPath); @@ -1133,7 +1133,7 @@ StorePath LocalStore::addTextToStore(const string & name, const string & s, StringSink sink; dumpString(s, sink); - auto narHash = hashString(HashType::SHA256, *sink.s); + auto narHash = hashString(htSHA256, *sink.s); optimisePath(realPath); @@ -1141,7 +1141,7 @@ StorePath LocalStore::addTextToStore(const string & name, const string & s, info.narHash = narHash; info.narSize = sink.s->size(); info.references = references; - info.ca = "text:" + hash.to_string(Base::Base32, true); + info.ca = "text:" + hash.to_string(Base32, true); registerValidPath(info); } @@ -1219,9 +1219,9 @@ bool LocalStore::verifyStore(bool checkContents, RepairFlag repair) printInfo("checking link hashes..."); for (auto & link : readDirectory(linksDir)) { - printMsg(Verbosity::Talkative, "checking contents of '%s'", link.name); + printMsg(lvlTalkative, "checking contents of '%s'", link.name); Path linkPath = linksDir + "/" + link.name; - string hash = hashPath(HashType::SHA256, linkPath).first.to_string(Base::Base32, false); + string hash = hashPath(htSHA256, linkPath).first.to_string(Base32, false); if (hash != link.name) { logError({ .name = "Invalid hash", @@ -1242,14 +1242,14 @@ bool LocalStore::verifyStore(bool checkContents, RepairFlag repair) printInfo("checking store hashes..."); - Hash nullHash(HashType::SHA256); + Hash nullHash(htSHA256); for (auto & i : validPaths) { try { auto info = std::const_pointer_cast(std::shared_ptr(queryPathInfo(i))); /* Check the content hash (optionally - slow). */ - printMsg(Verbosity::Talkative, "checking contents of '%s'", printStorePath(i)); + printMsg(lvlTalkative, "checking contents of '%s'", printStorePath(i)); std::unique_ptr hashSink; if (info->ca == "" || !info->references.count(info->path)) @@ -1264,7 +1264,7 @@ bool LocalStore::verifyStore(bool checkContents, RepairFlag repair) logError({ .name = "Invalid hash - path modified", .hint = hintfmt("path '%s' was modified! expected hash '%s', got '%s'", - printStorePath(i), info->narHash.to_string(Base::Base32, true), current.first.to_string(Base::Base32, true)) + printStorePath(i), info->narHash.to_string(Base32, true), current.first.to_string(Base32, true)) }); if (repair) repairPath(i); else errors = true; } else { diff --git a/src/libstore/local-store.hh b/src/libstore/local-store.hh index 90d921a2a..e17cc45ae 100644 --- a/src/libstore/local-store.hh +++ b/src/libstore/local-store.hh @@ -155,7 +155,7 @@ public: true) or simply the contents of a regular file (if recursive == false). */ StorePath addToStoreFromDump(const string & dump, const string & name, - FileIngestionMethod method = FileIngestionMethod::Recursive, HashType hashAlgo = HashType::SHA256, RepairFlag repair = NoRepair) override; + FileIngestionMethod method = FileIngestionMethod::Recursive, HashType hashAlgo = htSHA256, RepairFlag repair = NoRepair) override; StorePath addTextToStore(const string & name, const string & s, const StorePathSet & references, RepairFlag repair) override; diff --git a/src/libstore/misc.cc b/src/libstore/misc.cc index 369fbbd37..e68edb38c 100644 --- a/src/libstore/misc.cc +++ b/src/libstore/misc.cc @@ -112,7 +112,7 @@ void Store::queryMissing(const std::vector & targets, StorePathSet & willBuild_, StorePathSet & willSubstitute_, StorePathSet & unknown_, unsigned long long & downloadSize_, unsigned long long & narSize_) { - Activity act(*logger, Verbosity::Debug, ActivityType::Unknown, "querying info about missing paths"); + Activity act(*logger, lvlDebug, actUnknown, "querying info about missing paths"); downloadSize_ = narSize_ = 0; diff --git a/src/libstore/nar-info-disk-cache.cc b/src/libstore/nar-info-disk-cache.cc index c5da5a6be..552970248 100644 --- a/src/libstore/nar-info-disk-cache.cc +++ b/src/libstore/nar-info-disk-cache.cc @@ -230,9 +230,9 @@ public: (std::string(info->path.name())) (narInfo ? narInfo->url : "", narInfo != 0) (narInfo ? narInfo->compression : "", narInfo != 0) - (narInfo && narInfo->fileHash ? narInfo->fileHash.to_string(Base::Base32, true) : "", narInfo && narInfo->fileHash) + (narInfo && narInfo->fileHash ? narInfo->fileHash.to_string(Base32, true) : "", narInfo && narInfo->fileHash) (narInfo ? narInfo->fileSize : 0, narInfo != 0 && narInfo->fileSize) - (info->narHash.to_string(Base::Base32, true)) + (info->narHash.to_string(Base32, true)) (info->narSize) (concatStringsSep(" ", info->shortRefs())) (info->deriver ? std::string(info->deriver->to_string()) : "", (bool) info->deriver) diff --git a/src/libstore/nar-info.cc b/src/libstore/nar-info.cc index ade132d58..bb4448c90 100644 --- a/src/libstore/nar-info.cc +++ b/src/libstore/nar-info.cc @@ -86,11 +86,11 @@ std::string NarInfo::to_string(const Store & store) const res += "URL: " + url + "\n"; assert(compression != ""); res += "Compression: " + compression + "\n"; - assert(fileHash.type == HashType::SHA256); - res += "FileHash: " + fileHash.to_string(Base::Base32, true) + "\n"; + assert(fileHash.type == htSHA256); + res += "FileHash: " + fileHash.to_string(Base32, true) + "\n"; res += "FileSize: " + std::to_string(fileSize) + "\n"; - assert(narHash.type == HashType::SHA256); - res += "NarHash: " + narHash.to_string(Base::Base32, true) + "\n"; + assert(narHash.type == htSHA256); + res += "NarHash: " + narHash.to_string(Base32, true) + "\n"; res += "NarSize: " + std::to_string(narSize) + "\n"; res += "References: " + concatStringsSep(" ", shortRefs()) + "\n"; diff --git a/src/libstore/optimise-store.cc b/src/libstore/optimise-store.cc index 820243d30..b2b2412a3 100644 --- a/src/libstore/optimise-store.cc +++ b/src/libstore/optimise-store.cc @@ -57,7 +57,7 @@ LocalStore::InodeHash LocalStore::loadInodeHash() } if (errno) throw SysError("reading directory '%1%'", linksDir); - printMsg(Verbosity::Talkative, format("loaded %1% hash inodes") % inodeHash.size()); + printMsg(lvlTalkative, format("loaded %1% hash inodes") % inodeHash.size()); return inodeHash; } @@ -152,11 +152,11 @@ void LocalStore::optimisePath_(Activity * act, OptimiseStats & stats, Also note that if `path' is a symlink, then we're hashing the contents of the symlink (i.e. the result of readlink()), not the contents of the target (which may not even exist). */ - Hash hash = hashPath(HashType::SHA256, path).first; - debug(format("'%1%' has hash '%2%'") % path % hash.to_string(Base::Base32, true)); + Hash hash = hashPath(htSHA256, path).first; + debug(format("'%1%' has hash '%2%'") % path % hash.to_string(Base32, true)); /* Check if this is a known hash. */ - Path linkPath = linksDir + "/" + hash.to_string(Base::Base32, false); + Path linkPath = linksDir + "/" + hash.to_string(Base32, false); retry: if (!pathExists(linkPath)) { @@ -205,7 +205,7 @@ void LocalStore::optimisePath_(Activity * act, OptimiseStats & stats, goto retry; } - printMsg(Verbosity::Talkative, format("linking '%1%' to '%2%'") % path % linkPath); + printMsg(lvlTalkative, format("linking '%1%' to '%2%'") % path % linkPath); /* Make the containing directory writable, but only if it's not the store itself (we don't want or need to mess with its @@ -255,13 +255,13 @@ void LocalStore::optimisePath_(Activity * act, OptimiseStats & stats, stats.blocksFreed += st.st_blocks; if (act) - act->result(ResultType::FileLinked, st.st_size, st.st_blocks); + act->result(resFileLinked, st.st_size, st.st_blocks); } void LocalStore::optimiseStore(OptimiseStats & stats) { - Activity act(*logger, ActivityType::OptimiseStore); + Activity act(*logger, actOptimiseStore); auto paths = queryAllValidPaths(); InodeHash inodeHash = loadInodeHash(); @@ -274,7 +274,7 @@ void LocalStore::optimiseStore(OptimiseStats & stats) addTempRoot(i); if (!isValidPath(i)) continue; /* path was GC'ed, probably */ { - Activity act(*logger, Verbosity::Talkative, ActivityType::Unknown, fmt("optimising path '%s'", printStorePath(i))); + Activity act(*logger, lvlTalkative, actUnknown, fmt("optimising path '%s'", printStorePath(i))); optimisePath_(&act, stats, realStoreDir + "/" + std::string(i.to_string()), inodeHash); } done++; diff --git a/src/libstore/path.cc b/src/libstore/path.cc index 70a336c05..b3d8ce95c 100644 --- a/src/libstore/path.cc +++ b/src/libstore/path.cc @@ -31,7 +31,7 @@ StorePath::StorePath(std::string_view _baseName) } StorePath::StorePath(const Hash & hash, std::string_view _name) - : baseName((hash.to_string(Base::Base32, false) + "-").append(std::string(_name))) + : baseName((hash.to_string(Base32, false) + "-").append(std::string(_name))) { checkName(baseName, name()); } diff --git a/src/libstore/references.cc b/src/libstore/references.cc index 839fd13db..a10d536a3 100644 --- a/src/libstore/references.cc +++ b/src/libstore/references.cc @@ -54,7 +54,7 @@ struct RefScanSink : Sink string tail; - RefScanSink() : hashSink(HashType::SHA256) { } + RefScanSink() : hashSink(htSHA256) { } void operator () (const unsigned char * data, size_t len); }; @@ -96,7 +96,7 @@ PathSet scanForReferences(const string & path, string s = string(baseName, 0, pos); assert(s.size() == refLength); assert(backMap.find(s) == backMap.end()); - // parseHash(HashType::SHA256, s); + // parseHash(htSHA256, s); sink.hashes.insert(s); backMap[s] = i; } diff --git a/src/libstore/remote-store.cc b/src/libstore/remote-store.cc index dcd3b7cbf..f5f2ab7fd 100644 --- a/src/libstore/remote-store.cc +++ b/src/libstore/remote-store.cc @@ -177,11 +177,11 @@ void RemoteStore::setOptions(Connection & conn) << settings.keepFailed << settings.keepGoing << settings.tryFallback - << (uint64_t) verbosity + << verbosity << settings.maxBuildJobs << settings.maxSilentTime << true - << (uint64_t) (settings.verboseBuild ? Verbosity::Error : Verbosity::Vomit) + << (settings.verboseBuild ? lvlError : lvlVomit) << 0 // obsolete log type << 0 /* obsolete print build trace */ << settings.buildCores @@ -375,7 +375,7 @@ void RemoteStore::queryPathInfoUncached(const StorePath & path, info = std::make_shared(StorePath(path)); auto deriver = readString(conn->from); if (deriver != "") info->deriver = parseStorePath(deriver); - info->narHash = Hash(readString(conn->from), HashType::SHA256); + info->narHash = Hash(readString(conn->from), htSHA256); info->references = readStorePaths(*this, conn->from); conn->from >> info->registrationTime >> info->narSize; if (GET_PROTOCOL_MINOR(conn->daemonVersion) >= 16) { @@ -462,7 +462,7 @@ void RemoteStore::addToStore(const ValidPathInfo & info, Source & source, conn->to << wopAddToStoreNar << printStorePath(info.path) << (info.deriver ? printStorePath(*info.deriver) : "") - << info.narHash.to_string(Base::Base16, false); + << info.narHash.to_string(Base16, false); writeStorePaths(*this, conn->to, info.references); conn->to << info.registrationTime << info.narSize << info.ultimate << info.sigs << info.ca @@ -486,7 +486,7 @@ StorePath RemoteStore::addToStore(const string & name, const Path & _srcPath, conn->to << wopAddToStore << name - << ((hashAlgo == HashType::SHA256 && method == FileIngestionMethod::Recursive) ? 0 : 1) /* backwards compatibility hack */ + << ((hashAlgo == htSHA256 && method == FileIngestionMethod::Recursive) ? 0 : 1) /* backwards compatibility hack */ << (method == FileIngestionMethod::Recursive ? 1 : 0) << printHashType(hashAlgo); diff --git a/src/libstore/remote-store.hh b/src/libstore/remote-store.hh index 0908b511e..80c8e9f11 100644 --- a/src/libstore/remote-store.hh +++ b/src/libstore/remote-store.hh @@ -63,7 +63,7 @@ public: std::shared_ptr accessor) override; StorePath addToStore(const string & name, const Path & srcPath, - FileIngestionMethod method = FileIngestionMethod::Recursive, HashType hashAlgo = HashType::SHA256, + FileIngestionMethod method = FileIngestionMethod::Recursive, HashType hashAlgo = htSHA256, PathFilter & filter = defaultPathFilter, RepairFlag repair = NoRepair) override; StorePath addTextToStore(const string & name, const string & s, diff --git a/src/libstore/s3-binary-cache-store.cc b/src/libstore/s3-binary-cache-store.cc index 9fc6da9bf..427dd48ce 100644 --- a/src/libstore/s3-binary-cache-store.cc +++ b/src/libstore/s3-binary-cache-store.cc @@ -70,9 +70,9 @@ static void initAWS() shared.cc), so don't let aws-sdk-cpp override it. */ options.cryptoOptions.initAndCleanupOpenSSL = false; - if (verbosity >= Verbosity::Debug) { + if (verbosity >= lvlDebug) { options.loggingOptions.logLevel = - verbosity == Verbosity::Debug + verbosity == lvlDebug ? Aws::Utils::Logging::LogLevel::Debug : Aws::Utils::Logging::LogLevel::Trace; options.loggingOptions.logger_create_fn = [options]() { diff --git a/src/libstore/ssh.cc b/src/libstore/ssh.cc index f61c094a2..84548a6e4 100644 --- a/src/libstore/ssh.cc +++ b/src/libstore/ssh.cc @@ -58,7 +58,7 @@ std::unique_ptr SSHMaster::startCommand(const std::string addCommonSSHOpts(args); if (socketPath != "") args.insert(args.end(), {"-S", socketPath}); - if (verbosity >= Verbosity::Chatty) + if (verbosity >= lvlChatty) args.push_back("-v"); } @@ -110,7 +110,7 @@ Path SSHMaster::startMaster() , "-o", "LocalCommand=echo started" , "-o", "PermitLocalCommand=yes" }; - if (verbosity >= Verbosity::Chatty) + if (verbosity >= lvlChatty) args.push_back("-v"); addCommonSSHOpts(args); execvp(args.begin()->c_str(), stringsToCharPtrs(args).data()); diff --git a/src/libstore/store-api.cc b/src/libstore/store-api.cc index 5857b6f34..2615a43d4 100644 --- a/src/libstore/store-api.cc +++ b/src/libstore/store-api.cc @@ -143,8 +143,8 @@ StorePath Store::makeStorePath(const string & type, const Hash & hash, std::string_view name) const { /* e.g., "source:sha256:1abc...:/nix/store:foo.tar.gz" */ - string s = type + ":" + hash.to_string(Base::Base16, true) + ":" + storeDir + ":" + std::string(name); - auto h = compressHash(hashString(HashType::SHA256, s), 20); + string s = type + ":" + hash.to_string(Base16, true) + ":" + storeDir + ":" + std::string(name); + auto h = compressHash(hashString(htSHA256, s), 20); return StorePath(h, name); } @@ -179,15 +179,15 @@ StorePath Store::makeFixedOutputPath( const StorePathSet & references, bool hasSelfReference) const { - if (hash.type == HashType::SHA256 && recursive == FileIngestionMethod::Recursive) { + if (hash.type == htSHA256 && recursive == FileIngestionMethod::Recursive) { return makeStorePath(makeType(*this, "source", references, hasSelfReference), hash, name); } else { assert(references.empty()); return makeStorePath("output:out", - hashString(HashType::SHA256, + hashString(htSHA256, "fixed:out:" + (recursive == FileIngestionMethod::Recursive ? (string) "r:" : "") - + hash.to_string(Base::Base16, true) + ":"), + + hash.to_string(Base16, true) + ":"), name); } } @@ -196,7 +196,7 @@ StorePath Store::makeFixedOutputPath( StorePath Store::makeTextPath(std::string_view name, const Hash & hash, const StorePathSet & references) const { - assert(hash.type == HashType::SHA256); + assert(hash.type == htSHA256); /* Stuff the references (if any) into the type. This is a bit hacky, but we can't put them in `s' since that would be ambiguous. */ @@ -217,7 +217,7 @@ std::pair Store::computeStorePathForPath(std::string_view name, StorePath Store::computeStorePathForText(const string & name, const string & s, const StorePathSet & references) const { - return makeTextPath(name, hashString(HashType::SHA256, s), references); + return makeTextPath(name, hashString(htSHA256, s), references); } @@ -430,7 +430,7 @@ string Store::makeValidityRegistration(const StorePathSet & paths, auto info = queryPathInfo(i); if (showHash) { - s += info->narHash.to_string(Base::Base16, false) + "\n"; + s += info->narHash.to_string(Base16, false) + "\n"; s += (format("%1%\n") % info->narSize).str(); } @@ -505,7 +505,7 @@ void Store::pathInfoToJSON(JSONPlaceholder & jsonOut, const StorePathSet & store if (!narInfo->url.empty()) jsonPath.attr("url", narInfo->url); if (narInfo->fileHash) - jsonPath.attr("downloadHash", narInfo->fileHash.to_string(Base::Base32, true)); + jsonPath.attr("downloadHash", narInfo->fileHash.to_string(Base32, true)); if (narInfo->fileSize) jsonPath.attr("downloadSize", narInfo->fileSize); if (showClosureSize) @@ -568,7 +568,7 @@ void copyStorePath(ref srcStore, ref dstStore, auto srcUri = srcStore->getUri(); auto dstUri = dstStore->getUri(); - Activity act(*logger, Verbosity::Info, ActivityType::CopyPath, + Activity act(*logger, lvlInfo, actCopyPath, srcUri == "local" || srcUri == "daemon" ? fmt("copying path '%s' to '%s'", srcStore->printStorePath(storePath), dstUri) : dstUri == "local" || dstUri == "daemon" @@ -585,7 +585,7 @@ void copyStorePath(ref srcStore, ref dstStore, StringSink sink; srcStore->narFromPath({storePath}, sink); auto info2 = make_ref(*info); - info2->narHash = hashString(HashType::SHA256, *sink.s); + info2->narHash = hashString(htSHA256, *sink.s); if (!info->narSize) info2->narSize = sink.s->size(); if (info->ultimate) info2->ultimate = false; info = info2; @@ -627,7 +627,7 @@ void copyPaths(ref srcStore, ref dstStore, const StorePathSet & st if (missing.empty()) return; - Activity act(*logger, Verbosity::Info, ActivityType::CopyPaths, fmt("copying %d paths", missing.size())); + Activity act(*logger, lvlInfo, actCopyPaths, fmt("copying %d paths", missing.size())); std::atomic nrDone{0}; std::atomic nrFailed{0}; @@ -653,7 +653,7 @@ void copyPaths(ref srcStore, ref dstStore, const StorePathSet & st auto info = srcStore->queryPathInfo(srcStore->parseStorePath(storePath)); bytesExpected += info->narSize; - act.setExpected(ActivityType::CopyPath, bytesExpected); + act.setExpected(actCopyPath, bytesExpected); return srcStore->printStorePathSet(info->references); }, @@ -672,7 +672,7 @@ void copyPaths(ref srcStore, ref dstStore, const StorePathSet & st nrFailed++; if (!settings.keepGoing) throw e; - logger->log(Verbosity::Error, fmt("could not copy %s: %s", storePathS, e.what())); + logger->log(lvlError, fmt("could not copy %s: %s", storePathS, e.what())); showProgress(); return; } @@ -703,7 +703,7 @@ std::optional decodeValidPathInfo(const Store & store, std::istre if (hashGiven) { string s; getline(str, s); - info.narHash = Hash(s, HashType::SHA256); + info.narHash = Hash(s, htSHA256); getline(str, s); if (!string2Int(s, info.narSize)) throw Error("number expected"); } @@ -746,7 +746,7 @@ std::string ValidPathInfo::fingerprint(const Store & store) const store.printStorePath(path)); return "1;" + store.printStorePath(path) + ";" - + narHash.to_string(Base::Base32, true) + ";" + + narHash.to_string(Base32, true) + ";" + std::to_string(narSize) + ";" + concatStringsSep(",", store.printStorePathSet(references)); } @@ -826,7 +826,7 @@ std::string makeFixedOutputCA(FileIngestionMethod recursive, const Hash & hash) { return "fixed:" + (recursive == FileIngestionMethod::Recursive ? (std::string) "r:" : "") - + hash.to_string(Base::Base32, true); + + hash.to_string(Base32, true); } diff --git a/src/libstore/store-api.hh b/src/libstore/store-api.hh index 072aebc8d..6f4dd959c 100644 --- a/src/libstore/store-api.hh +++ b/src/libstore/store-api.hh @@ -360,7 +360,7 @@ public: path and the cryptographic hash of the contents of srcPath. */ std::pair computeStorePathForPath(std::string_view name, const Path & srcPath, FileIngestionMethod method = FileIngestionMethod::Recursive, - HashType hashAlgo = HashType::SHA256, PathFilter & filter = defaultPathFilter) const; + HashType hashAlgo = htSHA256, PathFilter & filter = defaultPathFilter) const; /* Preparatory part of addTextToStore(). @@ -454,12 +454,12 @@ public: The function object `filter' can be used to exclude files (see libutil/archive.hh). */ virtual StorePath addToStore(const string & name, const Path & srcPath, - FileIngestionMethod method = FileIngestionMethod::Recursive, HashType hashAlgo = HashType::SHA256, + FileIngestionMethod method = FileIngestionMethod::Recursive, HashType hashAlgo = htSHA256, PathFilter & filter = defaultPathFilter, RepairFlag repair = NoRepair) = 0; // FIXME: remove? virtual StorePath addToStoreFromDump(const string & dump, const string & name, - FileIngestionMethod method = FileIngestionMethod::Recursive, HashType hashAlgo = HashType::SHA256, RepairFlag repair = NoRepair) + FileIngestionMethod method = FileIngestionMethod::Recursive, HashType hashAlgo = htSHA256, RepairFlag repair = NoRepair) { throw Error("addToStoreFromDump() is not supported by this store"); } @@ -553,7 +553,7 @@ public: each path is included. */ void pathInfoToJSON(JSONPlaceholder & jsonOut, const StorePathSet & storePaths, bool includeImpureInfo, bool showClosureSize, - Base hashBase = Base::Base32, + Base hashBase = Base32, AllowInvalidFlag allowInvalid = DisallowInvalid); /* Return the size of the closure of the specified path, that is, diff --git a/src/libutil/args.hh b/src/libutil/args.hh index 73991881d..433d26bba 100644 --- a/src/libutil/args.hh +++ b/src/libutil/args.hh @@ -10,7 +10,7 @@ namespace nix { MakeError(UsageError, Error); -enum struct HashType : char; +enum HashType : char; class Args { diff --git a/src/libutil/compression.cc b/src/libutil/compression.cc index 9f270c8f3..a117ddc72 100644 --- a/src/libutil/compression.cc +++ b/src/libutil/compression.cc @@ -314,7 +314,7 @@ struct XzCompressionSink : CompressionSink ret = lzma_stream_encoder_mt(&strm, &mt_options); done = true; #else - printMsg(Verbosity::Error, "warning: parallel XZ compression requested but not supported, falling back to single-threaded compression"); + printMsg(lvlError, "warning: parallel XZ compression requested but not supported, falling back to single-threaded compression"); #endif } diff --git a/src/libutil/error.cc b/src/libutil/error.cc index 5c2f9ed3f..0fad9ae42 100644 --- a/src/libutil/error.cc +++ b/src/libutil/error.cc @@ -110,50 +110,50 @@ std::ostream& operator<<(std::ostream &out, const ErrorInfo &einfo) string levelString; switch (einfo.level) { - case Verbosity::Error: { + case Verbosity::lvlError: { levelString = ANSI_RED; levelString += "error:"; levelString += ANSI_NORMAL; break; } - case Verbosity::Warn: { + case Verbosity::lvlWarn: { levelString = ANSI_YELLOW; levelString += "warning:"; levelString += ANSI_NORMAL; break; } - case Verbosity::Info: { + case Verbosity::lvlInfo: { levelString = ANSI_GREEN; levelString += "info:"; levelString += ANSI_NORMAL; break; } - case Verbosity::Talkative: { + case Verbosity::lvlTalkative: { levelString = ANSI_GREEN; levelString += "talk:"; levelString += ANSI_NORMAL; break; } - case Verbosity::Chatty: { + case Verbosity::lvlChatty: { levelString = ANSI_GREEN; levelString += "chat:"; levelString += ANSI_NORMAL; break; } - case Verbosity::Vomit: { + case Verbosity::lvlVomit: { levelString = ANSI_GREEN; levelString += "vomit:"; levelString += ANSI_NORMAL; break; } - case Verbosity::Debug: { + case Verbosity::lvlDebug: { levelString = ANSI_YELLOW; levelString += "debug:"; levelString += ANSI_NORMAL; break; } default: { - levelString = fmt("invalid error level: %d", (uint8_t)einfo.level); + levelString = fmt("invalid error level: %1%", einfo.level); break; } } diff --git a/src/libutil/error.hh b/src/libutil/error.hh index 4f9df826f..1e6102ce1 100644 --- a/src/libutil/error.hh +++ b/src/libutil/error.hh @@ -40,15 +40,15 @@ See the error-demo.cc program for usage examples. */ -enum struct Verbosity { - Error = 0, - Warn, - Info, - Talkative, - Chatty, - Debug, - Vomit, -}; +typedef enum { + lvlError = 0, + lvlWarn, + lvlInfo, + lvlTalkative, + lvlChatty, + lvlDebug, + lvlVomit +} Verbosity; // ErrPos indicates the location of an error in a nix file. struct ErrPos { @@ -113,7 +113,7 @@ public: template BaseError(unsigned int status, const Args & ... args) - : err { .level = Verbosity::Error, + : err { .level = lvlError, .hint = hintfmt(args...) } , status(status) @@ -121,13 +121,13 @@ public: template BaseError(const std::string & fs, const Args & ... args) - : err { .level = Verbosity::Error, + : err { .level = lvlError, .hint = hintfmt(fs, args...) } { } BaseError(hintformat hint) - : err { .level = Verbosity::Error, + : err { .level = lvlError, .hint = hint } { } diff --git a/src/libutil/hash.cc b/src/libutil/hash.cc index 106b47ae3..7a8d091df 100644 --- a/src/libutil/hash.cc +++ b/src/libutil/hash.cc @@ -21,10 +21,10 @@ void Hash::init() { if (!type) abort(); switch (*type) { - case HashType::MD5: hashSize = md5HashSize; break; - case HashType::SHA1: hashSize = sha1HashSize; break; - case HashType::SHA256: hashSize = sha256HashSize; break; - case HashType::SHA512: hashSize = sha512HashSize; break; + case htMD5: hashSize = md5HashSize; break; + case htSHA1: hashSize = sha1HashSize; break; + case htSHA256: hashSize = sha256HashSize; break; + case htSHA512: hashSize = sha512HashSize; break; } assert(hashSize <= maxHashSize); memset(hash, 0, maxHashSize); @@ -101,7 +101,7 @@ static string printHash32(const Hash & hash) string printHash16or32(const Hash & hash) { - return hash.to_string(hash.type == HashType::MD5 ? Base::Base16 : Base::Base32, false); + return hash.to_string(hash.type == htMD5 ? Base16 : Base32, false); } @@ -115,19 +115,19 @@ HashType assertInitHashType(const Hash & h) { std::string Hash::to_string(Base base, bool includeType) const { std::string s; - if (base == Base::SRI || includeType) { + if (base == SRI || includeType) { s += printHashType(assertInitHashType(*this)); - s += base == Base::SRI ? '-' : ':'; + s += base == SRI ? '-' : ':'; } switch (base) { - case Base::Base16: + case Base16: s += printHash16(*this); break; - case Base::Base32: + case Base32: s += printHash32(*this); break; - case Base::Base64: - case Base::SRI: + case Base64: + case SRI: s += base64Encode(std::string((const char *) hash, hashSize)); break; } @@ -241,29 +241,29 @@ union Ctx static void start(HashType ht, Ctx & ctx) { - if (ht == HashType::MD5) MD5_Init(&ctx.md5); - else if (ht == HashType::SHA1) SHA1_Init(&ctx.sha1); - else if (ht == HashType::SHA256) SHA256_Init(&ctx.sha256); - else if (ht == HashType::SHA512) SHA512_Init(&ctx.sha512); + if (ht == htMD5) MD5_Init(&ctx.md5); + else if (ht == htSHA1) SHA1_Init(&ctx.sha1); + else if (ht == htSHA256) SHA256_Init(&ctx.sha256); + else if (ht == htSHA512) SHA512_Init(&ctx.sha512); } static void update(HashType ht, Ctx & ctx, const unsigned char * bytes, size_t len) { - if (ht == HashType::MD5) MD5_Update(&ctx.md5, bytes, len); - else if (ht == HashType::SHA1) SHA1_Update(&ctx.sha1, bytes, len); - else if (ht == HashType::SHA256) SHA256_Update(&ctx.sha256, bytes, len); - else if (ht == HashType::SHA512) SHA512_Update(&ctx.sha512, bytes, len); + if (ht == htMD5) MD5_Update(&ctx.md5, bytes, len); + else if (ht == htSHA1) SHA1_Update(&ctx.sha1, bytes, len); + else if (ht == htSHA256) SHA256_Update(&ctx.sha256, bytes, len); + else if (ht == htSHA512) SHA512_Update(&ctx.sha512, bytes, len); } static void finish(HashType ht, Ctx & ctx, unsigned char * hash) { - if (ht == HashType::MD5) MD5_Final(hash, &ctx.md5); - else if (ht == HashType::SHA1) SHA1_Final(hash, &ctx.sha1); - else if (ht == HashType::SHA256) SHA256_Final(hash, &ctx.sha256); - else if (ht == HashType::SHA512) SHA512_Final(hash, &ctx.sha512); + if (ht == htMD5) MD5_Final(hash, &ctx.md5); + else if (ht == htSHA1) SHA1_Final(hash, &ctx.sha1); + else if (ht == htSHA256) SHA256_Final(hash, &ctx.sha256); + else if (ht == htSHA512) SHA512_Final(hash, &ctx.sha512); } @@ -344,10 +344,10 @@ Hash compressHash(const Hash & hash, unsigned int newSize) std::optional parseHashTypeOpt(const string & s) { - if (s == "md5") return HashType::MD5; - else if (s == "sha1") return HashType::SHA1; - else if (s == "sha256") return HashType::SHA256; - else if (s == "sha512") return HashType::SHA512; + if (s == "md5") return htMD5; + else if (s == "sha1") return htSHA1; + else if (s == "sha256") return htSHA256; + else if (s == "sha512") return htSHA512; else return std::optional {}; } @@ -362,14 +362,15 @@ HashType parseHashType(const string & s) string printHashType(HashType ht) { - string ret; switch (ht) { - case HashType::MD5: ret = "md5"; break; - case HashType::SHA1: ret = "sha1"; break; - case HashType::SHA256: ret = "sha256"; break; - case HashType::SHA512: ret = "sha512"; break; + case htMD5: return "md5"; break; + case htSHA1: return "sha1"; break; + case htSHA256: return "sha256"; break; + case htSHA512: return "sha512"; break; } - return ret; + // illegal hash type enum value internally, as opposed to external input + // which should be validated with nice error message. + abort(); } } diff --git a/src/libutil/hash.hh b/src/libutil/hash.hh index 8f9364440..0d9916508 100644 --- a/src/libutil/hash.hh +++ b/src/libutil/hash.hh @@ -10,12 +10,7 @@ namespace nix { MakeError(BadHash, Error); -enum struct HashType : char { - MD5, - SHA1, - SHA256, - SHA512, -}; +enum HashType : char { htMD5, htSHA1, htSHA256, htSHA512 }; const int md5HashSize = 16; @@ -25,12 +20,7 @@ const int sha512HashSize = 64; extern const string base32Chars; -enum struct Base { - Base64, - Base32, - Base16, - SRI, -}; +enum Base : int { Base64, Base32, Base16, SRI }; struct Hash @@ -97,14 +87,14 @@ struct Hash std::string gitRev() const { - assert(type == HashType::SHA1); - return to_string(Base::Base16, false); + assert(type == htSHA1); + return to_string(Base16, false); } std::string gitShortRev() const { - assert(type == HashType::SHA1); - return std::string(to_string(Base::Base16, false), 0, 7); + assert(type == htSHA1); + return std::string(to_string(Base16, false), 0, 7); } }; diff --git a/src/libutil/logging.cc b/src/libutil/logging.cc index 04156151f..105fadb15 100644 --- a/src/libutil/logging.cc +++ b/src/libutil/logging.cc @@ -22,7 +22,7 @@ Logger * logger = makeSimpleLogger(true); void Logger::warn(const std::string & msg) { - log(Verbosity::Warn, ANSI_YELLOW "warning:" ANSI_NORMAL " " + msg); + log(lvlWarn, ANSI_YELLOW "warning:" ANSI_NORMAL " " + msg); } void Logger::writeToStdout(std::string_view s) @@ -57,10 +57,10 @@ public: if (systemd) { char c; switch (lvl) { - case Verbosity::Error: c = '3'; break; - case Verbosity::Warn: c = '4'; break; - case Verbosity::Info: c = '5'; break; - case Verbosity::Talkative: case Verbosity::Chatty: c = '6'; break; + case lvlError: c = '3'; break; + case lvlWarn: c = '4'; break; + case lvlInfo: c = '5'; break; + case lvlTalkative: case lvlChatty: c = '6'; break; default: c = '7'; } prefix = std::string("<") + c + ">"; @@ -87,18 +87,18 @@ public: void result(ActivityId act, ResultType type, const Fields & fields) override { - if (type == ResultType::BuildLogLine && printBuildLogs) { + if (type == resBuildLogLine && printBuildLogs) { auto lastLine = fields[0].s; printError(lastLine); } - else if (type == ResultType::PostBuildLogLine && printBuildLogs) { + else if (type == resPostBuildLogLine && printBuildLogs) { auto lastLine = fields[0].s; printError("post-build-hook: " + lastLine); } } }; -Verbosity verbosity = Verbosity::Info; +Verbosity verbosity = lvlInfo; void warnOnce(bool & haveWarned, const FormatOrString & fs) { @@ -158,7 +158,7 @@ struct JSONLogger : Logger { void write(const nlohmann::json & json) { - prevLogger.log(Verbosity::Error, "@nix " + json.dump()); + prevLogger.log(lvlError, "@nix " + json.dump()); } void log(Verbosity lvl, const FormatOrString & fs) override @@ -246,7 +246,7 @@ bool handleJSONLogMessage(const std::string & msg, if (action == "start") { auto type = (ActivityType) json["type"]; - if (trusted || type == ActivityType::Download) + if (trusted || type == actFileTransfer) activities.emplace(std::piecewise_construct, std::forward_as_tuple(json["id"]), std::forward_as_tuple(*logger, (Verbosity) json["level"], type, @@ -264,7 +264,7 @@ bool handleJSONLogMessage(const std::string & msg, else if (action == "setPhase") { std::string phase = json["phase"]; - act.result(ResultType::SetPhase, phase); + act.result(resSetPhase, phase); } else if (action == "msg") { diff --git a/src/libutil/logging.hh b/src/libutil/logging.hh index 3b54101f0..b1583eced 100644 --- a/src/libutil/logging.hh +++ b/src/libutil/logging.hh @@ -5,32 +5,32 @@ namespace nix { -enum struct ActivityType { - Unknown = 0, - CopyPath = 100, - Download = 101, - Realise = 102, - CopyPaths = 103, - Builds = 104, - Build = 105, - OptimiseStore = 106, - VerifyPaths = 107, - Substitute = 108, - QueryPathInfo = 109, - PostBuildHook = 110, - BuildWaiting = 111, -}; - -enum struct ResultType { - FileLinked = 100, - BuildLogLine = 101, - UntrustedPath = 102, - CorruptedPath = 103, - SetPhase = 104, - Progress = 105, - SetExpected = 106, - PostBuildLogLine = 107, -}; +typedef enum { + actUnknown = 0, + actCopyPath = 100, + actFileTransfer = 101, + actRealise = 102, + actCopyPaths = 103, + actBuilds = 104, + actBuild = 105, + actOptimiseStore = 106, + actVerifyPaths = 107, + actSubstitute = 108, + actQueryPathInfo = 109, + actPostBuildHook = 110, + actBuildWaiting = 111, +} ActivityType; + +typedef enum { + resFileLinked = 100, + resBuildLogLine = 101, + resUntrustedPath = 102, + resCorruptedPath = 103, + resSetPhase = 104, + resProgress = 105, + resSetExpected = 106, + resPostBuildLogLine = 107, +} ResultType; typedef uint64_t ActivityId; @@ -64,7 +64,7 @@ public: void log(const FormatOrString & fs) { - log(Verbosity::Info, fs); + log(lvlInfo, fs); } virtual void logEI(const ErrorInfo &ei) = 0; @@ -109,17 +109,17 @@ struct Activity Activity(Logger & logger, ActivityType type, const Logger::Fields & fields = {}, ActivityId parent = getCurActivity()) - : Activity(logger, Verbosity::Error, type, "", fields, parent) { }; + : Activity(logger, lvlError, type, "", fields, parent) { }; Activity(const Activity & act) = delete; ~Activity(); void progress(uint64_t done = 0, uint64_t expected = 0, uint64_t running = 0, uint64_t failed = 0) const - { result(ResultType::Progress, done, expected, running, failed); } + { result(resProgress, done, expected, running, failed); } void setExpected(ActivityType type2, uint64_t expected) const - { result(ResultType::SetExpected, (uint64_t)type2, expected); } + { result(resSetExpected, type2, expected); } template void result(ResultType type, const Args & ... args) const @@ -167,8 +167,8 @@ extern Verbosity verbosity; /* suppress msgs > this */ } \ } while (0) -#define logError(errorInfo...) logErrorInfo(Verbosity::Error, errorInfo) -#define logWarning(errorInfo...) logErrorInfo(Verbosity::Warn, errorInfo) +#define logError(errorInfo...) logErrorInfo(lvlError, errorInfo) +#define logWarning(errorInfo...) logErrorInfo(lvlWarn, errorInfo) /* Print a string message if the current log level is at least the specified level. Note that this has to be implemented as a macro to ensure that the @@ -180,13 +180,13 @@ extern Verbosity verbosity; /* suppress msgs > this */ } \ } while (0) -#define printError(args...) printMsg(Verbosity::Error, args) -#define printInfo(args...) printMsg(Verbosity::Info, args) -#define printTalkative(args...) printMsg(Verbosity::Talkative, args) -#define debug(args...) printMsg(Verbosity::Debug, args) -#define vomit(args...) printMsg(Verbosity::Vomit, args) +#define printError(args...) printMsg(lvlError, args) +#define printInfo(args...) printMsg(lvlInfo, args) +#define printTalkative(args...) printMsg(lvlTalkative, args) +#define debug(args...) printMsg(lvlDebug, args) +#define vomit(args...) printMsg(lvlVomit, args) -/* if verbosity >= Verbosity::Warn, print a message with a yellow 'warning:' prefix. */ +/* if verbosity >= lvlWarn, print a message with a yellow 'warning:' prefix. */ template inline void warn(const std::string & fs, const Args & ... args) { diff --git a/src/libutil/tests/hash.cc b/src/libutil/tests/hash.cc index 84a50d61b..412c03030 100644 --- a/src/libutil/tests/hash.cc +++ b/src/libutil/tests/hash.cc @@ -10,28 +10,28 @@ namespace nix { TEST(hashString, testKnownMD5Hashes1) { // values taken from: https://tools.ietf.org/html/rfc1321 auto s1 = ""; - auto hash = hashString(HashType::MD5, s1); + auto hash = hashString(HashType::htMD5, s1); ASSERT_EQ(hash.to_string(Base::Base16, true), "md5:d41d8cd98f00b204e9800998ecf8427e"); } TEST(hashString, testKnownMD5Hashes2) { // values taken from: https://tools.ietf.org/html/rfc1321 auto s2 = "abc"; - auto hash = hashString(HashType::MD5, s2); + auto hash = hashString(HashType::htMD5, s2); ASSERT_EQ(hash.to_string(Base::Base16, true), "md5:900150983cd24fb0d6963f7d28e17f72"); } TEST(hashString, testKnownSHA1Hashes1) { // values taken from: https://tools.ietf.org/html/rfc3174 auto s = "abc"; - auto hash = hashString(HashType::SHA1, s); + auto hash = hashString(HashType::htSHA1, s); ASSERT_EQ(hash.to_string(Base::Base16, true),"sha1:a9993e364706816aba3e25717850c26c9cd0d89d"); } TEST(hashString, testKnownSHA1Hashes2) { // values taken from: https://tools.ietf.org/html/rfc3174 auto s = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"; - auto hash = hashString(HashType::SHA1, s); + auto hash = hashString(HashType::htSHA1, s); ASSERT_EQ(hash.to_string(Base::Base16, true),"sha1:84983e441c3bd26ebaae4aa1f95129e5e54670f1"); } @@ -39,7 +39,7 @@ namespace nix { // values taken from: https://tools.ietf.org/html/rfc4634 auto s = "abc"; - auto hash = hashString(HashType::SHA256, s); + auto hash = hashString(HashType::htSHA256, s); ASSERT_EQ(hash.to_string(Base::Base16, true), "sha256:ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad"); } @@ -47,7 +47,7 @@ namespace nix { TEST(hashString, testKnownSHA256Hashes2) { // values taken from: https://tools.ietf.org/html/rfc4634 auto s = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"; - auto hash = hashString(HashType::SHA256, s); + auto hash = hashString(HashType::htSHA256, s); ASSERT_EQ(hash.to_string(Base::Base16, true), "sha256:248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1"); } @@ -55,7 +55,7 @@ namespace nix { TEST(hashString, testKnownSHA512Hashes1) { // values taken from: https://tools.ietf.org/html/rfc4634 auto s = "abc"; - auto hash = hashString(HashType::SHA512, s); + auto hash = hashString(HashType::htSHA512, s); ASSERT_EQ(hash.to_string(Base::Base16, true), "sha512:ddaf35a193617abacc417349ae20413112e6fa4e89a9" "7ea20a9eeee64b55d39a2192992a274fc1a836ba3c23a3feebbd" @@ -66,7 +66,7 @@ namespace nix { // values taken from: https://tools.ietf.org/html/rfc4634 auto s = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu"; - auto hash = hashString(HashType::SHA512, s); + auto hash = hashString(HashType::htSHA512, s); ASSERT_EQ(hash.to_string(Base::Base16, true), "sha512:8e959b75dae313da8cf4f72814fc143f8f7779c6eb9f7fa1" "7299aeadb6889018501d289e4900f7e4331b99dec4b5433a" diff --git a/src/libutil/tests/logging.cc b/src/libutil/tests/logging.cc index 2ffcbc41d..4cb54995b 100644 --- a/src/libutil/tests/logging.cc +++ b/src/libutil/tests/logging.cc @@ -68,7 +68,7 @@ namespace nix { TEST(logEI, loggingErrorOnInfoLevel) { testing::internal::CaptureStderr(); - logger->logEI({ .level = Verbosity::Info, + logger->logEI({ .level = lvlInfo, .name = "Info name", .description = "Info description", }); @@ -78,11 +78,11 @@ namespace nix { } TEST(logEI, loggingErrorOnTalkativeLevel) { - verbosity = Verbosity::Talkative; + verbosity = lvlTalkative; testing::internal::CaptureStderr(); - logger->logEI({ .level = Verbosity::Talkative, + logger->logEI({ .level = lvlTalkative, .name = "Talkative name", .description = "Talkative description", }); @@ -92,11 +92,11 @@ namespace nix { } TEST(logEI, loggingErrorOnChattyLevel) { - verbosity = Verbosity::Chatty; + verbosity = lvlChatty; testing::internal::CaptureStderr(); - logger->logEI({ .level = Verbosity::Chatty, + logger->logEI({ .level = lvlChatty, .name = "Chatty name", .description = "Talkative description", }); @@ -106,11 +106,11 @@ namespace nix { } TEST(logEI, loggingErrorOnDebugLevel) { - verbosity = Verbosity::Debug; + verbosity = lvlDebug; testing::internal::CaptureStderr(); - logger->logEI({ .level = Verbosity::Debug, + logger->logEI({ .level = lvlDebug, .name = "Debug name", .description = "Debug description", }); @@ -120,11 +120,11 @@ namespace nix { } TEST(logEI, loggingErrorOnVomitLevel) { - verbosity = Verbosity::Vomit; + verbosity = lvlVomit; testing::internal::CaptureStderr(); - logger->logEI({ .level = Verbosity::Vomit, + logger->logEI({ .level = lvlVomit, .name = "Vomit name", .description = "Vomit description", }); diff --git a/src/libutil/util.cc b/src/libutil/util.cc index e912d4450..1268b146a 100644 --- a/src/libutil/util.cc +++ b/src/libutil/util.cc @@ -442,7 +442,7 @@ void deletePath(const Path & path) void deletePath(const Path & path, unsigned long long & bytesFreed) { - //Activity act(*logger, Verbosity::Debug, format("recursively deleting path '%1%'") % path); + //Activity act(*logger, lvlDebug, format("recursively deleting path '%1%'") % path); bytesFreed = 0; _deletePath(path, bytesFreed); } @@ -1433,7 +1433,7 @@ string base64Decode(std::string_view s) char digit = decode[(unsigned char) c]; if (digit == -1) - throw Error("invalid character in Base::Base64 string"); + throw Error("invalid character in Base64 string"); bits += 6; d = d << 6 | digit; diff --git a/src/nix-copy-closure/nix-copy-closure.cc b/src/nix-copy-closure/nix-copy-closure.cc index 711074e56..b10184718 100755 --- a/src/nix-copy-closure/nix-copy-closure.cc +++ b/src/nix-copy-closure/nix-copy-closure.cc @@ -22,7 +22,7 @@ static int _main(int argc, char ** argv) printVersion("nix-copy-closure"); else if (*arg == "--gzip" || *arg == "--bzip2" || *arg == "--xz") { if (*arg != "--gzip") - printMsg(Verbosity::Error, format("Warning: '%1%' is not implemented, falling back to gzip") % *arg); + printMsg(lvlError, format("Warning: '%1%' is not implemented, falling back to gzip") % *arg); gzip = true; } else if (*arg == "--from") toMode = false; @@ -31,7 +31,7 @@ static int _main(int argc, char ** argv) else if (*arg == "--include-outputs") includeOutputs = true; else if (*arg == "--show-progress") - printMsg(Verbosity::Error, "Warning: '--show-progress' is not implemented"); + printMsg(lvlError, "Warning: '--show-progress' is not implemented"); else if (*arg == "--dry-run") dryRun = true; else if (*arg == "--use-substitutes" || *arg == "-s") diff --git a/src/nix-env/nix-env.cc b/src/nix-env/nix-env.cc index 40f0b7d71..8b0692035 100644 --- a/src/nix-env/nix-env.cc +++ b/src/nix-env/nix-env.cc @@ -976,7 +976,7 @@ static void opQuery(Globals & globals, Strings opFlags, Strings opArgs) try { paths.insert(globals.state->store->parseStorePath(i.queryOutPath())); } catch (AssertionError & e) { - printMsg(Verbosity::Talkative, "skipping derivation named '%s' which gives an assertion failure", i.queryName()); + printMsg(lvlTalkative, "skipping derivation named '%s' which gives an assertion failure", i.queryName()); i.setFailed(); } validPaths = globals.state->store->queryValidPaths(paths); @@ -1002,7 +1002,7 @@ static void opQuery(Globals & globals, Strings opFlags, Strings opArgs) try { if (i.hasFailed()) continue; - //Activity act(*logger, Verbosity::Debug, format("outputting query result '%1%'") % i.attrPath); + //Activity act(*logger, lvlDebug, format("outputting query result '%1%'") % i.attrPath); if (globals.prebuiltOnly && !validPaths.count(globals.state->store->parseStorePath(i.queryOutPath())) && @@ -1183,7 +1183,7 @@ static void opQuery(Globals & globals, Strings opFlags, Strings opArgs) cout.flush(); } catch (AssertionError & e) { - printMsg(Verbosity::Talkative, "skipping derivation named '%1%' which gives an assertion failure", i.queryName()); + printMsg(lvlTalkative, "skipping derivation named '%1%' which gives an assertion failure", i.queryName()); } catch (Error & e) { e.addPrefix(fmt("while querying the derivation named '%1%':\n", i.queryName())); throw; diff --git a/src/nix-prefetch-url/nix-prefetch-url.cc b/src/nix-prefetch-url/nix-prefetch-url.cc index 4f9077d13..40b05a2f3 100644 --- a/src/nix-prefetch-url/nix-prefetch-url.cc +++ b/src/nix-prefetch-url/nix-prefetch-url.cc @@ -51,7 +51,7 @@ string resolveMirrorUri(EvalState & state, string uri) static int _main(int argc, char * * argv) { { - HashType ht = HashType::SHA256; + HashType ht = htSHA256; std::vector args; bool printPath = getEnv("PRINT_PATH") == "1"; bool fromExpr = false; diff --git a/src/nix-store/nix-store.cc b/src/nix-store/nix-store.cc index b821b6c22..4e02aa2bf 100644 --- a/src/nix-store/nix-store.cc +++ b/src/nix-store/nix-store.cc @@ -372,8 +372,8 @@ static void opQuery(Strings opFlags, Strings opArgs) for (auto & j : maybeUseOutputs(store->followLinksToStorePath(i), useOutput, forceRealise)) { auto info = store->queryPathInfo(j); if (query == qHash) { - assert(info->narHash.type == HashType::SHA256); - cout << fmt("%s\n", info->narHash.to_string(Base::Base32, true)); + assert(info->narHash.type == htSHA256); + cout << fmt("%s\n", info->narHash.to_string(Base32, true)); } else if (query == qSize) cout << fmt("%d\n", info->narSize); } @@ -502,7 +502,7 @@ static void registerValidity(bool reregister, bool hashGiven, bool canonicalise) if (canonicalise) canonicalisePathMetaData(store->printStorePath(info->path), -1); if (!hashGiven) { - HashResult hash = hashPath(HashType::SHA256, store->printStorePath(info->path)); + HashResult hash = hashPath(htSHA256, store->printStorePath(info->path)); info->narHash = hash.first; info->narSize = hash.second; } @@ -723,7 +723,7 @@ static void opVerifyPath(Strings opFlags, Strings opArgs) for (auto & i : opArgs) { auto path = store->followLinksToStorePath(i); - printMsg(Verbosity::Talkative, "checking path '%s'...", store->printStorePath(path)); + printMsg(lvlTalkative, "checking path '%s'...", store->printStorePath(path)); auto info = store->queryPathInfo(path); HashSink sink(*info->narHash.type); store->narFromPath(path, sink); @@ -734,8 +734,8 @@ static void opVerifyPath(Strings opFlags, Strings opArgs) .hint = hintfmt( "path '%s' was modified! expected hash '%s', got '%s'", store->printStorePath(path), - info->narHash.to_string(Base::Base32, true), - current.first.to_string(Base::Base32, true)) + info->narHash.to_string(Base32, true), + current.first.to_string(Base32, true)) }); status = 1; } @@ -789,7 +789,7 @@ static void opServe(Strings opFlags, Strings opArgs) auto getBuildSettings = [&]() { // FIXME: changing options here doesn't work if we're // building through the daemon. - verbosity = Verbosity::Error; + verbosity = lvlError; settings.keepLog = false; settings.useSubstitutes = false; settings.maxSilentTime = readInt(in); @@ -864,7 +864,7 @@ static void opServe(Strings opFlags, Strings opArgs) out << info->narSize // downloadSize << info->narSize; if (GET_PROTOCOL_MINOR(clientVersion) >= 4) - out << (info->narHash ? info->narHash.to_string(Base::Base32, true) : "") << info->ca << info->sigs; + out << (info->narHash ? info->narHash.to_string(Base32, true) : "") << info->ca << info->sigs; } catch (InvalidPath &) { } } @@ -948,7 +948,7 @@ static void opServe(Strings opFlags, Strings opArgs) auto deriver = readString(in); if (deriver != "") info.deriver = store->parseStorePath(deriver); - info.narHash = Hash(readString(in), HashType::SHA256); + info.narHash = Hash(readString(in), htSHA256); info.references = readStorePaths(*store, in); in >> info.registrationTime >> info.narSize >> info.ultimate; info.sigs = readStrings(in); 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 From 3fc58a96387f55226ad78a0d8e765a0f041e8da0 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Fri, 19 Jun 2020 00:24:47 +0000 Subject: Remove some `Base::` that crept in --- src/libstore/content-address.cc | 2 +- src/libstore/derivations.cc | 4 ++-- src/libutil/hash.cc | 2 +- src/nix/show-derivation.cc | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/libstore/content-address.cc b/src/libstore/content-address.cc index 5bf51cb97..7de5c0874 100644 --- a/src/libstore/content-address.cc +++ b/src/libstore/content-address.cc @@ -31,7 +31,7 @@ template overloaded(Ts...) -> overloaded; std::string renderContentAddress(ContentAddress ca) { return std::visit(overloaded { [](TextHash th) { - return "text:" + th.hash.to_string(Base::Base32, true); + return "text:" + th.hash.to_string(Base32, true); }, [](FileSystemHash fsh) { return makeFixedOutputCA(fsh.method, fsh.hash); diff --git a/src/libstore/derivations.cc b/src/libstore/derivations.cc index 1ba957c4a..6383e31f4 100644 --- a/src/libstore/derivations.cc +++ b/src/libstore/derivations.cc @@ -267,7 +267,7 @@ string Derivation::unparse(const Store & store, bool maskOutputs, s += ','; printUnquotedString(s, maskOutputs ? "" : store.printStorePath(i.second.path)); s += ','; printUnquotedString(s, i.second.hash ? i.second.hash->printMethodAlgo() : ""); s += ','; printUnquotedString(s, - i.second.hash ? i.second.hash->hash.to_string(Base::Base16, false) : ""); + i.second.hash ? i.second.hash->hash.to_string(Base16, false) : ""); s += ')'; } @@ -467,7 +467,7 @@ void writeDerivation(Sink & out, const Store & store, const BasicDerivation & dr out << i.first << store.printStorePath(i.second.path) << i.second.hash->printMethodAlgo() - << i.second.hash->hash.to_string(Base::Base16, false); + << i.second.hash->hash.to_string(Base16, false); writeStorePaths(store, out, drv.inputSrcs); out << drv.platform << drv.builder << drv.args; out << drv.env.size(); diff --git a/src/libutil/hash.cc b/src/libutil/hash.cc index 7a8d091df..b187249e9 100644 --- a/src/libutil/hash.cc +++ b/src/libutil/hash.cc @@ -223,7 +223,7 @@ Hash newHashAllowEmpty(std::string hashStr, std::optional ht) if (!ht) throw BadHash("empty hash requires explicit hash type"); Hash h(*ht); - warn("found empty hash, assuming '%s'", h.to_string(Base::SRI, true)); + warn("found empty hash, assuming '%s'", h.to_string(SRI, true)); return h; } else return Hash(hashStr, ht); diff --git a/src/nix/show-derivation.cc b/src/nix/show-derivation.cc index 9132c75b1..5d77cfdca 100644 --- a/src/nix/show-derivation.cc +++ b/src/nix/show-derivation.cc @@ -72,7 +72,7 @@ struct CmdShowDerivation : InstallablesCommand outputObj.attr("path", store->printStorePath(output.second.path)); if (output.second.hash) { outputObj.attr("hashAlgo", output.second.hash->printMethodAlgo()); - outputObj.attr("hash", output.second.hash->hash.to_string(Base::Base16, false)); + outputObj.attr("hash", output.second.hash->hash.to_string(Base16, false)); } } } -- cgit v1.2.3 From 237d88c97e1f08f8c1513261ac5fea847d5917ff Mon Sep 17 00:00:00 2001 From: John Ericson Date: Fri, 19 Jun 2020 14:47:10 +0000 Subject: FileSystemHash -> DerivationOutputHash --- src/libexpr/primops.cc | 6 +++--- src/libstore/derivations.cc | 10 +++++----- src/libstore/derivations.hh | 12 ++++++------ src/nix/develop.cc | 2 +- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc index 8288dd6a1..175fccf39 100644 --- a/src/libexpr/primops.cc +++ b/src/libexpr/primops.cc @@ -776,7 +776,7 @@ static void prim_derivationStrict(EvalState & state, const Pos & pos, Value * * if (!jsonObject) drv.env["out"] = state.store->printStorePath(outPath); drv.outputs.insert_or_assign("out", DerivationOutput { .path = std::move(outPath), - .hash = FileSystemHash { ingestionMethod, std::move(h) }, + .hash = DerivationOutputHash { ingestionMethod, std::move(h) }, }); } @@ -792,7 +792,7 @@ static void prim_derivationStrict(EvalState & state, const Pos & pos, Value * * drv.outputs.insert_or_assign(i, DerivationOutput { .path = StorePath::dummy, - .hash = std::optional {}, + .hash = std::optional {}, }); } @@ -804,7 +804,7 @@ static void prim_derivationStrict(EvalState & state, const Pos & pos, Value * * drv.outputs.insert_or_assign(i, DerivationOutput { .path = std::move(outPath), - .hash = std::optional(), + .hash = std::optional(), }); } } diff --git a/src/libstore/derivations.cc b/src/libstore/derivations.cc index 826b336e0..51a01feac 100644 --- a/src/libstore/derivations.cc +++ b/src/libstore/derivations.cc @@ -8,7 +8,7 @@ namespace nix { -std::string FileSystemHash::printMethodAlgo() const { +std::string DerivationOutputHash::printMethodAlgo() const { return makeFileIngestionPrefix(method) + printHashType(hash.type); } @@ -113,7 +113,7 @@ static DerivationOutput parseDerivationOutput(const Store & store, istringstream expect(str, ","); const auto hash = parseString(str); expect(str, ")"); - std::optional fsh; + std::optional fsh; if (hashAlgo != "") { auto method = FileIngestionMethod::Flat; if (string(hashAlgo, 0, 2) == "r:") { @@ -123,7 +123,7 @@ static DerivationOutput parseDerivationOutput(const Store & store, istringstream const HashType hashType = parseHashType(hashAlgo); if (hashType == htUnknown) throw Error("unknown hash hashAlgorithm '%s'", hashAlgo); - fsh = FileSystemHash { + fsh = DerivationOutputHash { std::move(method), Hash(hash, hashType), }; @@ -413,7 +413,7 @@ static DerivationOutput readDerivationOutput(Source & in, const Store & store) auto hashAlgo = readString(in); const auto hash = readString(in); - std::optional fsh; + std::optional fsh; if (hashAlgo != "") { auto method = FileIngestionMethod::Flat; if (string(hashAlgo, 0, 2) == "r:") { @@ -423,7 +423,7 @@ static DerivationOutput readDerivationOutput(Source & in, const Store & store) const HashType hashType = parseHashType(hashAlgo); if (hashType == htUnknown) throw Error("unknown hash hashAlgorithm '%s'", hashAlgo); - fsh = FileSystemHash { + fsh = DerivationOutputHash { std::move(method), Hash(hash, hashType), }; diff --git a/src/libstore/derivations.hh b/src/libstore/derivations.hh index 3b4eb7ec4..f3eff2748 100644 --- a/src/libstore/derivations.hh +++ b/src/libstore/derivations.hh @@ -13,23 +13,23 @@ namespace nix { /* Abstract syntax of derivations. */ /// Pair of a hash, and how the file system was ingested -struct FileSystemHash { +struct DerivationOutputHash { FileIngestionMethod method; Hash hash; - FileSystemHash(FileIngestionMethod method, Hash hash) + DerivationOutputHash(FileIngestionMethod method, Hash hash) : method(std::move(method)) , hash(std::move(hash)) { } - FileSystemHash(const FileSystemHash &) = default; - FileSystemHash(FileSystemHash &&) = default; - FileSystemHash & operator = (const FileSystemHash &) = default; + DerivationOutputHash(const DerivationOutputHash &) = default; + DerivationOutputHash(DerivationOutputHash &&) = default; + DerivationOutputHash & operator = (const DerivationOutputHash &) = default; std::string printMethodAlgo() const; }; struct DerivationOutput { StorePath path; - std::optional hash; /* hash used for expected hash computation */ + std::optional hash; /* hash used for expected hash computation */ void parseHashInfo(FileIngestionMethod & recursive, Hash & hash) const; }; diff --git a/src/nix/develop.cc b/src/nix/develop.cc index 8abb710c2..0845c65fa 100644 --- a/src/nix/develop.cc +++ b/src/nix/develop.cc @@ -137,7 +137,7 @@ StorePath getDerivationEnvironment(ref store, const StorePath & drvPath) auto shellOutPath = store->makeOutputPath("out", h, drvName); drv.outputs.insert_or_assign("out", DerivationOutput { .path = shellOutPath, - .hash = FileSystemHash { + .hash = DerivationOutputHash { FileIngestionMethod::Flat, Hash { } }, }); -- cgit v1.2.3 From 145d88cb2a160871968285fb1898732090f4e14c Mon Sep 17 00:00:00 2001 From: John Ericson Date: Fri, 19 Jun 2020 14:58:30 +0000 Subject: Use designated initializers for `DerivationOutputHash` --- src/libexpr/primops.cc | 5 ++++- src/libstore/derivations.cc | 8 ++++---- src/libstore/derivations.hh | 3 --- src/nix/develop.cc | 3 ++- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc index 175fccf39..bf3c17997 100644 --- a/src/libexpr/primops.cc +++ b/src/libexpr/primops.cc @@ -776,7 +776,10 @@ static void prim_derivationStrict(EvalState & state, const Pos & pos, Value * * if (!jsonObject) drv.env["out"] = state.store->printStorePath(outPath); drv.outputs.insert_or_assign("out", DerivationOutput { .path = std::move(outPath), - .hash = DerivationOutputHash { ingestionMethod, std::move(h) }, + .hash = DerivationOutputHash { + .method = ingestionMethod, + .hash = std::move(h), + }, }); } diff --git a/src/libstore/derivations.cc b/src/libstore/derivations.cc index 51a01feac..528b7ccea 100644 --- a/src/libstore/derivations.cc +++ b/src/libstore/derivations.cc @@ -124,8 +124,8 @@ static DerivationOutput parseDerivationOutput(const Store & store, istringstream if (hashType == htUnknown) throw Error("unknown hash hashAlgorithm '%s'", hashAlgo); fsh = DerivationOutputHash { - std::move(method), - Hash(hash, hashType), + .method = std::move(method), + .hash = Hash(hash, hashType), }; } @@ -424,8 +424,8 @@ static DerivationOutput readDerivationOutput(Source & in, const Store & store) if (hashType == htUnknown) throw Error("unknown hash hashAlgorithm '%s'", hashAlgo); fsh = DerivationOutputHash { - std::move(method), - Hash(hash, hashType), + .method = std::move(method), + .hash = Hash(hash, hashType), }; } diff --git a/src/libstore/derivations.hh b/src/libstore/derivations.hh index f3eff2748..292861065 100644 --- a/src/libstore/derivations.hh +++ b/src/libstore/derivations.hh @@ -20,9 +20,6 @@ struct DerivationOutputHash { : method(std::move(method)) , hash(std::move(hash)) { } - DerivationOutputHash(const DerivationOutputHash &) = default; - DerivationOutputHash(DerivationOutputHash &&) = default; - DerivationOutputHash & operator = (const DerivationOutputHash &) = default; std::string printMethodAlgo() const; }; diff --git a/src/nix/develop.cc b/src/nix/develop.cc index 0845c65fa..8b85caf82 100644 --- a/src/nix/develop.cc +++ b/src/nix/develop.cc @@ -138,7 +138,8 @@ StorePath getDerivationEnvironment(ref store, const StorePath & drvPath) drv.outputs.insert_or_assign("out", DerivationOutput { .path = shellOutPath, .hash = DerivationOutputHash { - FileIngestionMethod::Flat, Hash { } + .method = FileIngestionMethod::Flat, + .hash = Hash { }, }, }); drv.env["out"] = store->printStorePath(shellOutPath); -- cgit v1.2.3 From b90cac3bad41715c2fefc9d725630d0abb9af725 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Fri, 19 Jun 2020 15:00:38 +0000 Subject: Remove uneeded `= default` for Hash --- src/libutil/hash.hh | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/libutil/hash.hh b/src/libutil/hash.hh index 92e10ee6e..180fb7633 100644 --- a/src/libutil/hash.hh +++ b/src/libutil/hash.hh @@ -44,12 +44,6 @@ struct Hash string. */ Hash(std::string_view s, HashType type = htUnknown); - Hash(const Hash &) = default; - - Hash(Hash &&) = default; - - Hash & operator = (const Hash &) = default; - void init(); /* Check whether a hash is set. */ -- cgit v1.2.3 From fb39a5e00c03c8fb3b893263e1d2b151c3ba11aa Mon Sep 17 00:00:00 2001 From: John Ericson Date: Fri, 19 Jun 2020 15:11:11 +0000 Subject: Remove unneeded constructor for `DerivationOutputHash` --- src/libstore/derivations.hh | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/libstore/derivations.hh b/src/libstore/derivations.hh index 292861065..7b677ca49 100644 --- a/src/libstore/derivations.hh +++ b/src/libstore/derivations.hh @@ -16,10 +16,6 @@ namespace nix { struct DerivationOutputHash { FileIngestionMethod method; Hash hash; - DerivationOutputHash(FileIngestionMethod method, Hash hash) - : method(std::move(method)) - , hash(std::move(hash)) - { } std::string printMethodAlgo() const; }; -- cgit v1.2.3 From 911fc88bcb467ff779c5d0ab49e0a5525f284e19 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Fri, 19 Jun 2020 17:42:56 +0000 Subject: More designated initializers --- src/libfetchers/tarball.cc | 4 ++-- src/libstore/build.cc | 5 ++++- src/libstore/content-address.cc | 10 ++++++++-- src/libstore/local-store.cc | 2 +- src/nix/add-to-store.cc | 4 ++-- src/nix/make-content-addressable.cc | 4 ++-- 6 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/libfetchers/tarball.cc b/src/libfetchers/tarball.cc index da8d20d98..f5356f0af 100644 --- a/src/libfetchers/tarball.cc +++ b/src/libfetchers/tarball.cc @@ -71,8 +71,8 @@ DownloadFileResult downloadFile( info.narHash = hashString(htSHA256, *sink.s); info.narSize = sink.s->size(); info.ca = FixedOutputHash { - FileIngestionMethod::Flat, - hash, + .method = FileIngestionMethod::Flat, + .hash = hash, }; auto source = StringSource { *sink.s }; store->addToStore(info, source, NoRepair, NoCheckSigs); diff --git a/src/libstore/build.cc b/src/libstore/build.cc index 1126c186f..0c25897f8 100644 --- a/src/libstore/build.cc +++ b/src/libstore/build.cc @@ -3764,7 +3764,10 @@ void DerivationGoal::registerOutputs() else assert(worker.store.parseStorePath(path) == dest); - ca = FixedOutputHash { i.second.hash->method, h2 }; + ca = FixedOutputHash { + .method = i.second.hash->method, + .hash = h2, + }; } /* Get rid of all weird permissions. This also checks that diff --git a/src/libstore/content-address.cc b/src/libstore/content-address.cc index 98b3677bb..3d753836f 100644 --- a/src/libstore/content-address.cc +++ b/src/libstore/content-address.cc @@ -55,10 +55,16 @@ ContentAddress parseContentAddress(std::string_view rawCa) { auto methodAndHash = rawCa.substr(prefixSeparator+1, string::npos); if (methodAndHash.substr(0,2) == "r:") { std::string_view hashRaw = methodAndHash.substr(2,string::npos); - return FixedOutputHash { FileIngestionMethod::Recursive, Hash(string(hashRaw)) }; + return FixedOutputHash { + .method = FileIngestionMethod::Recursive, + .hash = Hash(string(hashRaw)), + }; } else { std::string_view hashRaw = methodAndHash; - return FixedOutputHash { FileIngestionMethod::Flat, Hash(string(hashRaw)) }; + return FixedOutputHash { + .method = FileIngestionMethod::Flat, + .hash = Hash(string(hashRaw)), + }; } } else { throw Error("parseContentAddress: format not recognized; has to be text or fixed"); diff --git a/src/libstore/local-store.cc b/src/libstore/local-store.cc index f9b2db2e3..0dfbed9fc 100644 --- a/src/libstore/local-store.cc +++ b/src/libstore/local-store.cc @@ -1079,7 +1079,7 @@ StorePath LocalStore::addToStoreFromDump(const string & dump, const string & nam ValidPathInfo info(dstPath); info.narHash = hash.first; info.narSize = hash.second; - info.ca = FixedOutputHash { method, h }; + info.ca = FixedOutputHash { .method = method, .hash = h }; registerValidPath(info); } diff --git a/src/nix/add-to-store.cc b/src/nix/add-to-store.cc index 6d90e93e8..f9d6de16e 100644 --- a/src/nix/add-to-store.cc +++ b/src/nix/add-to-store.cc @@ -49,8 +49,8 @@ struct CmdAddToStore : MixDryRun, StoreCommand info.narHash = narHash; info.narSize = sink.s->size(); info.ca = std::optional { FixedOutputHash { - FileIngestionMethod::Recursive, - info.narHash, + .method = FileIngestionMethod::Recursive, + .hash = info.narHash, } }; if (!dryRun) { diff --git a/src/nix/make-content-addressable.cc b/src/nix/make-content-addressable.cc index c506eabd8..fb36fc410 100644 --- a/src/nix/make-content-addressable.cc +++ b/src/nix/make-content-addressable.cc @@ -83,8 +83,8 @@ struct CmdMakeContentAddressable : StorePathsCommand, MixJSON info.narHash = narHash; info.narSize = sink.s->size(); info.ca = FixedOutputHash { - FileIngestionMethod::Recursive, - info.narHash, + .method = FileIngestionMethod::Recursive, + .hash = info.narHash, }; if (!json) -- cgit v1.2.3 From c1892a53168f629d5baab2313c0066cc4386842d Mon Sep 17 00:00:00 2001 From: John Ericson Date: Fri, 19 Jun 2020 17:49:57 +0000 Subject: tabs -> spaces --- src/libutil/hash.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libutil/hash.cc b/src/libutil/hash.cc index 7a8d091df..e49eb4569 100644 --- a/src/libutil/hash.cc +++ b/src/libutil/hash.cc @@ -368,8 +368,8 @@ string printHashType(HashType ht) case htSHA256: return "sha256"; break; case htSHA512: return "sha512"; break; } - // illegal hash type enum value internally, as opposed to external input - // which should be validated with nice error message. + // illegal hash type enum value internally, as opposed to external input + // which should be validated with nice error message. abort(); } -- cgit v1.2.3 From cdddf24f2503c8b069a72c4d004ebfa80e8fe041 Mon Sep 17 00:00:00 2001 From: Ben Burdette Date: Fri, 19 Jun 2020 14:54:41 -0600 Subject: add hintfmt test --- src/libutil/tests/logging.cc | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/libutil/tests/logging.cc b/src/libutil/tests/logging.cc index 4cb54995b..b24975438 100644 --- a/src/libutil/tests/logging.cc +++ b/src/libutil/tests/logging.cc @@ -1,6 +1,7 @@ #include "logging.hh" #include "nixexpr.hh" #include "util.hh" +#include #include @@ -252,4 +253,21 @@ namespace nix { ASSERT_STREQ(str.c_str(), "\x1B[33;1mwarning:\x1B[0m\x1B[34;1m --- warning name --- error-unit-test\x1B[0m\nin file: \x1B[34;1mmyfile.nix (40:13)\x1B[0m\n\nwarning description\n\n 40| this is the problem line of code\n | \x1B[31;1m^\x1B[0m\n\nthis hint has \x1B[33;1myellow\x1B[0m templated \x1B[33;1mvalues\x1B[0m!!\n"); } + /* ---------------------------------------------------------------------------- + * hintfmt + * --------------------------------------------------------------------------*/ + + TEST(hintfmt, withstandsPercentString) { + + const char *teststr = "this is 100%s correct!"; + auto hint = hintfmt(teststr); + + std::ofstream meh("meh.txt"); + meh << hint.str() << std::endl; + + ASSERT_STREQ(hint.str().c_str(), teststr); + } + + + } -- cgit v1.2.3 From db475f9e7e7a35d7d73d39f06633ce04ac1b67fc Mon Sep 17 00:00:00 2001 From: Ben Burdette Date: Fri, 19 Jun 2020 15:28:13 -0600 Subject: too few, too many args --- src/libutil/tests/logging.cc | 83 +++++++++++++++++++++++++------------------- 1 file changed, 47 insertions(+), 36 deletions(-) diff --git a/src/libutil/tests/logging.cc b/src/libutil/tests/logging.cc index b24975438..e208efc07 100644 --- a/src/libutil/tests/logging.cc +++ b/src/libutil/tests/logging.cc @@ -70,9 +70,9 @@ namespace nix { testing::internal::CaptureStderr(); logger->logEI({ .level = lvlInfo, - .name = "Info name", - .description = "Info description", - }); + .name = "Info name", + .description = "Info description", + }); auto str = testing::internal::GetCapturedStderr(); ASSERT_STREQ(str.c_str(), "\x1B[32;1minfo:\x1B[0m\x1B[34;1m --- Info name --- error-unit-test\x1B[0m\nInfo description\n"); @@ -86,7 +86,7 @@ namespace nix { logger->logEI({ .level = lvlTalkative, .name = "Talkative name", .description = "Talkative description", - }); + }); auto str = testing::internal::GetCapturedStderr(); ASSERT_STREQ(str.c_str(), "\x1B[32;1mtalk:\x1B[0m\x1B[34;1m --- Talkative name --- error-unit-test\x1B[0m\nTalkative description\n"); @@ -100,7 +100,7 @@ namespace nix { logger->logEI({ .level = lvlChatty, .name = "Chatty name", .description = "Talkative description", - }); + }); auto str = testing::internal::GetCapturedStderr(); ASSERT_STREQ(str.c_str(), "\x1B[32;1mchat:\x1B[0m\x1B[34;1m --- Chatty name --- error-unit-test\x1B[0m\nTalkative description\n"); @@ -114,7 +114,7 @@ namespace nix { logger->logEI({ .level = lvlDebug, .name = "Debug name", .description = "Debug description", - }); + }); auto str = testing::internal::GetCapturedStderr(); ASSERT_STREQ(str.c_str(), "\x1B[33;1mdebug:\x1B[0m\x1B[34;1m --- Debug name --- error-unit-test\x1B[0m\nDebug description\n"); @@ -128,7 +128,7 @@ namespace nix { logger->logEI({ .level = lvlVomit, .name = "Vomit name", .description = "Vomit description", - }); + }); auto str = testing::internal::GetCapturedStderr(); ASSERT_STREQ(str.c_str(), "\x1B[32;1mvomit:\x1B[0m\x1B[34;1m --- Vomit name --- error-unit-test\x1B[0m\nVomit description\n"); @@ -145,7 +145,7 @@ namespace nix { logError({ .name = "name", .description = "error description", - }); + }); auto str = testing::internal::GetCapturedStderr(); ASSERT_STREQ(str.c_str(), "\x1B[31;1merror:\x1B[0m\x1B[34;1m --- name --- error-unit-test\x1B[0m\nerror description\n"); @@ -161,13 +161,13 @@ namespace nix { .name = "error name", .description = "error with code lines", .hint = hintfmt("this hint has %1% templated %2%!!", - "yellow", - "values"), + "yellow", + "values"), .nixCode = NixCode { - .errPos = Pos(problem_file, 40, 13), - .prevLineOfCode = "previous line of code", - .errLineOfCode = "this is the problem line of code", - .nextLineOfCode = "next line of code", + .errPos = Pos(problem_file, 40, 13), + .prevLineOfCode = "previous line of code", + .errLineOfCode = "this is the problem line of code", + .nextLineOfCode = "next line of code", }}); @@ -184,10 +184,10 @@ namespace nix { .name = "error name", .description = "error without any code lines.", .hint = hintfmt("this hint has %1% templated %2%!!", - "yellow", - "values"), + "yellow", + "values"), .nixCode = NixCode { - .errPos = Pos(problem_file, 40, 13) + .errPos = Pos(problem_file, 40, 13) }}); auto str = testing::internal::GetCapturedStderr(); @@ -203,7 +203,7 @@ namespace nix { .name = "error name", .hint = hintfmt("hint %1%", "only"), .nixCode = NixCode { - .errPos = Pos(problem_file, 40, 13) + .errPos = Pos(problem_file, 40, 13) }}); auto str = testing::internal::GetCapturedStderr(); @@ -219,10 +219,10 @@ namespace nix { testing::internal::CaptureStderr(); logWarning({ - .name = "name", - .description = "error description", - .hint = hintfmt("there was a %1%", "warning"), - }); + .name = "name", + .description = "error description", + .hint = hintfmt("there was a %1%", "warning"), + }); auto str = testing::internal::GetCapturedStderr(); ASSERT_STREQ(str.c_str(), "\x1B[33;1mwarning:\x1B[0m\x1B[34;1m --- name --- error-unit-test\x1B[0m\nerror description\n\nthere was a \x1B[33;1mwarning\x1B[0m\n"); @@ -239,13 +239,13 @@ namespace nix { .name = "warning name", .description = "warning description", .hint = hintfmt("this hint has %1% templated %2%!!", - "yellow", - "values"), + "yellow", + "values"), .nixCode = NixCode { - .errPos = Pos(problem_file, 40, 13), - .prevLineOfCode = std::nullopt, - .errLineOfCode = "this is the problem line of code", - .nextLineOfCode = std::nullopt + .errPos = Pos(problem_file, 40, 13), + .prevLineOfCode = std::nullopt, + .errLineOfCode = "this is the problem line of code", + .nextLineOfCode = std::nullopt }}); @@ -257,17 +257,28 @@ namespace nix { * hintfmt * --------------------------------------------------------------------------*/ - TEST(hintfmt, withstandsPercentString) { + TEST(hintfmt, percentStringWithoutArgs) { - const char *teststr = "this is 100%s correct!"; - auto hint = hintfmt(teststr); + const char *teststr = "this is 100%s correct!"; + auto hint = hintfmt(teststr); - std::ofstream meh("meh.txt"); - meh << hint.str() << std::endl; + ASSERT_STREQ(hint.str().c_str(), teststr); - ASSERT_STREQ(hint.str().c_str(), teststr); - } + } - + TEST(hintfmt, tooFewArguments) { + ASSERT_STREQ( + hintfmt("only one arg %1% %2%", "fulfilled").str().c_str(), + "only one arg " ANSI_YELLOW "fulfilled" ANSI_NORMAL " "); + + } + + TEST(hintfmt, tooManyArguments) { + + ASSERT_STREQ( + hintfmt("what about this %1% %2%", "%3%", "one", "two").str().c_str(), + "what about this " ANSI_YELLOW "%3%" ANSI_NORMAL " " ANSI_YELLOW "one" ANSI_NORMAL); + + } } -- cgit v1.2.3 From b193aca4ae339fb20184827e28523169d2d5370a Mon Sep 17 00:00:00 2001 From: Ben Burdette Date: Fri, 19 Jun 2020 15:29:19 -0600 Subject: escape percents --- src/libutil/fmt.hh | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/libutil/fmt.hh b/src/libutil/fmt.hh index 12ab9c407..ccab1c512 100644 --- a/src/libutil/fmt.hh +++ b/src/libutil/fmt.hh @@ -1,6 +1,7 @@ #pragma once #include +#include #include #include "ansicolor.hh" @@ -103,7 +104,9 @@ class hintformat public: hintformat(const string &format) :fmt(format) { - fmt.exceptions(boost::io::all_error_bits ^ boost::io::too_many_args_bit); + fmt.exceptions(boost::io::all_error_bits ^ + boost::io::too_many_args_bit ^ + boost::io::too_few_args_bit); } hintformat(const hintformat &hf) @@ -136,4 +139,12 @@ inline hintformat hintfmt(const std::string & fs, const Args & ... args) return f; } +inline hintformat hintfmt(std::string fs) +{ + // we won't be receiving any args in this case, so escape all percents. + boost::replace_all(fs, "%", "%%"); + hintformat f(fs); + formatHelper(f); + return f; +} } -- cgit v1.2.3 From 397dbe114e78682a370832e31269147b9d6ac6fa Mon Sep 17 00:00:00 2001 From: Ben Burdette Date: Fri, 19 Jun 2020 15:57:19 -0600 Subject: remove formathelper --- src/libutil/fmt.hh | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libutil/fmt.hh b/src/libutil/fmt.hh index ccab1c512..789e500ef 100644 --- a/src/libutil/fmt.hh +++ b/src/libutil/fmt.hh @@ -144,7 +144,6 @@ inline hintformat hintfmt(std::string fs) // we won't be receiving any args in this case, so escape all percents. boost::replace_all(fs, "%", "%%"); hintformat f(fs); - formatHelper(f); return f; } } -- cgit v1.2.3 From 0309488a66ffc4e6672772e37bcec2f92019efc0 Mon Sep 17 00:00:00 2001 From: Ben Burdette Date: Fri, 19 Jun 2020 16:46:49 -0600 Subject: fmt -> hintfmt test --- src/libutil/tests/logging.cc | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/libutil/tests/logging.cc b/src/libutil/tests/logging.cc index e208efc07..104f3e02c 100644 --- a/src/libutil/tests/logging.cc +++ b/src/libutil/tests/logging.cc @@ -266,6 +266,14 @@ namespace nix { } + TEST(hintfmt, fmtToHintfmt) { + + auto hint = hintfmt(fmt("the color of this this text is %1%", "not yellow")); + + ASSERT_STREQ(hint.str().c_str(), "the color of this this text is not yellow"); + + } + TEST(hintfmt, tooFewArguments) { ASSERT_STREQ( -- cgit v1.2.3 From be4f444175568fe48fdaf58387820a75bb16aeaa Mon Sep 17 00:00:00 2001 From: Ben Burdette Date: Fri, 19 Jun 2020 16:58:12 -0600 Subject: tidying up --- src/libutil/tests/logging.cc | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/libutil/tests/logging.cc b/src/libutil/tests/logging.cc index 104f3e02c..31e3de697 100644 --- a/src/libutil/tests/logging.cc +++ b/src/libutil/tests/logging.cc @@ -260,17 +260,18 @@ namespace nix { TEST(hintfmt, percentStringWithoutArgs) { const char *teststr = "this is 100%s correct!"; - auto hint = hintfmt(teststr); - ASSERT_STREQ(hint.str().c_str(), teststr); + ASSERT_STREQ( + hintfmt(teststr).str().c_str(), + teststr); } TEST(hintfmt, fmtToHintfmt) { - auto hint = hintfmt(fmt("the color of this this text is %1%", "not yellow")); - - ASSERT_STREQ(hint.str().c_str(), "the color of this this text is not yellow"); + ASSERT_STREQ( + hintfmt(fmt("the color of this this text is %1%", "not yellow")).str().c_str(), + "the color of this this text is not yellow"); } -- cgit v1.2.3 From 28b079067f4248c81b8946c459435c7a91dc2971 Mon Sep 17 00:00:00 2001 From: Ben Burdette Date: Mon, 22 Jun 2020 10:00:37 -0600 Subject: Update src/libutil/fmt.hh Co-authored-by: John Ericson --- src/libutil/fmt.hh | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/libutil/fmt.hh b/src/libutil/fmt.hh index 789e500ef..dc7fe8056 100644 --- a/src/libutil/fmt.hh +++ b/src/libutil/fmt.hh @@ -139,11 +139,9 @@ inline hintformat hintfmt(const std::string & fs, const Args & ... args) return f; } -inline hintformat hintfmt(std::string fs) +inline hintformat hintfmt(std::string plain_string) { - // we won't be receiving any args in this case, so escape all percents. - boost::replace_all(fs, "%", "%%"); - hintformat f(fs); - return f; + // we won't be receiving any args in this case, so just print the original string + return hintfmt("%s", plain_string); } } -- cgit v1.2.3 From 9d1cb0c5e64db3e34896ac43de978f132860f894 Mon Sep 17 00:00:00 2001 From: Ben Burdette Date: Mon, 22 Jun 2020 11:32:20 -0600 Subject: with normaltxt, elide yellow color code instead of canceling it; use normaltxt on plain_string hintfmt --- src/libutil/fmt.hh | 9 ++++++++- src/libutil/tests/logging.cc | 5 ++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/libutil/fmt.hh b/src/libutil/fmt.hh index dc7fe8056..a39de041f 100644 --- a/src/libutil/fmt.hh +++ b/src/libutil/fmt.hh @@ -120,6 +120,13 @@ public: return *this; } + template + hintformat& operator%(const normaltxt &value) + { + fmt % value.value; + return *this; + } + std::string str() const { return fmt.str(); @@ -142,6 +149,6 @@ inline hintformat hintfmt(const std::string & fs, const Args & ... args) inline hintformat hintfmt(std::string plain_string) { // we won't be receiving any args in this case, so just print the original string - return hintfmt("%s", plain_string); + return hintfmt("%s", normaltxt(plain_string)); } } diff --git a/src/libutil/tests/logging.cc b/src/libutil/tests/logging.cc index 31e3de697..6a6fb4ac3 100644 --- a/src/libutil/tests/logging.cc +++ b/src/libutil/tests/logging.cc @@ -43,7 +43,7 @@ namespace nix { logger->logEI(ei); auto str = testing::internal::GetCapturedStderr(); - ASSERT_STREQ(str.c_str(), "\x1B[31;1merror:\x1B[0m\x1B[34;1m --- TestError --- error-unit-test\x1B[0m\n\x1B[33;1m\x1B[0minitial error\x1B[0m; subsequent error message.\n"); + ASSERT_STREQ(str.c_str(), "\x1B[31;1merror:\x1B[0m\x1B[34;1m --- TestError --- error-unit-test\x1B[0m\ninitial error; subsequent error message.\n"); } } @@ -61,8 +61,7 @@ namespace nix { logError(e.info()); auto str = testing::internal::GetCapturedStderr(); - ASSERT_STREQ(str.c_str(), "\x1B[31;1merror:\x1B[0m\x1B[34;1m --- SysError --- error-unit-test\x1B[0m\n\x1B[33;1m\x1B[0mstatting file\x1B[0m: \x1B[33;1mBad file descriptor\x1B[0m\n"); - + ASSERT_STREQ(str.c_str(), "\x1B[31;1merror:\x1B[0m\x1B[34;1m --- SysError --- error-unit-test\x1B[0m\nstatting file: \x1B[33;1mBad file descriptor\x1B[0m\n"); } } -- cgit v1.2.3 From 3685f4eec650be473226b9c1623a28ab07d1f918 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Tue, 23 Jun 2020 22:51:09 +0100 Subject: docs/installer: add correct curl flags also see https://nixos.org/download.html --- doc/manual/installation/installing-binary.xml | 6 +++--- scripts/install-multi-user.sh | 4 ++-- scripts/install-nix-from-closure.sh | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/doc/manual/installation/installing-binary.xml b/doc/manual/installation/installing-binary.xml index d25c46b85..64c7a37fb 100644 --- a/doc/manual/installation/installing-binary.xml +++ b/doc/manual/installation/installing-binary.xml @@ -97,7 +97,7 @@ $ rm -rf /nix installation on your system: - sh <(curl https://nixos.org/nix/install) --daemon + sh <(curl -L https://nixos.org/nix/install) --daemon The multi-user installation of Nix will create build users between @@ -178,7 +178,7 @@ sudo rm /Library/LaunchDaemons/org.nixos.nix-daemon.plist is a bit of a misnomer). To use this approach, just install Nix with: - $ sh <(curl https://nixos.org/nix/install) --darwin-use-unencrypted-nix-store-volume + $ sh <(curl -L https://nixos.org/nix/install) --darwin-use-unencrypted-nix-store-volume If you don't like the sound of this, you'll want to weigh the @@ -429,7 +429,7 @@ LABEL=Nix\040Store /nix apfs rw,nobrowse NixOS.org installation script: - sh <(curl https://nixos.org/nix/install) + sh <(curl -L https://nixos.org/nix/install) diff --git a/scripts/install-multi-user.sh b/scripts/install-multi-user.sh index 157e8ddb4..00c9d540b 100644 --- a/scripts/install-multi-user.sh +++ b/scripts/install-multi-user.sh @@ -526,7 +526,7 @@ This script is going to call sudo a lot. Normally, it would show you exactly what commands it is running and why. However, the script is run in a headless fashion, like this: - $ curl https://nixos.org/nix/install | sh + $ curl -L https://nixos.org/nix/install | sh or maybe in a CI pipeline. Because of that, we're going to skip the verbose output in the interest of brevity. @@ -534,7 +534,7 @@ verbose output in the interest of brevity. If you would like to see the output, try like this: - $ curl -o install-nix https://nixos.org/nix/install + $ curl -L -o install-nix https://nixos.org/nix/install $ sh ./install-nix EOF diff --git a/scripts/install-nix-from-closure.sh b/scripts/install-nix-from-closure.sh index 826ca8b8c..5824c2217 100644 --- a/scripts/install-nix-from-closure.sh +++ b/scripts/install-nix-from-closure.sh @@ -113,7 +113,7 @@ if [ "$(uname -s)" = "Darwin" ]; then ( echo "" echo "Installing on macOS >=10.15 requires relocating the store to an apfs volume." - echo "Use sh <(curl https://nixos.org/nix/install) --darwin-use-unencrypted-nix-store-volume or run the preparation steps manually." + echo "Use sh <(curl -L https://nixos.org/nix/install) --darwin-use-unencrypted-nix-store-volume or run the preparation steps manually." echo "See https://nixos.org/nix/manual/#sect-macos-installation" echo "" ) >&2 -- cgit v1.2.3 From de2641ae99965ecf88e6f72e3969c0c7b7e7020a Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 25 Jun 2020 15:50:30 +0200 Subject: Fix empty std::optional dereference in writeDerivation() https://hydra.nixos.org/build/123017579 --- src/libstore/derivations.cc | 17 +++++++++++------ src/libutil/hash.cc | 27 ++++++++++++++------------- src/libutil/hash.hh | 2 +- 3 files changed, 26 insertions(+), 20 deletions(-) diff --git a/src/libstore/derivations.cc b/src/libstore/derivations.cc index 6c49075ba..42551ef6b 100644 --- a/src/libstore/derivations.cc +++ b/src/libstore/derivations.cc @@ -404,7 +404,7 @@ static DerivationOutput readDerivationOutput(Source & in, const Store & store) { auto path = store.parseStorePath(readString(in)); auto hashAlgo = readString(in); - const auto hash = readString(in); + auto hash = readString(in); std::optional fsh; if (hashAlgo != "") { @@ -413,7 +413,7 @@ static DerivationOutput readDerivationOutput(Source & in, const Store & store) method = FileIngestionMethod::Recursive; hashAlgo = string(hashAlgo, 2); } - const HashType hashType = parseHashType(hashAlgo); + auto hashType = parseHashType(hashAlgo); fsh = FixedOutputHash { .method = std::move(method), .hash = Hash(hash, hashType), @@ -463,11 +463,16 @@ Source & readDerivation(Source & in, const Store & store, BasicDerivation & drv) void writeDerivation(Sink & out, const Store & store, const BasicDerivation & drv) { out << drv.outputs.size(); - for (auto & i : drv.outputs) + for (auto & i : drv.outputs) { out << i.first - << store.printStorePath(i.second.path) - << i.second.hash->printMethodAlgo() - << i.second.hash->hash.to_string(Base16, false); + << store.printStorePath(i.second.path); + if (i.second.hash) { + out << i.second.hash->printMethodAlgo() + << i.second.hash->hash.to_string(Base16, false); + } else { + out << "" << ""; + } + } writeStorePaths(store, out, drv.inputSrcs); out << drv.platform << drv.builder << drv.args; out << drv.env.size(); diff --git a/src/libutil/hash.cc b/src/libutil/hash.cc index c8fcdfed0..01fae3044 100644 --- a/src/libutil/hash.cc +++ b/src/libutil/hash.cc @@ -19,7 +19,7 @@ namespace nix { void Hash::init() { - if (!type) abort(); + assert(type); switch (*type) { case htMD5: hashSize = md5HashSize; break; case htSHA1: hashSize = sha1HashSize; break; @@ -101,15 +101,15 @@ static string printHash32(const Hash & hash) string printHash16or32(const Hash & hash) { + assert(hash.type); return hash.to_string(hash.type == htMD5 ? Base16 : Base32, false); } -HashType assertInitHashType(const Hash & h) { - if (h.type) - return *h.type; - else - abort(); +HashType assertInitHashType(const Hash & h) +{ + assert(h.type); + return *h.type; } std::string Hash::to_string(Base base, bool includeType) const @@ -363,14 +363,15 @@ HashType parseHashType(const string & s) string printHashType(HashType ht) { switch (ht) { - case htMD5: return "md5"; break; - case htSHA1: return "sha1"; break; - case htSHA256: return "sha256"; break; - case htSHA512: return "sha512"; break; + case htMD5: return "md5"; + case htSHA1: return "sha1"; + case htSHA256: return "sha256"; + case htSHA512: return "sha512"; + default: + // illegal hash type enum value internally, as opposed to external input + // which should be validated with nice error message. + abort(); } - // illegal hash type enum value internally, as opposed to external input - // which should be validated with nice error message. - abort(); } } diff --git a/src/libutil/hash.hh b/src/libutil/hash.hh index 0d9916508..23259dced 100644 --- a/src/libutil/hash.hh +++ b/src/libutil/hash.hh @@ -10,7 +10,7 @@ namespace nix { MakeError(BadHash, Error); -enum HashType : char { htMD5, htSHA1, htSHA256, htSHA512 }; +enum HashType : char { htMD5 = 42, htSHA1, htSHA256, htSHA512 }; const int md5HashSize = 16; -- cgit v1.2.3 From b7ccf7ae2af3d7eaf3696358ecbbce5a2bcfe652 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 25 Jun 2020 18:26:34 +0200 Subject: build-remote.sh: Test LegacySSHStore --- tests/build-hook.nix | 32 ++++++++++++++++++++++++-------- tests/build-remote.sh | 33 ++++++++++++++++++++------------- tests/common.sh.in | 1 + tests/post-hook.sh | 2 ++ tests/recursive.sh | 2 ++ tests/structured-attrs.sh | 2 ++ 6 files changed, 51 insertions(+), 21 deletions(-) diff --git a/tests/build-hook.nix b/tests/build-hook.nix index 8c5ca8cd3..a19c10dde 100644 --- a/tests/build-hook.nix +++ b/tests/build-hook.nix @@ -1,23 +1,39 @@ +{ busybox }: + with import ./config.nix; let + mkDerivation = args: + derivation ({ + inherit system; + builder = busybox; + args = ["sh" "-e" args.builder or (builtins.toFile "builder-${args.name}.sh" "if [ -e .attrs.sh ]; then source .attrs.sh; fi; eval \"$buildCommand\"")]; + } // removeAttrs args ["builder" "meta"]) + // { meta = args.meta or {}; }; + input1 = mkDerivation { - name = "build-hook-input-1"; - buildCommand = "mkdir $out; echo FOO > $out/foo"; + shell = busybox; + name = "build-remote-input-1"; + buildCommand = "echo FOO > $out"; requiredSystemFeatures = ["foo"]; }; input2 = mkDerivation { - name = "build-hook-input-2"; - buildCommand = "mkdir $out; echo BAR > $out/bar"; + shell = busybox; + name = "build-remote-input-2"; + buildCommand = "echo BAR > $out"; }; in mkDerivation { - name = "build-hook"; - builder = ./dependencies.builder0.sh; - input1 = " " + input1 + "/."; - input2 = " ${input2}/."; + shell = busybox; + name = "build-remote"; + buildCommand = + '' + read x < ${input1} + read y < ${input2} + echo $x$y > $out + ''; } diff --git a/tests/build-remote.sh b/tests/build-remote.sh index a550f4460..4dfb753e1 100644 --- a/tests/build-remote.sh +++ b/tests/build-remote.sh @@ -3,22 +3,29 @@ source common.sh clearStore if ! canUseSandbox; then exit; fi -if [[ ! $SHELL =~ /nix/store ]]; then exit; fi +if ! [[ $busybox =~ busybox ]]; then exit; fi -chmod -R u+w $TEST_ROOT/store0 || true -chmod -R u+w $TEST_ROOT/store1 || true -rm -rf $TEST_ROOT/store0 $TEST_ROOT/store1 +chmod -R u+w $TEST_ROOT/machine0 || true +chmod -R u+w $TEST_ROOT/machine1 || true +chmod -R u+w $TEST_ROOT/machine2 || true +rm -rf $TEST_ROOT/machine0 $TEST_ROOT/machine1 $TEST_ROOT/machine2 +rm -f $TEST_ROOT/result -nix build -f build-hook.nix -o $TEST_ROOT/result --max-jobs 0 \ - --sandbox-paths /nix/store --sandbox-build-dir /build-tmp \ - --builders "$TEST_ROOT/store0; $TEST_ROOT/store1 - - 1 1 foo" \ +unset NIX_STORE_DIR +unset NIX_STATE_DIR + +# Note: ssh://localhost bypasses ssh, directly invoking nix-store as a +# child process. This allows us to test LegacySSHStore::buildDerivation(). +nix build -L -v -f build-hook.nix -o $TEST_ROOT/result --max-jobs 0 \ + --arg busybox $busybox \ + --store $TEST_ROOT/machine0 \ + --builders "ssh://localhost?remote-store=$TEST_ROOT/machine1; $TEST_ROOT/machine2 - - 1 1 foo" \ --system-features foo -outPath=$TEST_ROOT/result +outPath=$(readlink -f $TEST_ROOT/result) -cat $outPath/foobar | grep FOOBAR +cat $TEST_ROOT/machine0/$outPath | grep FOOBAR -# Ensure that input1 was built on store1 due to the required feature. -p=$(readlink -f $outPath/input-2) -(! nix path-info --store $TEST_ROOT/store0 --all | grep builder-build-hook-input-1.sh) -nix path-info --store $TEST_ROOT/store1 --all | grep builder-build-hook-input-1.sh +# Ensure that input1 was built on store2 due to the required feature. +(! nix path-info --store $TEST_ROOT/machine1 --all | grep builder-build-remote-input-1.sh) +nix path-info --store $TEST_ROOT/machine2 --all | grep builder-build-remote-input-1.sh diff --git a/tests/common.sh.in b/tests/common.sh.in index dd7e61822..73fe77345 100644 --- a/tests/common.sh.in +++ b/tests/common.sh.in @@ -35,6 +35,7 @@ export xmllint="@xmllint@" export SHELL="@bash@" export PAGER=cat export HAVE_SODIUM="@HAVE_SODIUM@" +export busybox="@sandbox_shell@" export version=@PACKAGE_VERSION@ export system=@system@ diff --git a/tests/post-hook.sh b/tests/post-hook.sh index a02657215..aa3e6a574 100644 --- a/tests/post-hook.sh +++ b/tests/post-hook.sh @@ -2,6 +2,8 @@ source common.sh clearStore +rm -f $TEST_ROOT/result + export REMOTE_STORE=$TEST_ROOT/remote_store # Build the dependencies and push them to the remote store diff --git a/tests/recursive.sh b/tests/recursive.sh index 394ae5ddb..2d4f83895 100644 --- a/tests/recursive.sh +++ b/tests/recursive.sh @@ -5,6 +5,8 @@ if [[ $(uname) != Linux ]]; then exit; fi clearStore +rm -f $TEST_ROOT/result + export unreachable=$(nix add-to-store ./recursive.sh) nix --experimental-features 'nix-command recursive-nix' build -o $TEST_ROOT/result -L '( diff --git a/tests/structured-attrs.sh b/tests/structured-attrs.sh index 646bdb876..dcfe6d580 100644 --- a/tests/structured-attrs.sh +++ b/tests/structured-attrs.sh @@ -2,6 +2,8 @@ source common.sh clearStore +rm -f $TEST_ROOT/result + nix-build structured-attrs.nix -A all -o $TEST_ROOT/result [[ $(cat $TEST_ROOT/result/foo) = bar ]] -- cgit v1.2.3