mirror of
https://github.com/NixOS/nix.git
synced 2025-11-12 21:46:01 +01:00
Specialise for searching under $stateDir/{profiles,gcroots}
This commit is contained in:
parent
b4ab02ef13
commit
c788718de1
1 changed files with 39 additions and 20 deletions
|
|
@ -12,12 +12,14 @@
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <getopt.h>
|
||||||
|
|
||||||
namespace fs = std::filesystem;
|
namespace fs = std::filesystem;
|
||||||
using std::set, std::string;
|
using std::set, std::string;
|
||||||
|
|
||||||
struct GlobalOpts {
|
struct GlobalOpts {
|
||||||
fs::path storeDir;
|
fs::path storeDir = "/nix/store";
|
||||||
|
fs::path stateDir = "/nix/var/nix";
|
||||||
enum VerbosityLvl {
|
enum VerbosityLvl {
|
||||||
Quiet,
|
Quiet,
|
||||||
Verbose
|
Verbose
|
||||||
|
|
@ -36,22 +38,40 @@ GlobalOpts parseCmdLine(int argc, char** argv)
|
||||||
{
|
{
|
||||||
GlobalOpts res;
|
GlobalOpts res;
|
||||||
auto usage = [&]() {
|
auto usage = [&]() {
|
||||||
std::cerr << "Usage: " << string(argv[0]) << " [-v] [storeDir]" << std::endl;
|
std::cerr << "Usage: " << string(argv[0]) << " [--verbose|-v] [-s storeDir] [-d stateDir]" << std::endl;
|
||||||
exit(1);
|
exit(1);
|
||||||
};
|
};
|
||||||
auto args = std::vector<char*>(argv+1, argv+argc);
|
static struct option long_options[] = {
|
||||||
bool storeDirSet = false;
|
{ "verbose", no_argument, (int*)&res.verbosity, GlobalOpts::Verbose },
|
||||||
for (auto & arg : args) {
|
{ "store_dir", required_argument, 0, 's' },
|
||||||
if (string(arg) == "-v")
|
{ "state_dir", required_argument, 0, 'd' },
|
||||||
res.verbosity = GlobalOpts::Verbose;
|
};
|
||||||
else if (!storeDirSet) {
|
|
||||||
res.storeDir = arg;
|
int option_index = 0;
|
||||||
storeDirSet = true;
|
int opt_char;
|
||||||
}
|
while((opt_char = getopt_long(argc, argv, "vs:",
|
||||||
else usage();
|
long_options, &option_index)) != -1) {
|
||||||
|
switch (opt_char) {
|
||||||
|
case 0:
|
||||||
|
break;
|
||||||
|
break;
|
||||||
|
case '?':
|
||||||
|
usage();
|
||||||
|
break;
|
||||||
|
case 'v':
|
||||||
|
res.verbosity = GlobalOpts::Verbose;
|
||||||
|
break;
|
||||||
|
case 's':
|
||||||
|
res.storeDir = fs::path(optarg);
|
||||||
|
break;
|
||||||
|
case 'd':
|
||||||
|
res.stateDir = fs::path(optarg);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
std::cerr << "Got invalid char: " << (char)opt_char << std::endl;
|
||||||
|
abort();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
if (!storeDirSet)
|
|
||||||
usage();
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -151,12 +171,11 @@ TraceResult followPathsToStore(GlobalOpts opts, set<fs::path> roots)
|
||||||
int main(int argc, char * * argv)
|
int main(int argc, char * * argv)
|
||||||
{
|
{
|
||||||
GlobalOpts opts = parseCmdLine(argc, argv);
|
GlobalOpts opts = parseCmdLine(argc, argv);
|
||||||
set<fs::path> originalRoots;
|
set<fs::path> standardRoots = {
|
||||||
std::string currentLine;
|
opts.stateDir / fs::path("profiles"),
|
||||||
while (std::getline(std::cin, currentLine)) {
|
opts.stateDir / fs::path("gcroots"),
|
||||||
originalRoots.insert(fs::path(currentLine));
|
};
|
||||||
}
|
auto traceResult = followPathsToStore(opts, standardRoots);
|
||||||
auto traceResult = followPathsToStore(opts, originalRoots);
|
|
||||||
for (auto & rootInStore : traceResult.storeRoots) {
|
for (auto & rootInStore : traceResult.storeRoots) {
|
||||||
std::cout << rootInStore.string() << std::endl;
|
std::cout << rootInStore.string() << std::endl;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue