about summary refs log tree commit diff
path: root/third_party/nix/src/libstore
diff options
context:
space:
mode:
authorKane York <kanepyork@gmail.com>2020-08-06T08·28-0700
committerkanepyork <rikingcoding@gmail.com>2020-08-06T20·50+0000
commita5dae62e85d9ff9db6c4088d64559d7bac713486 (patch)
treee551ce79399e51dba895f95b8077c877cd94942a /third_party/nix/src/libstore
parent6a97206cebf17f15b5cfede556bcb3c259ce5154 (diff)
fix(3p/nix): Use SkipEmpty in all calls to absl::StrSplit r/1613
The behavior to return a list containing a single empty string when
provided an empty string is a behavior that absl inherited from legacy
code. However, the behavior expected by legacy code in Nix is the
behavior provided by the SkipEmpty option. Switch all calls to use
SkipEmpty, except for the call already using SkipWhitespace.

See also commit 26a59482d2427f640893517f1b24dd650a5bd5da, with the
partly-prophetic message: "there may be other places we need to
fix this as well."

Change-Id: I6e94856a12cfb1b7e4a3b4e221769ed446648861
Reviewed-on: https://cl.tvl.fyi/c/depot/+/1687
Tested-by: BuildkiteCI
Reviewed-by: glittershark <grfn@gws.fyi>
Diffstat (limited to 'third_party/nix/src/libstore')
-rw-r--r--third_party/nix/src/libstore/binary-cache-store.cc3
-rw-r--r--third_party/nix/src/libstore/build.cc3
-rw-r--r--third_party/nix/src/libstore/builtins/buildenv.cc6
-rw-r--r--third_party/nix/src/libstore/derivations.cc3
-rw-r--r--third_party/nix/src/libstore/download.cc7
-rw-r--r--third_party/nix/src/libstore/gc.cc4
-rw-r--r--third_party/nix/src/libstore/globals.cc6
-rw-r--r--third_party/nix/src/libstore/local-store.cc8
-rw-r--r--third_party/nix/src/libstore/local-store.hh4
-rw-r--r--third_party/nix/src/libstore/machines.cc20
-rw-r--r--third_party/nix/src/libstore/nar-info-disk-cache.cc7
-rw-r--r--third_party/nix/src/libstore/nar-info.cc3
-rw-r--r--third_party/nix/src/libstore/parsed-derivations.cc3
-rw-r--r--third_party/nix/src/libstore/ssh.cc3
-rw-r--r--third_party/nix/src/libstore/store-api.cc3
15 files changed, 48 insertions, 35 deletions
diff --git a/third_party/nix/src/libstore/binary-cache-store.cc b/third_party/nix/src/libstore/binary-cache-store.cc
index b862ea0058..fce4dc0e11 100644
--- a/third_party/nix/src/libstore/binary-cache-store.cc
+++ b/third_party/nix/src/libstore/binary-cache-store.cc
@@ -42,7 +42,8 @@ void BinaryCacheStore::init() {
     upsertFile(cacheInfoFile, "StoreDir: " + storeDir + "\n",
                "text/x-nix-cache-info");
   } else {
-    for (auto& line : absl::StrSplit(*cacheInfo, absl::ByChar('\n'))) {
+    for (auto& line :
+         absl::StrSplit(*cacheInfo, absl::ByChar('\n'), absl::SkipEmpty())) {
       size_t colon = line.find(':');
       if (colon == std::string::npos) {
         continue;
diff --git a/third_party/nix/src/libstore/build.cc b/third_party/nix/src/libstore/build.cc
index 27d6aa611f..9bff3b8345 100644
--- a/third_party/nix/src/libstore/build.cc
+++ b/third_party/nix/src/libstore/build.cc
@@ -2485,7 +2485,8 @@ void DerivationGoal::initTmpDir() {
      there is no size constraint). */
   if (!parsedDrv->getStructuredAttrs()) {
     std::set<std::string> passAsFile =
-        absl::StrSplit(get(drv->env, "passAsFile"), absl::ByAnyChar(" \t\n\r"));
+        absl::StrSplit(get(drv->env, "passAsFile"), absl::ByAnyChar(" \t\n\r"),
+                       absl::SkipEmpty());
     for (auto& i : drv->env) {
       if (passAsFile.find(i.first) == passAsFile.end()) {
         env[i.first] = i.second;
diff --git a/third_party/nix/src/libstore/builtins/buildenv.cc b/third_party/nix/src/libstore/builtins/buildenv.cc
index 95f915227b..7ef7e2c25a 100644
--- a/third_party/nix/src/libstore/builtins/buildenv.cc
+++ b/third_party/nix/src/libstore/builtins/buildenv.cc
@@ -137,7 +137,7 @@ static void addPkg(const Path& pkgDir, int priority) {
   try {
     for (auto p : absl::StrSplit(
              readFile(pkgDir + "/nix-support/propagated-user-env-packages"),
-             absl::ByAnyChar(" \n"))) {
+             absl::ByAnyChar(" \n"), absl::SkipEmpty())) {
       auto pkg = std::string(p);
       if (!done.count(pkg)) {
         postponed.insert(pkg);
@@ -175,8 +175,8 @@ void builtinBuildenv(const BasicDerivation& drv) {
   /* Convert the stuff we get from the environment back into a
    * coherent data type. */
   Packages pkgs;
-  Strings derivations =
-      absl::StrSplit(getAttr("derivations"), absl::ByAnyChar(" \t\n\r"));
+  Strings derivations = absl::StrSplit(
+      getAttr("derivations"), absl::ByAnyChar(" \t\n\r"), absl::SkipEmpty());
   while (!derivations.empty()) {
     /* !!! We're trusting the caller to structure derivations env var correctly
      */
diff --git a/third_party/nix/src/libstore/derivations.cc b/third_party/nix/src/libstore/derivations.cc
index 0e8b637fa7..b7dcded3de 100644
--- a/third_party/nix/src/libstore/derivations.cc
+++ b/third_party/nix/src/libstore/derivations.cc
@@ -421,7 +421,8 @@ DrvPathWithOutputs parseDrvPathWithOutputs(absl::string_view path) {
 
   return DrvPathWithOutputs(
       path.substr(0, pos),
-      absl::StrSplit(path.substr(pos + 1), absl::ByChar(',')));
+      absl::StrSplit(path.substr(pos + 1), absl::ByChar(','),
+                     absl::SkipEmpty()));
 }
 
 Path makeDrvPathWithOutputs(const Path& drvPath,
diff --git a/third_party/nix/src/libstore/download.cc b/third_party/nix/src/libstore/download.cc
index fdc14b3762..cf64a6bad7 100644
--- a/third_party/nix/src/libstore/download.cc
+++ b/third_party/nix/src/libstore/download.cc
@@ -181,7 +181,8 @@ struct CurlDownloader : public Downloader {
                  << "': " << absl::StripAsciiWhitespace(line);
       if (line.compare(0, 5, "HTTP/") == 0) {  // new response starts
         result.etag = "";
-        std::vector<std::string> ss = absl::StrSplit(line, absl::ByChar(' '));
+        std::vector<std::string> ss =
+            absl::StrSplit(line, absl::ByChar(' '), absl::SkipEmpty());
         status = ss.size() >= 2 ? ss[1] : "";
         result.data = std::make_shared<std::string>();
         result.bodySize = 0;
@@ -896,8 +897,8 @@ CachedDownloadResult Downloader::downloadCached(
     storePath = readLink(fileLink);
     store->addTempRoot(storePath);
     if (store->isValidPath(storePath)) {
-      std::vector<std::string> ss =
-          absl::StrSplit(readFile(dataFile), absl::ByChar('\n'));
+      std::vector<std::string> ss = absl::StrSplit(
+          readFile(dataFile), absl::ByChar('\n'), absl::SkipEmpty());
       if (ss.size() >= 3 && ss[0] == url) {
         time_t lastChecked;
         if (absl::SimpleAtoi(ss[2], &lastChecked) &&
diff --git a/third_party/nix/src/libstore/gc.cc b/third_party/nix/src/libstore/gc.cc
index 9a6d97eb73..a491d7e32c 100644
--- a/third_party/nix/src/libstore/gc.cc
+++ b/third_party/nix/src/libstore/gc.cc
@@ -423,8 +423,8 @@ void LocalStore::findRuntimeRoots(Roots& roots, bool censor) {
 
         try {
           auto mapFile = fmt("/proc/%s/maps", ent->d_name);
-          std::vector<std::string> mapLines =
-              absl::StrSplit(readFile(mapFile, true), absl::ByChar('\n'));
+          std::vector<std::string> mapLines = absl::StrSplit(
+              readFile(mapFile, true), absl::ByChar('\n'), absl::SkipEmpty());
           for (const auto& line : mapLines) {
             auto match = std::smatch{};
             if (std::regex_match(line, match, mapRegex)) {
diff --git a/third_party/nix/src/libstore/globals.cc b/third_party/nix/src/libstore/globals.cc
index 06ef3dd040..1e194135cc 100644
--- a/third_party/nix/src/libstore/globals.cc
+++ b/third_party/nix/src/libstore/globals.cc
@@ -59,14 +59,14 @@ Settings::Settings()
   auto s = getEnv("NIX_REMOTE_SYSTEMS");
   if (!s.empty()) {
     Strings ss;
-    for (auto p : absl::StrSplit(s, absl::ByChar(':'))) {
+    for (auto p : absl::StrSplit(s, absl::ByChar(':'), absl::SkipEmpty())) {
       ss.push_back(absl::StrCat("@", p));
     }
     builders = concatStringsSep(" ", ss);
   }
 
-  sandboxPaths =
-      absl::StrSplit("/bin/sh=" SANDBOX_SHELL, absl::ByAnyChar(" \t\n\r"));
+  sandboxPaths = absl::StrSplit("/bin/sh=" SANDBOX_SHELL,
+                                absl::ByAnyChar(" \t\n\r"), absl::SkipEmpty());
 }
 
 void loadConfFile() {
diff --git a/third_party/nix/src/libstore/local-store.cc b/third_party/nix/src/libstore/local-store.cc
index 3ad574186b..9b19e078b8 100644
--- a/third_party/nix/src/libstore/local-store.cc
+++ b/third_party/nix/src/libstore/local-store.cc
@@ -468,9 +468,9 @@ static void canonicalisePathMetaData_(const Path& path, uid_t fromUid,
       throw SysError("querying extended attributes of '%s'", path);
     }
 
-    for (auto& eaName :
-         absl::StrSplit(std::string(eaBuf.data(), eaSize),
-                        absl::ByString(std::string("\000", 1)))) {
+    for (auto& eaName : absl::StrSplit(std::string(eaBuf.data(), eaSize),
+                                       absl::ByString(std::string("\000", 1)),
+                                       absl::SkipEmpty())) {
       /* Ignore SELinux security labels since these cannot be
          removed even by root. */
       if (eaName == "security.selinux") {
@@ -702,7 +702,7 @@ void LocalStore::queryPathInfoUncached(
 
       s = (const char*)sqlite3_column_text(state->stmtQueryPathInfo, 6);
       if (s != nullptr) {
-        info->sigs = absl::StrSplit(s, absl::ByChar(' '));
+        info->sigs = absl::StrSplit(s, absl::ByChar(' '), absl::SkipEmpty());
       }
 
       s = (const char*)sqlite3_column_text(state->stmtQueryPathInfo, 7);
diff --git a/third_party/nix/src/libstore/local-store.hh b/third_party/nix/src/libstore/local-store.hh
index 7ad9de3a8a..731cf1764c 100644
--- a/third_party/nix/src/libstore/local-store.hh
+++ b/third_party/nix/src/libstore/local-store.hh
@@ -97,8 +97,8 @@ class LocalStore : public LocalFSStore {
  public:
   // Hack for build-remote.cc.
   // TODO(tazjin): remove this when we've got gRPC
-  PathSet locksHeld =
-      absl::StrSplit(getEnv("NIX_HELD_LOCKS"), absl::ByAnyChar(" \t\n\r"));
+  PathSet locksHeld = absl::StrSplit(
+      getEnv("NIX_HELD_LOCKS"), absl::ByAnyChar(" \t\n\r"), absl::SkipEmpty());
 
   /* Initialise the local store, upgrading the schema if
      necessary. */
diff --git a/third_party/nix/src/libstore/machines.cc b/third_party/nix/src/libstore/machines.cc
index e5d22c534c..57c89e0692 100644
--- a/third_party/nix/src/libstore/machines.cc
+++ b/third_party/nix/src/libstore/machines.cc
@@ -52,7 +52,8 @@ bool Machine::mandatoryMet(const std::set<std::string>& features) const {
 }
 
 void parseMachines(const std::string& s, Machines& machines) {
-  for (auto line : absl::StrSplit(s, absl::ByAnyChar("\n;"))) {
+  for (auto line :
+       absl::StrSplit(s, absl::ByAnyChar("\n;"), absl::SkipEmpty())) {
     // Skip empty lines & comments
     line = absl::StripAsciiWhitespace(line);
     if (line.empty() || line[line.find_first_not_of(" \t")] == '#') {
@@ -73,7 +74,7 @@ void parseMachines(const std::string& s, Machines& machines) {
     }
 
     std::vector<std::string> tokens =
-        absl::StrSplit(line, absl::ByAnyChar(" \t\n\r"));
+        absl::StrSplit(line, absl::ByAnyChar(" \t\n\r"), absl::SkipEmpty());
     auto sz = tokens.size();
     if (sz < 1) {
       throw FormatError("bad machine specification '%s'", line);
@@ -86,14 +87,17 @@ void parseMachines(const std::string& s, Machines& machines) {
     // TODO(tazjin): what???
     machines.emplace_back(
         tokens[0],
-        isSet(1) ? absl::StrSplit(tokens[1], absl::ByChar(','))
-                 : std::vector<std::string>{settings.thisSystem},
+        isSet(1)
+            ? absl::StrSplit(tokens[1], absl::ByChar(','), absl::SkipEmpty())
+            : std::vector<std::string>{settings.thisSystem},
         isSet(2) ? tokens[2] : "", isSet(3) ? std::stoull(tokens[3]) : 1LL,
         isSet(4) ? std::stoull(tokens[4]) : 1LL,
-        isSet(5) ? absl::StrSplit(tokens[5], absl::ByChar(','))
-                 : std::set<std::string>{},
-        isSet(6) ? absl::StrSplit(tokens[6], absl::ByChar(','))
-                 : std::set<std::string>{},
+        isSet(5)
+            ? absl::StrSplit(tokens[5], absl::ByChar(','), absl::SkipEmpty())
+            : std::set<std::string>{},
+        isSet(6)
+            ? absl::StrSplit(tokens[6], absl::ByChar(','), absl::SkipEmpty())
+            : std::set<std::string>{},
         isSet(7) ? tokens[7] : "");
   }
 }
diff --git a/third_party/nix/src/libstore/nar-info-disk-cache.cc b/third_party/nix/src/libstore/nar-info-disk-cache.cc
index a09ed3c0b6..b284fc698d 100644
--- a/third_party/nix/src/libstore/nar-info-disk-cache.cc
+++ b/third_party/nix/src/libstore/nar-info-disk-cache.cc
@@ -232,14 +232,15 @@ class NarInfoDiskCacheImpl final : public NarInfoDiskCache {
           auto hash_ = Hash::deserialize(queryNAR.getStr(6));
           narInfo->narHash = Hash::unwrap_throw(hash_);
           narInfo->narSize = queryNAR.getInt(7);
-          for (auto r : absl::StrSplit(queryNAR.getStr(8), absl::ByChar(' '))) {
+          for (auto r : absl::StrSplit(queryNAR.getStr(8), absl::ByChar(' '),
+                                       absl::SkipEmpty())) {
             narInfo->references.insert(absl::StrCat(cache.storeDir, "/", r));
           }
           if (!queryNAR.isNull(9)) {
             narInfo->deriver = cache.storeDir + "/" + queryNAR.getStr(9);
           }
-          for (auto& sig :
-               absl::StrSplit(queryNAR.getStr(10), absl::ByChar(' '))) {
+          for (auto& sig : absl::StrSplit(
+                   queryNAR.getStr(10), absl::ByChar(' '), absl::SkipEmpty())) {
             narInfo->sigs.insert(std::string(sig));
           }
           narInfo->ca = queryNAR.getStr(11);
diff --git a/third_party/nix/src/libstore/nar-info.cc b/third_party/nix/src/libstore/nar-info.cc
index ec9f882f4f..d42167dbfa 100644
--- a/third_party/nix/src/libstore/nar-info.cc
+++ b/third_party/nix/src/libstore/nar-info.cc
@@ -62,7 +62,8 @@ NarInfo::NarInfo(const Store& store, const std::string& s,
         corrupt();
       }
     } else if (name == "References") {
-      std::vector<std::string> refs = absl::StrSplit(value, absl::ByChar(' '));
+      std::vector<std::string> refs =
+          absl::StrSplit(value, absl::ByChar(' '), absl::SkipEmpty());
       if (!references.empty()) {
         corrupt();
       }
diff --git a/third_party/nix/src/libstore/parsed-derivations.cc b/third_party/nix/src/libstore/parsed-derivations.cc
index 9ee93b6a6d..6989a21fee 100644
--- a/third_party/nix/src/libstore/parsed-derivations.cc
+++ b/third_party/nix/src/libstore/parsed-derivations.cc
@@ -88,7 +88,8 @@ std::optional<Strings> ParsedDerivation::getStringsAttr(
     if (i == drv.env.end()) {
       return {};
     }
-    return absl::StrSplit(i->second, absl::ByAnyChar(" \t\n\r"));
+    return absl::StrSplit(i->second, absl::ByAnyChar(" \t\n\r"),
+                          absl::SkipEmpty());
   }
 }
 
diff --git a/third_party/nix/src/libstore/ssh.cc b/third_party/nix/src/libstore/ssh.cc
index e84944c4c9..8f27f5eb22 100644
--- a/third_party/nix/src/libstore/ssh.cc
+++ b/third_party/nix/src/libstore/ssh.cc
@@ -22,7 +22,8 @@ SSHMaster::SSHMaster(const std::string& host, std::string keyFile,
 
 void SSHMaster::addCommonSSHOpts(Strings& args) {
   for (auto& i :
-       absl::StrSplit(getEnv("NIX_SSHOPTS"), absl::ByAnyChar(" \t\n\r"))) {
+       absl::StrSplit(getEnv("NIX_SSHOPTS"), absl::ByAnyChar(" \t\n\r"),
+                      absl::SkipEmpty())) {
     args.push_back(std::string(i));
   }
   if (!keyFile.empty()) {
diff --git a/third_party/nix/src/libstore/store-api.cc b/third_party/nix/src/libstore/store-api.cc
index ab71282272..4f4083f64f 100644
--- a/third_party/nix/src/libstore/store-api.cc
+++ b/third_party/nix/src/libstore/store-api.cc
@@ -960,7 +960,8 @@ std::pair<std::string, Store::Params> splitUriAndParams(
   Store::Params params;
   auto q = uri.find('?');
   if (q != std::string::npos) {
-    Strings parts = absl::StrSplit(uri.substr(q + 1), absl::ByChar('&'));
+    Strings parts =
+        absl::StrSplit(uri.substr(q + 1), absl::ByChar('&'), absl::SkipEmpty());
     for (const auto& s : parts) {
       auto e = s.find('=');
       if (e != std::string::npos) {