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.cc45
3 files changed, 44 insertions, 35 deletions
diff --git a/src/nix-store/dotgraph.cc b/src/nix-store/dotgraph.cc
index 8b699f39b..577cadceb 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 8ca5c9c8d..425d61e53 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 f0ce0368a..153b84137 100644
--- a/src/nix-store/nix-store.cc
+++ b/src/nix-store/nix-store.cc
@@ -2,6 +2,10 @@
#include "derivations.hh"
#include "dotgraph.hh"
#include "globals.hh"
+#include "build-result.hh"
+#include "store-cast.hh"
+#include "gc-store.hh"
+#include "log-store.hh"
#include "local-store.hh"
#include "monitor-fd.hh"
#include "serve-protocol.hh"
@@ -208,8 +212,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(recursive, Hash::parseAny(hash, hashAlgo), name)));
}
@@ -238,7 +242,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));
@@ -277,7 +281,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;
@@ -427,11 +431,12 @@ static void opQuery(Strings opFlags, Strings opArgs)
store->computeFSClosure(
args, referrers, true, settings.gcKeepOutputs, settings.gcKeepDerivations);
- Roots roots = store->findRoots(false);
+ auto & gcStore = require<GcStore>(*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;
}
@@ -471,13 +476,15 @@ static void opReadLog(Strings opFlags, Strings opArgs)
{
if (!opFlags.empty()) throw UsageError("unknown flag");
+ auto & logStore = require<LogStore>(*store);
+
RunPager pager;
for (auto & i : opArgs) {
- auto path = store->followLinksToStorePath(i);
- auto log = store->getBuildLog(path);
+ auto path = logStore.followLinksToStorePath(i);
+ auto log = logStore.getBuildLog(path);
if (!log)
- throw Error("build log of derivation '%s' is not available", store->printStorePath(path));
+ throw Error("build log of derivation '%s' is not available", logStore.printStorePath(path));
std::cout << *log;
}
}
@@ -587,20 +594,22 @@ static void opGC(Strings opFlags, Strings opArgs)
if (!opArgs.empty()) throw UsageError("no arguments expected");
+ auto & gcStore = require<GcStore>(*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)
@@ -624,9 +633,11 @@ static void opDelete(Strings opFlags, Strings opArgs)
for (auto & i : opArgs)
options.pathsToDelete.insert(store->followLinksToStorePath(i));
+ auto & gcStore = require<GcStore>(*store);
+
GCResults results;
PrintFreed freed(true, results);
- store->collectGarbage(options, results);
+ gcStore.collectGarbage(options, results);
}
@@ -637,7 +648,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();
}
@@ -975,9 +986,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);