about summary refs log tree commit diff
path: root/third_party/nix/src/libstore/nar-info.cc
diff options
context:
space:
mode:
authorVincent Ambo <tazjin@google.com>2020-05-17T15·31+0100
committerVincent Ambo <tazjin@google.com>2020-05-17T15·31+0100
commit0f2cf531f705d370321843e5ba9135b2ebdb5d19 (patch)
tree256feb13963a849ed96e89228fa05454c2a22363 /third_party/nix/src/libstore/nar-info.cc
parent65a1aae98ce5a237c9643e639e550c8b0c0be7f1 (diff)
style(3p/nix): Reformat project in Google C++ style r/740
Reformatted with:

    fd . -e hh -e cc | xargs clang-format -i
Diffstat (limited to 'third_party/nix/src/libstore/nar-info.cc')
-rw-r--r--third_party/nix/src/libstore/nar-info.cc187
1 files changed, 88 insertions, 99 deletions
diff --git a/third_party/nix/src/libstore/nar-info.cc b/third_party/nix/src/libstore/nar-info.cc
index cb568ccdc828..bf195290d040 100644
--- a/third_party/nix/src/libstore/nar-info.cc
+++ b/third_party/nix/src/libstore/nar-info.cc
@@ -1,116 +1,105 @@
-#include "globals.hh"
 #include "nar-info.hh"
+#include "globals.hh"
 
 namespace nix {
 
-NarInfo::NarInfo(const Store & store, const std::string & s, const std::string & whence)
-{
-    auto corrupt = [&]() {
-        throw Error(format("NAR info file '%1%' is corrupt") % whence);
-    };
-
-    auto parseHashField = [&](const string & s) {
-        try {
-            return Hash(s);
-        } catch (BadHash &) {
-            corrupt();
-            return Hash(); // never reached
-        }
-    };
-
-    size_t pos = 0;
-    while (pos < s.size()) {
-
-        size_t colon = s.find(':', pos);
-        if (colon == std::string::npos) corrupt();
-
-        std::string name(s, pos, colon - pos);
-
-        size_t eol = s.find('\n', colon + 2);
-        if (eol == std::string::npos) corrupt();
-
-        std::string value(s, colon + 2, eol - colon - 2);
-
-        if (name == "StorePath") {
-            if (!store.isStorePath(value)) corrupt();
-            path = value;
-        }
-        else if (name == "URL")
-            url = value;
-        else if (name == "Compression")
-            compression = value;
-        else if (name == "FileHash")
-            fileHash = parseHashField(value);
-        else if (name == "FileSize") {
-            if (!string2Int(value, fileSize)) corrupt();
-        }
-        else if (name == "NarHash")
-            narHash = parseHashField(value);
-        else if (name == "NarSize") {
-            if (!string2Int(value, narSize)) corrupt();
-        }
-        else if (name == "References") {
-            auto refs = tokenizeString<Strings>(value, " ");
-            if (!references.empty()) corrupt();
-            for (auto & r : refs) {
-                auto r2 = store.storeDir + "/" + r;
-                if (!store.isStorePath(r2)) corrupt();
-                references.insert(r2);
-            }
-        }
-        else if (name == "Deriver") {
-            if (value != "unknown-deriver") {
-                auto p = store.storeDir + "/" + value;
-                if (!store.isStorePath(p)) corrupt();
-                deriver = p;
-            }
-        }
-        else if (name == "System")
-            system = value;
-        else if (name == "Sig")
-            sigs.insert(value);
-        else if (name == "CA") {
-            if (!ca.empty()) corrupt();
-            ca = value;
-        }
-
-        pos = eol + 1;
+NarInfo::NarInfo(const Store& store, const std::string& s,
+                 const std::string& whence) {
+  auto corrupt = [&]() {
+    throw Error(format("NAR info file '%1%' is corrupt") % whence);
+  };
+
+  auto parseHashField = [&](const string& s) {
+    try {
+      return Hash(s);
+    } catch (BadHash&) {
+      corrupt();
+      return Hash();  // never reached
+    }
+  };
+
+  size_t pos = 0;
+  while (pos < s.size()) {
+    size_t colon = s.find(':', pos);
+    if (colon == std::string::npos) corrupt();
+
+    std::string name(s, pos, colon - pos);
+
+    size_t eol = s.find('\n', colon + 2);
+    if (eol == std::string::npos) corrupt();
+
+    std::string value(s, colon + 2, eol - colon - 2);
+
+    if (name == "StorePath") {
+      if (!store.isStorePath(value)) corrupt();
+      path = value;
+    } else if (name == "URL")
+      url = value;
+    else if (name == "Compression")
+      compression = value;
+    else if (name == "FileHash")
+      fileHash = parseHashField(value);
+    else if (name == "FileSize") {
+      if (!string2Int(value, fileSize)) corrupt();
+    } else if (name == "NarHash")
+      narHash = parseHashField(value);
+    else if (name == "NarSize") {
+      if (!string2Int(value, narSize)) corrupt();
+    } else if (name == "References") {
+      auto refs = tokenizeString<Strings>(value, " ");
+      if (!references.empty()) corrupt();
+      for (auto& r : refs) {
+        auto r2 = store.storeDir + "/" + r;
+        if (!store.isStorePath(r2)) corrupt();
+        references.insert(r2);
+      }
+    } else if (name == "Deriver") {
+      if (value != "unknown-deriver") {
+        auto p = store.storeDir + "/" + value;
+        if (!store.isStorePath(p)) corrupt();
+        deriver = p;
+      }
+    } else if (name == "System")
+      system = value;
+    else if (name == "Sig")
+      sigs.insert(value);
+    else if (name == "CA") {
+      if (!ca.empty()) corrupt();
+      ca = value;
     }
 
-    if (compression == "") compression = "bzip2";
+    pos = eol + 1;
+  }
 
-    if (path.empty() || url.empty() || narSize == 0 || !narHash) corrupt();
+  if (compression == "") compression = "bzip2";
+
+  if (path.empty() || url.empty() || narSize == 0 || !narHash) corrupt();
 }
 
-std::string NarInfo::to_string() const
-{
-    std::string res;
-    res += "StorePath: " + path + "\n";
-    res += "URL: " + url + "\n";
-    assert(compression != "");
-    res += "Compression: " + compression + "\n";
-    assert(fileHash.type == htSHA256);
-    res += "FileHash: " + fileHash.to_string(Base32) + "\n";
-    res += "FileSize: " + std::to_string(fileSize) + "\n";
-    assert(narHash.type == htSHA256);
-    res += "NarHash: " + narHash.to_string(Base32) + "\n";
-    res += "NarSize: " + std::to_string(narSize) + "\n";
+std::string NarInfo::to_string() const {
+  std::string res;
+  res += "StorePath: " + path + "\n";
+  res += "URL: " + url + "\n";
+  assert(compression != "");
+  res += "Compression: " + compression + "\n";
+  assert(fileHash.type == htSHA256);
+  res += "FileHash: " + fileHash.to_string(Base32) + "\n";
+  res += "FileSize: " + std::to_string(fileSize) + "\n";
+  assert(narHash.type == htSHA256);
+  res += "NarHash: " + narHash.to_string(Base32) + "\n";
+  res += "NarSize: " + std::to_string(narSize) + "\n";
 
-    res += "References: " + concatStringsSep(" ", shortRefs()) + "\n";
+  res += "References: " + concatStringsSep(" ", shortRefs()) + "\n";
 
-    if (!deriver.empty())
-        res += "Deriver: " + baseNameOf(deriver) + "\n";
+  if (!deriver.empty()) res += "Deriver: " + baseNameOf(deriver) + "\n";
 
-    if (!system.empty())
-        res += "System: " + system + "\n";
+  if (!system.empty()) res += "System: " + system + "\n";
 
-    for (auto sig : sigs)
-        res += "Sig: " + sig + "\n";
+  for (auto sig : sigs) res += "Sig: " + sig + "\n";
 
-    if (!ca.empty())
-        res += "CA: " + ca + "\n";
+  if (!ca.empty()) res += "CA: " + ca + "\n";
 
-    return res;
+  return res;
 }
 
-}
+}  // namespace nix