about summary refs log tree commit diff
path: root/third_party/nix/src/nix-store
diff options
context:
space:
mode:
authorVincent Ambo <tazjin@google.com>2020-05-19T17·55+0100
committerVincent Ambo <tazjin@google.com>2020-05-19T17·55+0100
commit867055133d3f487e52dd44149f76347c2c28bf10 (patch)
treec367803ad94f024b0052727a2c7a037af169169a /third_party/nix/src/nix-store
parentc6a31838cd7e88ebcb01422b329a499d04ab4b6b (diff)
style(3p/nix): Add braces around single-line conditionals r/771
These were not caught by the previous clang-tidy invocation, but were
instead sorted out using amber[0] as such:

    ambr --regex 'if (\(.+\))\s([a-z].*;)' 'if $1 { $2 }'

[0]: https://github.com/dalance/amber
Diffstat (limited to 'third_party/nix/src/nix-store')
-rw-r--r--third_party/nix/src/nix-store/dotgraph.cc6
-rw-r--r--third_party/nix/src/nix-store/graphml.cc4
-rw-r--r--third_party/nix/src/nix-store/nix-store.cc168
3 files changed, 133 insertions, 45 deletions
diff --git a/third_party/nix/src/nix-store/dotgraph.cc b/third_party/nix/src/nix-store/dotgraph.cc
index 710d781c7edb..259ecbd74a5e 100644
--- a/third_party/nix/src/nix-store/dotgraph.cc
+++ b/third_party/nix/src/nix-store/dotgraph.cc
@@ -89,7 +89,9 @@ void printDotGraph(ref<Store> store, const PathSet& roots) {
     Path path = *(workList.begin());
     workList.erase(path);
 
-    if (doneSet.find(path) != doneSet.end()) continue;
+    if (doneSet.find(path) != doneSet.end()) {
+      continue;
+    }
     doneSet.insert(path);
 
     cout << makeNode(path, symbolicName(path), "#ff0000");
@@ -118,7 +120,7 @@ void printDotGraph(ref<Store> store, const PathSet& roots) {
             colour = "#00ff00";
             for (StringPairs::iterator i = ne.derivation.env.begin();
                  i != ne.derivation.env.end(); ++i)
-                if (i->first == "name") label = i->second;
+                if (i->first == "name") { label = i->second; }
         }
 
         else if (ne.type == StoreExpr::neClosure) {
diff --git a/third_party/nix/src/nix-store/graphml.cc b/third_party/nix/src/nix-store/graphml.cc
index a48b19bf9636..07116cda930a 100644
--- a/third_party/nix/src/nix-store/graphml.cc
+++ b/third_party/nix/src/nix-store/graphml.cc
@@ -58,7 +58,9 @@ void printGraphML(ref<Store> store, const PathSet& roots) {
     workList.erase(path);
 
     ret = doneSet.insert(path);
-    if (ret.second == false) continue;
+    if (ret.second == false) {
+      continue;
+    }
 
     ValidPathInfo info = *(store->queryPathInfo(path));
     cout << makeNode(info);
diff --git a/third_party/nix/src/nix-store/nix-store.cc b/third_party/nix/src/nix-store/nix-store.cc
index 14ad5364cd46..3de536a6c4a6 100644
--- a/third_party/nix/src/nix-store/nix-store.cc
+++ b/third_party/nix/src/nix-store/nix-store.cc
@@ -44,7 +44,9 @@ ref<LocalStore> ensureLocalStore() {
 }
 
 static Path useDeriver(Path path) {
-  if (isDerivation(path)) return path;
+  if (isDerivation(path)) {
+    return path;
+  }
   Path drvPath = store->queryPathInfo(path)->deriver;
   if (drvPath == "")
     throw Error(format("deriver of path '%1%' is not known") % path);
@@ -59,7 +61,9 @@ static PathSet realisePath(Path path, bool build = true) {
   auto store2 = std::dynamic_pointer_cast<LocalFSStore>(store);
 
   if (isDerivation(p.first)) {
-    if (build) store->buildPaths({path});
+    if (build) {
+      store->buildPaths({path});
+    }
     Derivation drv = store->derivationFromPath(p.first);
     rootNr++;
 
@@ -79,8 +83,12 @@ static PathSet realisePath(Path path, bool build = true) {
           printGCWarning();
         else {
           Path rootName = gcRoot;
-          if (rootNr > 1) rootName += "-" + std::to_string(rootNr);
-          if (i->first != "out") rootName += "-" + i->first;
+          if (rootNr > 1) {
+            rootName += "-" + std::to_string(rootNr);
+          }
+          if (i->first != "out") {
+            rootName += "-" + i->first;
+          }
           outPath = store2->addPermRoot(outPath, rootName, indirectRoot);
         }
       }
@@ -101,7 +109,9 @@ static PathSet realisePath(Path path, bool build = true) {
       else {
         Path rootName = gcRoot;
         rootNr++;
-        if (rootNr > 1) rootName += "-" + std::to_string(rootNr);
+        if (rootNr > 1) {
+          rootName += "-" + std::to_string(rootNr);
+        }
         path = store2->addPermRoot(path, rootName, indirectRoot);
       }
     }
@@ -142,7 +152,9 @@ static void opRealise(Strings opFlags, Strings opArgs) {
   if (ignoreUnknown) {
     Paths paths2;
     for (auto& i : paths)
-      if (unknown.find(i) == unknown.end()) paths2.push_back(i);
+      if (unknown.find(i) == unknown.end()) {
+        paths2.push_back(i);
+      }
     paths = paths2;
     unknown = PathSet();
   }
@@ -168,7 +180,9 @@ static void opRealise(Strings opFlags, Strings opArgs) {
 
 /* Add files to the Nix store and print the resulting paths. */
 static void opAdd(Strings opFlags, Strings opArgs) {
-  if (!opFlags.empty()) throw UsageError("unknown flag");
+  if (!opFlags.empty()) {
+    throw UsageError("unknown flag");
+  }
 
   for (auto& i : opArgs)
     cout << format("%1%\n") % store->addToStore(baseNameOf(i), i);
@@ -185,7 +199,9 @@ static void opAddFixed(Strings opFlags, Strings opArgs) {
     else
       throw UsageError(format("unknown flag '%1%'") % i);
 
-  if (opArgs.empty()) throw UsageError("first argument must be hash algorithm");
+  if (opArgs.empty()) {
+    throw UsageError("first argument must be hash algorithm");
+  }
 
   HashType hashAlgo = parseHashType(opArgs.front());
   opArgs.pop_front();
@@ -307,7 +323,9 @@ static void opQuery(Strings opFlags, Strings opArgs) {
     else if (i == "--deriver" || i == "-d")
       query = qDeriver;
     else if (i == "--binding" || i == "-b") {
-      if (opArgs.size() == 0) throw UsageError("expected binding name");
+      if (opArgs.size() == 0) {
+        throw UsageError("expected binding name");
+      }
       bindingName = opArgs.front();
       opArgs.pop_front();
       query = qBinding;
@@ -348,7 +366,9 @@ static void opQuery(Strings opFlags, Strings opArgs) {
     case qOutputs: {
       for (auto& i : opArgs) {
         i = store->followLinksToStorePath(i);
-        if (forceRealise) realisePath(i);
+        if (forceRealise) {
+          realisePath(i);
+        }
         Derivation drv = store->derivationFromPath(i);
         for (auto& j : drv.outputs) cout << format("%1%\n") % j.second.path;
       }
@@ -476,7 +496,9 @@ static void opQuery(Strings opFlags, Strings opArgs) {
 }
 
 static void opPrintEnv(Strings opFlags, Strings opArgs) {
-  if (!opFlags.empty()) throw UsageError("unknown flag");
+  if (!opFlags.empty()) {
+    throw UsageError("unknown flag");
+  }
   if (opArgs.size() != 1)
     throw UsageError("'--print-env' requires one derivation store path");
 
@@ -493,7 +515,9 @@ static void opPrintEnv(Strings opFlags, Strings opArgs) {
   cout << "export _args; _args='";
   bool first = true;
   for (auto& i : drv.args) {
-    if (!first) cout << ' ';
+    if (!first) {
+      cout << ' ';
+    }
     first = false;
     cout << shellEscape(i);
   }
@@ -501,7 +525,9 @@ static void opPrintEnv(Strings opFlags, Strings opArgs) {
 }
 
 static void opReadLog(Strings opFlags, Strings opArgs) {
-  if (!opFlags.empty()) throw UsageError("unknown flag");
+  if (!opFlags.empty()) {
+    throw UsageError("unknown flag");
+  }
 
   RunPager pager;
 
@@ -515,7 +541,9 @@ static void opReadLog(Strings opFlags, Strings opArgs) {
 }
 
 static void opDumpDB(Strings opFlags, Strings opArgs) {
-  if (!opFlags.empty()) throw UsageError("unknown flag");
+  if (!opFlags.empty()) {
+    throw UsageError("unknown flag");
+  }
   if (!opArgs.empty()) {
     for (auto& i : opArgs) i = store->followLinksToStorePath(i);
     for (auto& i : opArgs)
@@ -533,10 +561,14 @@ static void registerValidity(bool reregister, bool hashGiven,
 
   while (1) {
     ValidPathInfo info = decodeValidPathInfo(cin, hashGiven);
-    if (info.path == "") break;
+    if (info.path == "") {
+      break;
+    }
     if (!store->isValidPath(info.path) || reregister) {
       /* !!! races */
-      if (canonicalise) canonicalisePathMetaData(info.path, -1);
+      if (canonicalise) {
+        canonicalisePathMetaData(info.path, -1);
+      }
       if (!hashGiven) {
         HashResult hash = hashPath(htSHA256, info.path);
         info.narHash = hash.first;
@@ -550,8 +582,12 @@ static void registerValidity(bool reregister, bool hashGiven,
 }
 
 static void opLoadDB(Strings opFlags, Strings opArgs) {
-  if (!opFlags.empty()) throw UsageError("unknown flag");
-  if (!opArgs.empty()) throw UsageError("no arguments expected");
+  if (!opFlags.empty()) {
+    throw UsageError("unknown flag");
+  }
+  if (!opArgs.empty()) {
+    throw UsageError("no arguments expected");
+  }
   registerValidity(true, true, false);
 }
 
@@ -567,7 +603,9 @@ static void opRegisterValidity(Strings opFlags, Strings opArgs) {
     else
       throw UsageError(format("unknown flag '%1%'") % i);
 
-  if (!opArgs.empty()) throw UsageError("no arguments expected");
+  if (!opArgs.empty()) {
+    throw UsageError("no arguments expected");
+  }
 
   registerValidity(reregister, hashGiven, true);
 }
@@ -615,7 +653,9 @@ static void opGC(Strings opFlags, Strings opArgs) {
     } else
       throw UsageError(format("bad sub-operation '%1%' in GC") % *i);
 
-  if (!opArgs.empty()) throw UsageError("no arguments expected");
+  if (!opArgs.empty()) {
+    throw UsageError("no arguments expected");
+  }
 
   if (printRoots) {
     Roots roots = store->findRoots(false);
@@ -660,8 +700,12 @@ static void opDelete(Strings opFlags, Strings opArgs) {
 /* Dump a path as a Nix archive.  The archive is written to standard
    output. */
 static void opDump(Strings opFlags, Strings opArgs) {
-  if (!opFlags.empty()) throw UsageError("unknown flag");
-  if (opArgs.size() != 1) throw UsageError("only one argument allowed");
+  if (!opFlags.empty()) {
+    throw UsageError("unknown flag");
+  }
+  if (opArgs.size() != 1) {
+    throw UsageError("only one argument allowed");
+  }
 
   FdSink sink(STDOUT_FILENO);
   string path = *opArgs.begin();
@@ -672,8 +716,12 @@ static void opDump(Strings opFlags, Strings opArgs) {
 /* Restore a value from a Nix archive.  The archive is read from
    standard input. */
 static void opRestore(Strings opFlags, Strings opArgs) {
-  if (!opFlags.empty()) throw UsageError("unknown flag");
-  if (opArgs.size() != 1) throw UsageError("only one argument allowed");
+  if (!opFlags.empty()) {
+    throw UsageError("unknown flag");
+  }
+  if (opArgs.size() != 1) {
+    throw UsageError("only one argument allowed");
+  }
 
   FdSource source(STDIN_FILENO);
   restorePath(*opArgs.begin(), source);
@@ -692,7 +740,9 @@ static void opExport(Strings opFlags, Strings opArgs) {
 static void opImport(Strings opFlags, Strings opArgs) {
   for (auto& i : opFlags) throw UsageError(format("unknown flag '%1%'") % i);
 
-  if (!opArgs.empty()) throw UsageError("no arguments expected");
+  if (!opArgs.empty()) {
+    throw UsageError("no arguments expected");
+  }
 
   FdSource source(STDIN_FILENO);
   Paths paths = store->importPaths(source, nullptr, NoCheckSigs);
@@ -702,15 +752,21 @@ static void opImport(Strings opFlags, Strings opArgs) {
 
 /* Initialise the Nix databases. */
 static void opInit(Strings opFlags, Strings opArgs) {
-  if (!opFlags.empty()) throw UsageError("unknown flag");
-  if (!opArgs.empty()) throw UsageError("no arguments expected");
+  if (!opFlags.empty()) {
+    throw UsageError("unknown flag");
+  }
+  if (!opArgs.empty()) {
+    throw UsageError("no arguments expected");
+  }
   /* Doesn't do anything right now; database tables are initialised
      automatically. */
 }
 
 /* Verify the consistency of the Nix environment. */
 static void opVerify(Strings opFlags, Strings opArgs) {
-  if (!opArgs.empty()) throw UsageError("no arguments expected");
+  if (!opArgs.empty()) {
+    throw UsageError("no arguments expected");
+  }
 
   bool checkContents = false;
   RepairFlag repair = NoRepair;
@@ -731,7 +787,9 @@ static void opVerify(Strings opFlags, Strings opArgs) {
 
 /* Verify whether the contents of the given store path have not changed. */
 static void opVerifyPath(Strings opFlags, Strings opArgs) {
-  if (!opFlags.empty()) throw UsageError("no flags expected");
+  if (!opFlags.empty()) {
+    throw UsageError("no flags expected");
+  }
 
   int status = 0;
 
@@ -756,7 +814,9 @@ static void opVerifyPath(Strings opFlags, Strings opArgs) {
 /* Repair the contents of the given path by redownloading it using a
    substituter (if available). */
 static void opRepairPath(Strings opFlags, Strings opArgs) {
-  if (!opFlags.empty()) throw UsageError("no flags expected");
+  if (!opFlags.empty()) {
+    throw UsageError("no flags expected");
+  }
 
   for (auto& i : opArgs) {
     Path path = store->followLinksToStorePath(i);
@@ -782,14 +842,18 @@ static void opServe(Strings opFlags, Strings opArgs) {
     else
       throw UsageError(format("unknown flag '%1%'") % i);
 
-  if (!opArgs.empty()) throw UsageError("no arguments expected");
+  if (!opArgs.empty()) {
+    throw UsageError("no arguments expected");
+  }
 
   FdSource in(STDIN_FILENO);
   FdSink out(STDOUT_FILENO);
 
   /* Exchange the greeting. */
   unsigned int magic = readInt(in);
-  if (magic != SERVE_MAGIC_1) throw Error("protocol mismatch");
+  if (magic != SERVE_MAGIC_1) {
+    throw Error("protocol mismatch");
+  }
   out << SERVE_MAGIC_2 << SERVE_PROTOCOL_VERSION;
   out.flush();
   unsigned int clientVersion = readInt(in);
@@ -834,7 +898,9 @@ static void opServe(Strings opFlags, Strings opArgs) {
           /* Filter out .drv files (we don't want to build anything). */
           PathSet paths2;
           for (auto& path : paths)
-            if (!isDerivation(path)) paths2.insert(path);
+            if (!isDerivation(path)) {
+              paths2.insert(path);
+            }
           unsigned long long downloadSize, narSize;
           PathSet willBuild, willSubstitute, unknown;
           store->queryMissing(PathSet(paths2.begin(), paths2.end()), willBuild,
@@ -877,7 +943,9 @@ static void opServe(Strings opFlags, Strings opArgs) {
         break;
 
       case cmdImportPaths: {
-        if (!writeAllowed) throw Error("importing paths is not allowed");
+        if (!writeAllowed) {
+          throw Error("importing paths is not allowed");
+        }
         store->importPaths(in, nullptr,
                            NoCheckSigs);  // FIXME: should we skip sig checking?
         out << 1;                         // indicate success
@@ -891,7 +959,9 @@ static void opServe(Strings opFlags, Strings opArgs) {
       }
 
       case cmdBuildPaths: {
-        if (!writeAllowed) throw Error("building paths is not allowed");
+        if (!writeAllowed) {
+          throw Error("building paths is not allowed");
+        }
         PathSet paths = readStorePaths<PathSet>(*store, in);
 
         getBuildSettings();
@@ -909,7 +979,9 @@ static void opServe(Strings opFlags, Strings opArgs) {
 
       case cmdBuildDerivation: { /* Used by hydra-queue-runner. */
 
-        if (!writeAllowed) throw Error("building paths is not allowed");
+        if (!writeAllowed) {
+          throw Error("building paths is not allowed");
+        }
 
         Path drvPath = readStorePath(*store, in);  // informational only
         BasicDerivation drv;
@@ -939,12 +1011,16 @@ static void opServe(Strings opFlags, Strings opArgs) {
       }
 
       case cmdAddToStoreNar: {
-        if (!writeAllowed) throw Error("importing paths is not allowed");
+        if (!writeAllowed) {
+          throw Error("importing paths is not allowed");
+        }
 
         ValidPathInfo info;
         info.path = readStorePath(*store, in);
         in >> info.deriver;
-        if (!info.deriver.empty()) store->assertStorePath(info.deriver);
+        if (!info.deriver.empty()) {
+          store->assertStorePath(info.deriver);
+        }
         info.narHash = Hash(readString(in), htSHA256);
         info.references = readStorePaths<PathSet>(*store, in);
         in >> info.registrationTime >> info.narSize >> info.ultimate;
@@ -978,18 +1054,24 @@ static void opServe(Strings opFlags, Strings opArgs) {
 static void opGenerateBinaryCacheKey(Strings opFlags, Strings opArgs) {
   for (auto& i : opFlags) throw UsageError(format("unknown flag '%1%'") % i);
 
-  if (opArgs.size() != 3) throw UsageError("three arguments expected");
+  if (opArgs.size() != 3) {
+    throw UsageError("three arguments expected");
+  }
   auto i = opArgs.begin();
   string keyName = *i++;
   string secretKeyFile = *i++;
   string publicKeyFile = *i++;
 
 #if HAVE_SODIUM
-  if (sodium_init() == -1) throw Error("could not initialise libsodium");
+  if (sodium_init() == -1) {
+    throw Error("could not initialise libsodium");
+  }
 
   unsigned char pk[crypto_sign_PUBLICKEYBYTES];
   unsigned char sk[crypto_sign_SECRETKEYBYTES];
-  if (crypto_sign_keypair(pk, sk) != 0) throw Error("key generation failed");
+  if (crypto_sign_keypair(pk, sk) != 0) {
+    throw Error("key generation failed");
+  }
 
   writeFile(publicKeyFile,
             keyName + ":" +
@@ -1095,7 +1177,9 @@ static int _main(int argc, char** argv) {
 
     initPlugins();
 
-    if (!op) throw UsageError("no operation specified");
+    if (!op) {
+      throw UsageError("no operation specified");
+    }
 
     if (op != opDump && op != opRestore) /* !!! hack */
       store = openStore();