about summary refs log tree commit diff
path: root/third_party/nix/src/nix-channel/nix-channel.cc
diff options
context:
space:
mode:
authorVincent Ambo <tazjin@google.com>2020-05-19T19·47+0100
committerVincent Ambo <tazjin@google.com>2020-05-19T19·51+0100
commit39087321811e81e26a1a47d6967df1088dcf0e95 (patch)
tree57110be423eeb7869e9960466f4b17c0ea7cd961 /third_party/nix/src/nix-channel/nix-channel.cc
parentcf40d08908ede4061eb15513b770c98877844b8b (diff)
style(3p/nix): Final act in the brace-wrapping saga r/777
This last change set was generated by a full clang-tidy run (including
compilation):

    clang-tidy -p ~/projects/nix-build/ \
      -checks=-*,readability-braces-around-statements -fix src/*/*.cc

Actually running clang-tidy requires some massaging to make it play
nice with Nix + meson, I'll be adding a wrapper or something for that soon.
Diffstat (limited to 'third_party/nix/src/nix-channel/nix-channel.cc')
-rw-r--r--third_party/nix/src/nix-channel/nix-channel.cc30
1 files changed, 20 insertions, 10 deletions
diff --git a/third_party/nix/src/nix-channel/nix-channel.cc b/third_party/nix/src/nix-channel/nix-channel.cc
index ec72258b10aa..ae5e77e86db5 100644
--- a/third_party/nix/src/nix-channel/nix-channel.cc
+++ b/third_party/nix/src/nix-channel/nix-channel.cc
@@ -40,18 +40,22 @@ static void readChannels() {
 static void writeChannels() {
   auto channelsFD = AutoCloseFD{open(
       channelsList.c_str(), O_WRONLY | O_CLOEXEC | O_CREAT | O_TRUNC, 0644)};
-  if (!channelsFD)
+  if (!channelsFD) {
     throw SysError(format("opening '%1%' for writing") % channelsList);
-  for (const auto& channel : channels)
+  }
+  for (const auto& channel : channels) {
     writeFull(channelsFD.get(), channel.second + " " + channel.first + "\n");
+  }
 }
 
 // Adds a channel.
 static void addChannel(const string& url, const string& name) {
-  if (!regex_search(url, std::regex("^(file|http|https)://")))
+  if (!regex_search(url, std::regex("^(file|http|https)://"))) {
     throw Error(format("invalid channel URL '%1%'") % url);
-  if (!regex_search(name, std::regex("^[a-zA-Z0-9_][a-zA-Z0-9_\\.-]*$")))
+  }
+  if (!regex_search(name, std::regex("^[a-zA-Z0-9_][a-zA-Z0-9_\\.-]*$"))) {
     throw Error(format("invalid channel identifier '%1%'") % name);
+  }
   readChannels();
   channels[name] = url;
   writeChannels();
@@ -157,10 +161,12 @@ static void update(const StringSet& channelNames) {
   // Make the channels appear in nix-env.
   struct stat st;
   if (lstat(nixDefExpr.c_str(), &st) == 0) {
-    if (S_ISLNK(st.st_mode))
+    if (S_ISLNK(st.st_mode)) {
       // old-skool ~/.nix-defexpr
-      if (unlink(nixDefExpr.c_str()) == -1)
+      if (unlink(nixDefExpr.c_str()) == -1) {
         throw SysError(format("unlinking %1%") % nixDefExpr);
+      }
+    }
   } else if (errno != ENOENT) {
     throw SysError(format("getting status of %1%") % nixDefExpr);
   }
@@ -210,8 +216,9 @@ static int _main(int argc, char** argv) {
       case cNone:
         throw UsageError("no command specified");
       case cAdd:
-        if (args.size() < 1 || args.size() > 2)
+        if (args.size() < 1 || args.size() > 2) {
           throw UsageError("'--add' requires one or two arguments");
+        }
         {
           auto url = args[0];
           std::string name;
@@ -226,8 +233,9 @@ static int _main(int argc, char** argv) {
         }
         break;
       case cRemove:
-        if (args.size() != 1)
+        if (args.size() != 1) {
           throw UsageError("'--remove' requires one argument");
+        }
         removeChannel(args[0]);
         break;
       case cList:
@@ -235,15 +243,17 @@ static int _main(int argc, char** argv) {
           throw UsageError("'--list' expects no arguments");
         }
         readChannels();
-        for (const auto& channel : channels)
+        for (const auto& channel : channels) {
           std::cout << channel.first << ' ' << channel.second << '\n';
+        }
         break;
       case cUpdate:
         update(StringSet(args.begin(), args.end()));
         break;
       case cRollback:
-        if (args.size() > 1)
+        if (args.size() > 1) {
           throw UsageError("'--rollback' has at most one argument");
+        }
         Strings envArgs{"--profile", profile};
         if (args.size() == 1) {
           envArgs.push_back("--switch-generation");