From 25e61812f341a4467ab4fdffb12f63b48a3d0272 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Tue, 2 Jun 2020 12:47:18 -0400 Subject: [PATCH] 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)));