about summary refs log tree commit diff
path: root/third_party/nix/src/nix-prefetch-url/nix-prefetch-url.cc
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-prefetch-url/nix-prefetch-url.cc
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-prefetch-url/nix-prefetch-url.cc')
-rw-r--r--third_party/nix/src/nix-prefetch-url/nix-prefetch-url.cc36
1 files changed, 27 insertions, 9 deletions
diff --git a/third_party/nix/src/nix-prefetch-url/nix-prefetch-url.cc b/third_party/nix/src/nix-prefetch-url/nix-prefetch-url.cc
index d1a34842bc7a..96d8540958fc 100644
--- a/third_party/nix/src/nix-prefetch-url/nix-prefetch-url.cc
+++ b/third_party/nix/src/nix-prefetch-url/nix-prefetch-url.cc
@@ -21,11 +21,15 @@ using namespace nix;
 /* If ‘uri’ starts with ‘mirror://’, then resolve it using the list of
    mirrors defined in Nixpkgs. */
 string resolveMirrorUri(EvalState& state, string uri) {
-  if (string(uri, 0, 9) != "mirror://") return uri;
+  if (string(uri, 0, 9) != "mirror://") {
+    return uri;
+  }
 
   string s(uri, 9);
   auto p = s.find('/');
-  if (p == string::npos) throw Error("invalid mirror URI");
+  if (p == string::npos) {
+    throw Error("invalid mirror URI");
+  }
   string mirrorName(s, 0, p);
 
   Value vMirrors;
@@ -92,7 +96,9 @@ static int _main(int argc, char** argv) {
 
     initPlugins();
 
-    if (args.size() > 2) throw UsageError("too many arguments");
+    if (args.size() > 2) {
+      throw UsageError("too many arguments");
+    }
 
     auto store = openStore();
     auto state = std::make_unique<EvalState>(myArgs.searchPath, store);
@@ -103,7 +109,9 @@ static int _main(int argc, char** argv) {
        expression. */
     string uri;
     if (!fromExpr) {
-      if (args.empty()) throw UsageError("you must specify a URI");
+      if (args.empty()) {
+        throw UsageError("you must specify a URI");
+      }
       uri = args[0];
     } else {
       Path path =
@@ -118,7 +126,9 @@ static int _main(int argc, char** argv) {
       if (attr == v.attrs->end())
         throw Error("attribute set does not contain a 'urls' attribute");
       state->forceList(*attr->value);
-      if (attr->value->listSize() < 1) throw Error("'urls' list is empty");
+      if (attr->value->listSize() < 1) {
+        throw Error("'urls' list is empty");
+      }
       uri = state->forceString(*attr->value->listElems()[0]);
 
       /* Extract the hash mode. */
@@ -131,12 +141,16 @@ static int _main(int argc, char** argv) {
       /* Extract the name. */
       if (name.empty()) {
         attr = v.attrs->find(state->symbols.create("name"));
-        if (attr != v.attrs->end()) name = state->forceString(*attr->value);
+        if (attr != v.attrs->end()) {
+          name = state->forceString(*attr->value);
+        }
       }
     }
 
     /* Figure out a name in the Nix store. */
-    if (name.empty()) name = baseNameOf(uri);
+    if (name.empty()) {
+      name = baseNameOf(uri);
+    }
     if (name.empty())
       throw Error(format("cannot figure out file name for '%1%'") % uri);
 
@@ -163,7 +177,9 @@ static int _main(int argc, char** argv) {
       {
         AutoCloseFD fd =
             open(tmpFile.c_str(), O_WRONLY | O_CREAT | O_EXCL, 0600);
-        if (!fd) throw SysError("creating temporary file '%s'", tmpFile);
+        if (!fd) {
+          throw SysError("creating temporary file '%s'", tmpFile);
+        }
 
         FdSink sink(fd.get());
 
@@ -213,7 +229,9 @@ static int _main(int argc, char** argv) {
     }
 
     std::cout << printHash16or32(hash) << std::endl;
-    if (printPath) std::cout << storePath << std::endl;
+    if (printPath) {
+      std::cout << storePath << std::endl;
+    }
 
     return 0;
   }