about summary refs log tree commit diff
path: root/third_party/nix/src/libstore/gc.cc
diff options
context:
space:
mode:
authorVincent Ambo <tazjin@google.com>2020-05-25T14·54+0100
committerVincent Ambo <tazjin@google.com>2020-05-25T14·54+0100
commitbf452cbc2ae2b209ec262ce858deca470d086f24 (patch)
tree198e98902be569301ecb9a821b0c9512b128f930 /third_party/nix/src/libstore/gc.cc
parentb99b368d17f2e806a61f7abb83c6d3a9e4bbdc38 (diff)
refactor(3p/nix): Replace tokenizeStrings with absl::StrSplit r/846
This function was a custom (and inefficient in the case of
single-character delimiters) string splitter which was used all over
the codebase. Abseil provides an appropriate replacement function.
Diffstat (limited to 'third_party/nix/src/libstore/gc.cc')
-rw-r--r--third_party/nix/src/libstore/gc.cc27
1 files changed, 3 insertions, 24 deletions
diff --git a/third_party/nix/src/libstore/gc.cc b/third_party/nix/src/libstore/gc.cc
index 262f17df0338..5c1ea3d58b69 100644
--- a/third_party/nix/src/libstore/gc.cc
+++ b/third_party/nix/src/libstore/gc.cc
@@ -7,6 +7,7 @@
 #include <regex>
 
 #include <absl/strings/match.h>
+#include <absl/strings/str_split.h>
 #include <fcntl.h>
 #include <sys/stat.h>
 #include <sys/statvfs.h>
@@ -422,8 +423,8 @@ void LocalStore::findRuntimeRoots(Roots& roots, bool censor) {
 
         try {
           auto mapFile = fmt("/proc/%s/maps", ent->d_name);
-          auto mapLines = tokenizeString<std::vector<std::string>>(
-              readFile(mapFile, true), "\n");
+          std::vector<std::string> mapLines =
+              absl::StrSplit(readFile(mapFile, true), absl::ByChar('\n'));
           for (const auto& line : mapLines) {
             auto match = std::smatch{};
             if (std::regex_match(line, match, mapRegex)) {
@@ -452,31 +453,9 @@ void LocalStore::findRuntimeRoots(Roots& roots, bool censor) {
     }
   }
 
-#if !defined(__linux__)
-  // lsof is really slow on OS X. This actually causes the gc-concurrent.sh test
-  // to fail. See: https://github.com/NixOS/nix/issues/3011 Because of this we
-  // disable lsof when running the tests.
-  if (getEnv("_NIX_TEST_NO_LSOF") == "") {
-    try {
-      std::regex lsofRegex(R"(^n(/.*)$)");
-      auto lsofLines = tokenizeString<std::vector<std::string>>(
-          runProgram(LSOF, true, {"-n", "-w", "-F", "n"}), "\n");
-      for (const auto& line : lsofLines) {
-        std::smatch match;
-        if (std::regex_match(line, match, lsofRegex))
-          unchecked[match[1]].emplace("{lsof}");
-      }
-    } catch (ExecError& e) {
-      /* lsof not installed, lsof failed */
-    }
-  }
-#endif
-
-#if defined(__linux__)
   readFileRoots("/proc/sys/kernel/modprobe", unchecked);
   readFileRoots("/proc/sys/kernel/fbsplash", unchecked);
   readFileRoots("/proc/sys/kernel/poweroff_cmd", unchecked);
-#endif
 
   for (auto& [target, links] : unchecked) {
     if (isInStore(target)) {