Style fix

This commit is contained in:
Eelco Dolstra 2018-03-20 17:33:45 +01:00
parent 668ac3ea2c
commit e0c1597910
No known key found for this signature in database
GPG key ID: 8170B4726D7198DE

View file

@ -10,8 +10,8 @@ using namespace nix;
typedef std::map<string,string> Channels; typedef std::map<string,string> Channels;
static auto channels = Channels{}; static Channels channels;
static auto channelsList = Path{}; static Path channelsList;
// Reads the list of channels. // Reads the list of channels.
static void readChannels() static void readChannels()
@ -52,7 +52,7 @@ static void addChannel(const string & url, const string & name)
writeChannels(); writeChannels();
} }
static auto profile = Path{}; static Path profile;
// Remove a channel. // Remove a channel.
static void removeChannel(const string & name) static void removeChannel(const string & name)
@ -64,7 +64,7 @@ static void removeChannel(const string & name)
runProgram(settings.nixBinDir + "/nix-env", true, { "--profile", profile, "--uninstall", name }); runProgram(settings.nixBinDir + "/nix-env", true, { "--profile", profile, "--uninstall", name });
} }
static auto nixDefExpr = Path{}; static Path nixDefExpr;
// Fetch Nix expressions and binary cache URLs from the subscribed channels. // Fetch Nix expressions and binary cache URLs from the subscribed channels.
static void update(const StringSet & channelNames) static void update(const StringSet & channelNames)
@ -74,7 +74,7 @@ static void update(const StringSet & channelNames)
auto store = openStore(); auto store = openStore();
// Download each channel. // Download each channel.
auto exprs = Strings{}; Strings exprs;
for (const auto & channel : channels) { for (const auto & channel : channels) {
auto name = channel.first; auto name = channel.first;
auto url = channel.second; auto url = channel.second;
@ -84,7 +84,7 @@ static void update(const StringSet & channelNames)
// We want to download the url to a file to see if it's a tarball while also checking if we // We want to download the url to a file to see if it's a tarball while also checking if we
// got redirected in the process, so that we can grab the various parts of a nix channel // got redirected in the process, so that we can grab the various parts of a nix channel
// definition from a consistent location if the redirect changes mid-download. // definition from a consistent location if the redirect changes mid-download.
auto effectiveUrl = string{}; std::string effectiveUrl;
auto dl = getDownloader(); auto dl = getDownloader();
auto filename = dl->downloadCached(store, url, false, "", Hash(), &effectiveUrl); auto filename = dl->downloadCached(store, url, false, "", Hash(), &effectiveUrl);
url = chomp(std::move(effectiveUrl)); url = chomp(std::move(effectiveUrl));
@ -99,9 +99,9 @@ static void update(const StringSet & channelNames)
cname = cname + (string) match[1]; cname = cname + (string) match[1];
} }
auto extraAttrs = string{}; std::string extraAttrs;
auto unpacked = false; bool unpacked = false;
if (std::regex_search(filename, std::regex("\\.tar\\.(gz|bz2|xz)$"))) { if (std::regex_search(filename, std::regex("\\.tar\\.(gz|bz2|xz)$"))) {
runProgram(settings.nixBinDir + "/nix-build", false, { "--no-out-link", "--expr", "import <nix/unpack-channel.nix> " runProgram(settings.nixBinDir + "/nix-build", false, { "--no-out-link", "--expr", "import <nix/unpack-channel.nix> "
"{ name = \"" + cname + "\"; channelName = \"" + name + "\"; src = builtins.storePath \"" + filename + "\"; }" }); "{ name = \"" + cname + "\"; channelName = \"" + name + "\"; src = builtins.storePath \"" + filename + "\"; }" });
@ -136,7 +136,7 @@ static void update(const StringSet & channelNames)
// Unpack the channel tarballs into the Nix store and install them // Unpack the channel tarballs into the Nix store and install them
// into the channels profile. // into the channels profile.
std::cerr << "unpacking channels...\n"; std::cerr << "unpacking channels...\n";
auto envArgs = Strings{ "--profile", profile, "--file", "<nix/unpack-channel.nix>", "--install", "--from-expression" }; Strings envArgs{ "--profile", profile, "--file", "<nix/unpack-channel.nix>", "--install", "--from-expression" };
for (auto & expr : exprs) for (auto & expr : exprs)
envArgs.push_back(std::move(expr)); envArgs.push_back(std::move(expr));
envArgs.push_back("--quiet"); envArgs.push_back("--quiet");
@ -173,12 +173,9 @@ int main(int argc, char ** argv)
nixDefExpr = home + "/.nix-defexpr"; nixDefExpr = home + "/.nix-defexpr";
// Figure out the name of the channels profile. // Figure out the name of the channels profile.
auto name = string{}; ;
auto pw = getpwuid(getuid()); auto pw = getpwuid(getuid());
if (!pw) std::string name = pw ? pw->pw_name : getEnv("USER", "");
name = getEnv("USER", "");
else
name = pw->pw_name;
if (name.empty()) if (name.empty())
throw Error("cannot figure out user name"); throw Error("cannot figure out user name");
profile = settings.nixStateDir + "/profiles/per-user/" + name + "/channels"; profile = settings.nixStateDir + "/profiles/per-user/" + name + "/channels";
@ -192,7 +189,7 @@ int main(int argc, char ** argv)
cUpdate, cUpdate,
cRollback cRollback
} cmd = cNone; } cmd = cNone;
auto args = std::vector<string>{}; std::vector<string> args;
parseCmdLine(argc, argv, [&](Strings::iterator & arg, const Strings::iterator & end) { parseCmdLine(argc, argv, [&](Strings::iterator & arg, const Strings::iterator & end) {
if (*arg == "--help") { if (*arg == "--help") {
showManPage("nix-channel"); showManPage("nix-channel");
@ -224,7 +221,7 @@ int main(int argc, char ** argv)
throw UsageError("'--add' requires one or two arguments"); throw UsageError("'--add' requires one or two arguments");
{ {
auto url = args[0]; auto url = args[0];
auto name = string{}; std::string name;
if (args.size() == 2) { if (args.size() == 2) {
name = args[1]; name = args[1];
} else { } else {
@ -253,7 +250,7 @@ int main(int argc, char ** argv)
case cRollback: case cRollback:
if (args.size() > 1) if (args.size() > 1)
throw UsageError("'--rollback' has at most one argument"); throw UsageError("'--rollback' has at most one argument");
auto envArgs = Strings{"--profile", profile}; Strings envArgs{"--profile", profile};
if (args.size() == 1) { if (args.size() == 1) {
envArgs.push_back("--switch-generation"); envArgs.push_back("--switch-generation");
envArgs.push_back(args[0]); envArgs.push_back(args[0]);