diff options
author | Vincent Ambo <tazjin@google.com> | 2020-05-25T00·19+0100 |
---|---|---|
committer | Vincent Ambo <tazjin@google.com> | 2020-05-25T00·19+0100 |
commit | 98299da0fda612b42ab933c47f18163cfef5fa71 (patch) | |
tree | 78fc0f1127b5f2336d3e370f342f72f38d5a5ee2 /third_party/nix/src/libstore/binary-cache-store.cc | |
parent | b371821db59d33851d521d66ba1fb126d388c00f (diff) |
refactor(3p/nix/libutil): Replace string2Int & trim functions r/843
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.
Diffstat (limited to 'third_party/nix/src/libstore/binary-cache-store.cc')
-rw-r--r-- | third_party/nix/src/libstore/binary-cache-store.cc | 13 |
1 files changed, 10 insertions, 3 deletions
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 <future> #include <memory> +#include <absl/strings/ascii.h> +#include <absl/strings/numbers.h> + #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<SecretKey>(readFile(secretKeyFile)); + const std::string& secret_key_file = secretKeyFile; + secretKey = std::make_unique<SecretKey>(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; + } } } } |