From 98299da0fda612b42ab933c47f18163cfef5fa71 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Mon, 25 May 2020 01:19:02 +0100 Subject: refactor(3p/nix/libutil): Replace string2Int & trim functions Replaces these functions with corresponding functions from Abseil, namely absl::StripAsciiWhitespace and absl::SimpleAtoi. In the course of doing this some minor things I encountered along the way were also refactored. This also changes the signatures of the various custom readFile functions to use absl::string_view types. --- third_party/nix/src/libstore/binary-cache-store.cc | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'third_party/nix/src/libstore/binary-cache-store.cc') diff --git a/third_party/nix/src/libstore/binary-cache-store.cc b/third_party/nix/src/libstore/binary-cache-store.cc index 37d1c1a440a2..ea36078435ba 100644 --- a/third_party/nix/src/libstore/binary-cache-store.cc +++ b/third_party/nix/src/libstore/binary-cache-store.cc @@ -4,6 +4,9 @@ #include #include +#include +#include + #include "archive.hh" #include "compression.hh" #include "derivations.hh" @@ -21,7 +24,8 @@ namespace nix { BinaryCacheStore::BinaryCacheStore(const Params& params) : Store(params) { if (secretKeyFile != "") { - secretKey = std::make_unique(readFile(secretKeyFile)); + const std::string& secret_key_file = secretKeyFile; + secretKey = std::make_unique(readFile(secret_key_file)); } StringSink sink; @@ -43,7 +47,8 @@ void BinaryCacheStore::init() { continue; } auto name = line.substr(0, colon); - auto value = trim(line.substr(colon + 1, std::string::npos)); + auto value = + absl::StripAsciiWhitespace(line.substr(colon + 1, std::string::npos)); if (name == "StoreDir") { if (value != storeDir) { throw Error(format("binary cache '%s' is for Nix stores with prefix " @@ -53,7 +58,9 @@ void BinaryCacheStore::init() { } else if (name == "WantMassQuery") { wantMassQuery_ = value == "1"; } else if (name == "Priority") { - string2Int(value, priority); + if (!absl::SimpleAtoi(value, &priority)) { + LOG(WARNING) << "Invalid 'Priority' value: " << value; + } } } } -- cgit 1.4.1