mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-26 07:46:21 +02:00
nix-collect-garbage: Call collectGarbage() internally
This commit is contained in:
parent
4441e4cc13
commit
13493ef97c
4 changed files with 41 additions and 24 deletions
|
@ -342,4 +342,19 @@ RunPager::~RunPager()
|
|||
}
|
||||
|
||||
|
||||
string showBytes(unsigned long long bytes)
|
||||
{
|
||||
return (format("%.2f MiB") % (bytes / (1024.0 * 1024.0))).str();
|
||||
}
|
||||
|
||||
|
||||
PrintFreed::~PrintFreed()
|
||||
{
|
||||
if (show)
|
||||
std::cout << format("%1% store paths deleted, %2% freed\n")
|
||||
% results.paths.size()
|
||||
% showBytes(results.bytesFreed);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -83,4 +83,21 @@ private:
|
|||
|
||||
extern volatile ::sig_atomic_t blockInt;
|
||||
|
||||
|
||||
/* GC helpers. */
|
||||
|
||||
string showBytes(unsigned long long bytes);
|
||||
|
||||
class GCResults;
|
||||
|
||||
struct PrintFreed
|
||||
{
|
||||
bool show;
|
||||
const GCResults & results;
|
||||
PrintFreed(bool show, const GCResults & results)
|
||||
: show(show), results(results) { }
|
||||
~PrintFreed();
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
#include "store-api.hh"
|
||||
#include "hash.hh"
|
||||
#include "shared.hh"
|
||||
#include "globals.hh"
|
||||
|
@ -87,7 +88,13 @@ int main(int argc, char * * argv)
|
|||
if (removeOld) removeOldGenerations(profilesDir);
|
||||
|
||||
// Run the actual garbage collector.
|
||||
if (!dryRun) runProgramSimple(settings.nixBinDir + "/nix-store", Strings{"--gc"});
|
||||
if (!dryRun) {
|
||||
store = openStore(false);
|
||||
GCOptions options;
|
||||
options.action = GCOptions::gcDeleteDead;
|
||||
GCResults results;
|
||||
PrintFreed freed(true, results);
|
||||
store->collectGarbage(options, results);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -625,28 +625,6 @@ static void opCheckValidity(Strings opFlags, Strings opArgs)
|
|||
}
|
||||
|
||||
|
||||
static string showBytes(unsigned long long bytes)
|
||||
{
|
||||
return (format("%.2f MiB") % (bytes / (1024.0 * 1024.0))).str();
|
||||
}
|
||||
|
||||
|
||||
struct PrintFreed
|
||||
{
|
||||
bool show;
|
||||
const GCResults & results;
|
||||
PrintFreed(bool show, const GCResults & results)
|
||||
: show(show), results(results) { }
|
||||
~PrintFreed()
|
||||
{
|
||||
if (show)
|
||||
cout << format("%1% store paths deleted, %2% freed\n")
|
||||
% results.paths.size()
|
||||
% showBytes(results.bytesFreed);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
static void opGC(Strings opFlags, Strings opArgs)
|
||||
{
|
||||
bool printRoots = false;
|
||||
|
|
Loading…
Reference in a new issue