aboutsummaryrefslogtreecommitdiff
path: root/src/nix-store
diff options
context:
space:
mode:
Diffstat (limited to 'src/nix-store')
-rw-r--r--src/nix-store/dotgraph.cc26
-rw-r--r--src/nix-store/graphml.cc8
-rw-r--r--src/nix-store/nix-store.cc35
3 files changed, 37 insertions, 32 deletions
diff --git a/src/nix-store/dotgraph.cc b/src/nix-store/dotgraph.cc
index 45abe0405..36d774dca 100644
--- a/src/nix-store/dotgraph.cc
+++ b/src/nix-store/dotgraph.cc
@@ -10,37 +10,35 @@ using std::cout;
namespace nix {
-static string dotQuote(std::string_view s)
+static std::string dotQuote(std::string_view s)
{
return "\"" + std::string(s) + "\"";
}
-static string nextColour()
+static const std::string & nextColour()
{
static int n = 0;
- static string colours[] =
+ static std::vector<std::string> colours
{ "black", "red", "green", "blue"
, "magenta", "burlywood" };
- return colours[n++ % (sizeof(colours) / sizeof(string))];
+ return colours[n++ % colours.size()];
}
-static string makeEdge(const string & src, const string & dst)
+static std::string makeEdge(std::string_view src, std::string_view dst)
{
- format f = format("%1% -> %2% [color = %3%];\n")
- % dotQuote(src) % dotQuote(dst) % dotQuote(nextColour());
- return f.str();
+ return fmt("%1% -> %2% [color = %3%];\n",
+ dotQuote(src), dotQuote(dst), dotQuote(nextColour()));
}
-static string makeNode(const string & id, std::string_view label,
- const string & colour)
+static std::string makeNode(std::string_view id, std::string_view label,
+ std::string_view colour)
{
- format f = format("%1% [label = %2%, shape = box, "
- "style = filled, fillcolor = %3%];\n")
- % dotQuote(id) % dotQuote(label) % dotQuote(colour);
- return f.str();
+ return fmt("%1% [label = %2%, shape = box, "
+ "style = filled, fillcolor = %3%];\n",
+ dotQuote(id), dotQuote(label), dotQuote(colour));
}
diff --git a/src/nix-store/graphml.cc b/src/nix-store/graphml.cc
index 1cd974e41..d2eebca7a 100644
--- a/src/nix-store/graphml.cc
+++ b/src/nix-store/graphml.cc
@@ -19,20 +19,20 @@ static inline std::string_view xmlQuote(std::string_view s)
}
-static string symbolicName(const std::string & p)
+static std::string symbolicName(std::string_view p)
{
- return string(p, p.find('-') + 1);
+ return std::string(p.substr(0, p.find('-') + 1));
}
-static string makeEdge(std::string_view src, std::string_view dst)
+static std::string makeEdge(std::string_view src, std::string_view dst)
{
return fmt(" <edge source=\"%1%\" target=\"%2%\"/>\n",
xmlQuote(src), xmlQuote(dst));
}
-static string makeNode(const ValidPathInfo & info)
+static std::string makeNode(const ValidPathInfo & info)
{
return fmt(
" <node id=\"%1%\">\n"
diff --git a/src/nix-store/nix-store.cc b/src/nix-store/nix-store.cc
index 24a488d43..ad14ba9db 100644
--- a/src/nix-store/nix-store.cc
+++ b/src/nix-store/nix-store.cc
@@ -2,6 +2,8 @@
#include "derivations.hh"
#include "dotgraph.hh"
#include "globals.hh"
+#include "build-result.hh"
+#include "gc-store.hh"
#include "local-store.hh"
#include "monitor-fd.hh"
#include "serve-protocol.hh"
@@ -208,8 +210,8 @@ static void opPrintFixedPath(Strings opFlags, Strings opArgs)
Strings::iterator i = opArgs.begin();
HashType hashAlgo = parseHashType(*i++);
- string hash = *i++;
- string name = *i++;
+ std::string hash = *i++;
+ std::string name = *i++;
cout << fmt("%s\n", store->printStorePath(store->makeFixedOutputPath(name, FixedOutputInfo {
{
@@ -244,7 +246,7 @@ static StorePathSet maybeUseOutputs(const StorePath & storePath, bool useOutput,
graph. Topological sorting is used to keep the tree relatively
flat. */
static void printTree(const StorePath & path,
- const string & firstPad, const string & tailPad, StorePathSet & done)
+ const std::string & firstPad, const std::string & tailPad, StorePathSet & done)
{
if (!done.insert(path).second) {
cout << fmt("%s%s [...]\n", firstPad, store->printStorePath(path));
@@ -283,7 +285,7 @@ static void opQuery(Strings opFlags, Strings opArgs)
bool useOutput = false;
bool includeOutputs = false;
bool forceRealise = false;
- string bindingName;
+ std::string bindingName;
for (auto & i : opFlags) {
QueryType prev = query;
@@ -433,11 +435,12 @@ static void opQuery(Strings opFlags, Strings opArgs)
store->computeFSClosure(
args, referrers, true, settings.gcKeepOutputs, settings.gcKeepDerivations);
- Roots roots = store->findRoots(false);
+ auto & gcStore = requireGcStore(*store);
+ Roots roots = gcStore.findRoots(false);
for (auto & [target, links] : roots)
if (referrers.find(target) != referrers.end())
for (auto & link : links)
- cout << fmt("%1% -> %2%\n", link, store->printStorePath(target));
+ cout << fmt("%1% -> %2%\n", link, gcStore.printStorePath(target));
break;
}
@@ -593,20 +596,22 @@ static void opGC(Strings opFlags, Strings opArgs)
if (!opArgs.empty()) throw UsageError("no arguments expected");
+ auto & gcStore = requireGcStore(*store);
+
if (printRoots) {
- Roots roots = store->findRoots(false);
+ Roots roots = gcStore.findRoots(false);
std::set<std::pair<Path, StorePath>> roots2;
// Transpose and sort the roots.
for (auto & [target, links] : roots)
for (auto & link : links)
roots2.emplace(link, target);
for (auto & [link, target] : roots2)
- std::cout << link << " -> " << store->printStorePath(target) << "\n";
+ std::cout << link << " -> " << gcStore.printStorePath(target) << "\n";
}
else {
PrintFreed freed(options.action == GCOptions::gcDeleteDead, results);
- store->collectGarbage(options, results);
+ gcStore.collectGarbage(options, results);
if (options.action != GCOptions::gcDeleteDead)
for (auto & i : results.paths)
@@ -630,9 +635,11 @@ static void opDelete(Strings opFlags, Strings opArgs)
for (auto & i : opArgs)
options.pathsToDelete.insert(store->followLinksToStorePath(i));
+ auto & gcStore = requireGcStore(*store);
+
GCResults results;
PrintFreed freed(true, results);
- store->collectGarbage(options, results);
+ gcStore.collectGarbage(options, results);
}
@@ -643,7 +650,7 @@ static void opDump(Strings opFlags, Strings opArgs)
if (opArgs.size() != 1) throw UsageError("only one argument allowed");
FdSink sink(STDOUT_FILENO);
- string path = *opArgs.begin();
+ std::string path = *opArgs.begin();
dumpPath(path, sink);
sink.flush();
}
@@ -981,9 +988,9 @@ static void opGenerateBinaryCacheKey(Strings opFlags, Strings opArgs)
if (opArgs.size() != 3) throw UsageError("three arguments expected");
auto i = opArgs.begin();
- string keyName = *i++;
- string secretKeyFile = *i++;
- string publicKeyFile = *i++;
+ std::string keyName = *i++;
+ std::string secretKeyFile = *i++;
+ std::string publicKeyFile = *i++;
auto secretKey = SecretKey::generate(keyName);