about summary refs log tree commit diff
path: root/third_party/nix/src/libstore
diff options
context:
space:
mode:
authorVincent Ambo <tazjin@google.com>2020-05-25T01·19+0100
committerVincent Ambo <tazjin@google.com>2020-05-25T01·19+0100
commitb99b368d17f2e806a61f7abb83c6d3a9e4bbdc38 (patch)
tree1f76047dd027421dcf79cdf4804fa5ff1bb08b2b /third_party/nix/src/libstore
parent8cf1322a6fd5ae282d8a09fdba634f27a1a88560 (diff)
refactor(3p/nix/libutil): Replace hasPrefix/Suffix with Abseil r/845
Uses the equivalent absl::StartsWith and absl::EndsWith functions
instead.
Diffstat (limited to 'third_party/nix/src/libstore')
-rw-r--r--third_party/nix/src/libstore/builtins/buildenv.cc9
-rw-r--r--third_party/nix/src/libstore/builtins/fetchurl.cc5
-rw-r--r--third_party/nix/src/libstore/derivations.cc4
-rw-r--r--third_party/nix/src/libstore/download.cc7
-rw-r--r--third_party/nix/src/libstore/gc.cc3
-rw-r--r--third_party/nix/src/libstore/local-binary-cache-store.cc4
-rw-r--r--third_party/nix/src/libstore/machines.cc8
-rw-r--r--third_party/nix/src/libstore/s3-binary-cache-store.cc9
-rw-r--r--third_party/nix/src/libstore/ssh.cc4
-rw-r--r--third_party/nix/src/libstore/store-api.cc9
10 files changed, 38 insertions, 24 deletions
diff --git a/third_party/nix/src/libstore/builtins/buildenv.cc b/third_party/nix/src/libstore/builtins/buildenv.cc
index d14474a93d..92cf2f8c1e 100644
--- a/third_party/nix/src/libstore/builtins/buildenv.cc
+++ b/third_party/nix/src/libstore/builtins/buildenv.cc
@@ -1,5 +1,6 @@
 #include <algorithm>
 
+#include <absl/strings/match.h>
 #include <fcntl.h>
 #include <glog/logging.h>
 #include <sys/stat.h>
@@ -56,10 +57,10 @@ static void createLinks(const Path& srcDir, const Path& dstDir, int priority) {
      * Python package brings its own
      * `$out/lib/pythonX.Y/site-packages/easy-install.pth'.)
      */
-    if (hasSuffix(srcFile, "/propagated-build-inputs") ||
-        hasSuffix(srcFile, "/nix-support") ||
-        hasSuffix(srcFile, "/perllocal.pod") ||
-        hasSuffix(srcFile, "/info/dir") || hasSuffix(srcFile, "/log"))
+    if (absl::EndsWith(srcFile, "/propagated-build-inputs") ||
+        absl::EndsWith(srcFile, "/nix-support") ||
+        absl::EndsWith(srcFile, "/perllocal.pod") ||
+        absl::EndsWith(srcFile, "/info/dir") || absl::EndsWith(srcFile, "/log"))
       continue;
 
     else if (S_ISDIR(srcSt.st_mode)) {
diff --git a/third_party/nix/src/libstore/builtins/fetchurl.cc b/third_party/nix/src/libstore/builtins/fetchurl.cc
index 97260d2e52..90814f6d7f 100644
--- a/third_party/nix/src/libstore/builtins/fetchurl.cc
+++ b/third_party/nix/src/libstore/builtins/fetchurl.cc
@@ -1,3 +1,4 @@
+#include <absl/strings/match.h>
 #include <glog/logging.h>
 
 #include "archive.hh"
@@ -41,7 +42,7 @@ void builtinFetchurl(const BasicDerivation& drv, const std::string& netrcData) {
       request.decompress = false;
 
       auto decompressor = makeDecompressionSink(
-          unpack && hasSuffix(mainUrl, ".xz") ? "xz" : "none", sink);
+          unpack && absl::EndsWith(mainUrl, ".xz") ? "xz" : "none", sink);
       downloader->download(std::move(request), *decompressor);
       decompressor->finish();
     });
@@ -61,7 +62,7 @@ void builtinFetchurl(const BasicDerivation& drv, const std::string& netrcData) {
   /* Try the hashed mirrors first. */
   if (getAttr("outputHashMode") == "flat")
     for (auto hashedMirror : settings.hashedMirrors.get()) try {
-        if (!hasSuffix(hashedMirror, "/")) {
+        if (!absl::EndsWith(hashedMirror, "/")) {
           hashedMirror += '/';
         }
         auto ht = parseHashType(getAttr("outputHashAlgo"));
diff --git a/third_party/nix/src/libstore/derivations.cc b/third_party/nix/src/libstore/derivations.cc
index f8770327bf..9f2aa5ea92 100644
--- a/third_party/nix/src/libstore/derivations.cc
+++ b/third_party/nix/src/libstore/derivations.cc
@@ -1,5 +1,7 @@
 #include "derivations.hh"
 
+#include <absl/strings/match.h>
+
 #include "fs-accessor.hh"
 #include "globals.hh"
 #include "istringstream_nocopy.hh"
@@ -299,7 +301,7 @@ std::string Derivation::unparse() const {
 }
 
 bool isDerivation(const std::string& fileName) {
-  return hasSuffix(fileName, drvExtension);
+  return absl::EndsWith(fileName, drvExtension);
 }
 
 bool BasicDerivation::isFixedOutput() const {
diff --git a/third_party/nix/src/libstore/download.cc b/third_party/nix/src/libstore/download.cc
index bebe0d1bf8..8b36063dab 100644
--- a/third_party/nix/src/libstore/download.cc
+++ b/third_party/nix/src/libstore/download.cc
@@ -1,6 +1,7 @@
 #include "download.hh"
 
 #include <absl/strings/ascii.h>
+#include <absl/strings/match.h>
 #include <absl/strings/numbers.h>
 
 #include "archive.hh"
@@ -653,8 +654,8 @@ struct CurlDownloader : public Downloader {
   }
 
   void enqueueItem(const std::shared_ptr<DownloadItem>& item) {
-    if (item->request.data && !hasPrefix(item->request.uri, "http://") &&
-        !hasPrefix(item->request.uri, "https://")) {
+    if (item->request.data && !absl::StartsWith(item->request.uri, "http://") &&
+        !absl::StartsWith(item->request.uri, "https://")) {
       throw nix::Error("uploading to '%s' is not supported", item->request.uri);
     }
 
@@ -690,7 +691,7 @@ struct CurlDownloader : public Downloader {
   void enqueueDownload(const DownloadRequest& request,
                        Callback<DownloadResult> callback) override {
     /* Ugly hack to support s3:// URIs. */
-    if (hasPrefix(request.uri, "s3://")) {
+    if (absl::StartsWith(request.uri, "s3://")) {
       // FIXME: do this on a worker thread
       try {
 #ifdef ENABLE_S3
diff --git a/third_party/nix/src/libstore/gc.cc b/third_party/nix/src/libstore/gc.cc
index 1b2364c253..262f17df03 100644
--- a/third_party/nix/src/libstore/gc.cc
+++ b/third_party/nix/src/libstore/gc.cc
@@ -6,6 +6,7 @@
 #include <random>
 #include <regex>
 
+#include <absl/strings/match.h>
 #include <fcntl.h>
 #include <sys/stat.h>
 #include <sys/statvfs.h>
@@ -512,7 +513,7 @@ struct LocalStore::GCState {
 
 bool LocalStore::isActiveTempFile(const GCState& state, const Path& path,
                                   const std::string& suffix) {
-  return hasSuffix(path, suffix) &&
+  return absl::EndsWith(path, suffix) &&
          state.tempRoots.find(std::string(
              path, 0, path.size() - suffix.size())) != state.tempRoots.end();
 }
diff --git a/third_party/nix/src/libstore/local-binary-cache-store.cc b/third_party/nix/src/libstore/local-binary-cache-store.cc
index 00bb21eb24..88dd19a320 100644
--- a/third_party/nix/src/libstore/local-binary-cache-store.cc
+++ b/third_party/nix/src/libstore/local-binary-cache-store.cc
@@ -1,5 +1,7 @@
 #include <utility>
 
+#include <absl/strings/match.h>
+
 #include "binary-cache-store.hh"
 #include "globals.hh"
 #include "nar-info-disk-cache.hh"
@@ -39,7 +41,7 @@ class LocalBinaryCacheStore : public BinaryCacheStore {
     PathSet paths;
 
     for (auto& entry : readDirectory(binaryCacheDir)) {
-      if (entry.name.size() != 40 || !hasSuffix(entry.name, ".narinfo")) {
+      if (entry.name.size() != 40 || !absl::EndsWith(entry.name, ".narinfo")) {
         continue;
       }
       paths.insert(storeDir + "/" +
diff --git a/third_party/nix/src/libstore/machines.cc b/third_party/nix/src/libstore/machines.cc
index 6472e037d1..bbb84784c4 100644
--- a/third_party/nix/src/libstore/machines.cc
+++ b/third_party/nix/src/libstore/machines.cc
@@ -3,6 +3,7 @@
 #include <algorithm>
 
 #include <absl/strings/ascii.h>
+#include <absl/strings/match.h>
 #include <absl/strings/string_view.h>
 #include <glog/logging.h>
 
@@ -21,9 +22,10 @@ Machine::Machine(decltype(storeUri)& storeUri,
           // Backwards compatibility: if the URI is a hostname,
           // prepend ssh://.
           storeUri.find("://") != std::string::npos ||
-                  hasPrefix(storeUri, "local") ||
-                  hasPrefix(storeUri, "remote") ||
-                  hasPrefix(storeUri, "auto") || hasPrefix(storeUri, "/")
+                  absl::StartsWith(storeUri, "local") ||
+                  absl::StartsWith(storeUri, "remote") ||
+                  absl::StartsWith(storeUri, "auto") ||
+                  absl::StartsWith(storeUri, "/")
               ? storeUri
               : "ssh://" + storeUri),
       systemTypes(systemTypes),
diff --git a/third_party/nix/src/libstore/s3-binary-cache-store.cc b/third_party/nix/src/libstore/s3-binary-cache-store.cc
index 2b25fd8744..d713c5ce01 100644
--- a/third_party/nix/src/libstore/s3-binary-cache-store.cc
+++ b/third_party/nix/src/libstore/s3-binary-cache-store.cc
@@ -3,6 +3,7 @@
 #include "s3-binary-cache-store.hh"
 
 #include <absl/strings/ascii.h>
+#include <absl/strings/match.h>
 #include <aws/core/Aws.h>
 #include <aws/core/VersionConfig.h>
 #include <aws/core/auth/AWSCredentialsProvider.h>
@@ -347,12 +348,12 @@ struct S3BinaryCacheStoreImpl : public S3BinaryCacheStore {
 
   void upsertFile(const std::string& path, const std::string& data,
                   const std::string& mimeType) override {
-    if (narinfoCompression != "" && hasSuffix(path, ".narinfo"))
+    if (narinfoCompression != "" && absl::EndsWith(path, ".narinfo"))
       uploadFile(path, *compress(narinfoCompression, data), mimeType,
                  narinfoCompression);
-    else if (lsCompression != "" && hasSuffix(path, ".ls"))
+    else if (lsCompression != "" && absl::EndsWith(path, ".ls"))
       uploadFile(path, *compress(lsCompression, data), mimeType, lsCompression);
-    else if (logCompression != "" && hasPrefix(path, "log/"))
+    else if (logCompression != "" && absl::StartsWith(path, "log/"))
       uploadFile(path, *compress(logCompression, data), mimeType,
                  logCompression);
     else
@@ -400,7 +401,7 @@ struct S3BinaryCacheStoreImpl : public S3BinaryCacheStore {
 
       for (auto object : contents) {
         auto& key = object.GetKey();
-        if (key.size() != 40 || !hasSuffix(key, ".narinfo")) {
+        if (key.size() != 40 || !absl::EndsWith(key, ".narinfo")) {
           continue;
         }
         paths.insert(storeDir + "/" + key.substr(0, key.size() - 8));
diff --git a/third_party/nix/src/libstore/ssh.cc b/third_party/nix/src/libstore/ssh.cc
index 06aaf285f1..76c78b2fcd 100644
--- a/third_party/nix/src/libstore/ssh.cc
+++ b/third_party/nix/src/libstore/ssh.cc
@@ -2,6 +2,8 @@
 
 #include <utility>
 
+#include <absl/strings/match.h>
+
 namespace nix {
 
 SSHMaster::SSHMaster(const std::string& host, std::string keyFile,
@@ -12,7 +14,7 @@ SSHMaster::SSHMaster(const std::string& host, std::string keyFile,
       useMaster(useMaster && !fakeSSH),
       compress(compress),
       logFD(logFD) {
-  if (host.empty() || hasPrefix(host, "-")) {
+  if (host.empty() || absl::StartsWith(host, "-")) {
     throw Error("invalid SSH host name '%s'", host);
   }
 }
diff --git a/third_party/nix/src/libstore/store-api.cc b/third_party/nix/src/libstore/store-api.cc
index 54214e6f4e..9440d78d5f 100644
--- a/third_party/nix/src/libstore/store-api.cc
+++ b/third_party/nix/src/libstore/store-api.cc
@@ -3,6 +3,7 @@
 #include <future>
 #include <utility>
 
+#include <absl/strings/match.h>
 #include <absl/strings/numbers.h>
 #include <glog/logging.h>
 
@@ -771,7 +772,7 @@ bool ValidPathInfo::isContentAddressed(const Store& store) const {
                << "' claims to be content-addressed but isn't";
   };
 
-  if (hasPrefix(ca, "text:")) {
+  if (absl::StartsWith(ca, "text:")) {
     Hash hash(std::string(ca, 5));
     if (store.makeTextPath(storePathToName(path), hash, references) == path) {
       return true;
@@ -780,7 +781,7 @@ bool ValidPathInfo::isContentAddressed(const Store& store) const {
 
   }
 
-  else if (hasPrefix(ca, "fixed:")) {
+  else if (absl::StartsWith(ca, "fixed:")) {
     bool recursive = ca.compare(6, 2, "r:") == 0;
     Hash hash(std::string(ca, recursive ? 8 : 6));
     if (references.empty() &&
@@ -906,7 +907,7 @@ StoreType getStoreType(const std::string& uri, const std::string& stateDir) {
   if (uri == "daemon") {
     return tDaemon;
   }
-  if (uri == "local" || hasPrefix(uri, "/")) {
+  if (uri == "local" || absl::StartsWith(uri, "/")) {
     return tLocal;
   } else if (uri.empty() || uri == "auto") {
     if (access(stateDir.c_str(), R_OK | W_OK) == 0) {
@@ -930,7 +931,7 @@ static RegisterStoreImplementation regStore([](const std::string& uri,
       return std::shared_ptr<Store>(std::make_shared<UDSRemoteStore>(params));
     case tLocal: {
       Store::Params params2 = params;
-      if (hasPrefix(uri, "/")) {
+      if (absl::StartsWith(uri, "/")) {
         params2["root"] = uri;
       }
       return std::shared_ptr<Store>(std::make_shared<LocalStore>(params2));