From 530b27df1e71852580d8b0d474543aeffe65618f Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 15 Dec 2005 21:11:39 +0000 Subject: * `nix-store --gc' prints out the number of bytes freed on stdout (even when it is interrupted by a signal). --- src/libstore/gc.cc | 8 ++++++-- src/libstore/gc.hh | 3 ++- src/libstore/store.cc | 5 +++-- src/libstore/store.hh | 2 +- 4 files changed, 12 insertions(+), 6 deletions(-) (limited to 'src/libstore') diff --git a/src/libstore/gc.cc b/src/libstore/gc.cc index bdaf2946ca58..cb808b6d1b68 100644 --- a/src/libstore/gc.cc +++ b/src/libstore/gc.cc @@ -303,9 +303,11 @@ static Paths topoSort(const PathSet & paths) } -void collectGarbage(GCAction action, PathSet & result) +void collectGarbage(GCAction action, PathSet & result, + unsigned long long & bytesFreed) { result.clear(); + bytesFreed = 0; bool gcKeepOutputs = queryBoolSetting("gc-keep-outputs", false); @@ -452,7 +454,9 @@ void collectGarbage(GCAction action, PathSet & result) printMsg(lvlInfo, format("deleting `%1%'") % *i); /* Okay, it's safe to delete. */ - deleteFromStore(*i); + unsigned long long freed; + deleteFromStore(*i, freed); + bytesFreed += freed; if (fdLock != -1) /* Write token to stale (deleted) lock file. */ diff --git a/src/libstore/gc.hh b/src/libstore/gc.hh index b6a367c4b330..eb1858729037 100644 --- a/src/libstore/gc.hh +++ b/src/libstore/gc.hh @@ -19,7 +19,8 @@ typedef enum { closure of) the roots. If `action' is `gcReturnDead', return the set of paths not reachable from the roots. If `action' is `gcDeleteDead', actually delete the latter set. */ -void collectGarbage(GCAction action, PathSet & result); +void collectGarbage(GCAction action, PathSet & result, + unsigned long long & bytesFreed); /* Register a temporary GC root. This root will automatically disappear when this process exits. WARNING: this function should diff --git a/src/libstore/store.cc b/src/libstore/store.cc index 281ccc4bf147..dc3625a1d5da 100644 --- a/src/libstore/store.cc +++ b/src/libstore/store.cc @@ -746,8 +746,9 @@ Path addTextToStore(const string & suffix, const string & s, } -void deleteFromStore(const Path & _path) +void deleteFromStore(const Path & _path, unsigned long long & bytesFreed) { + bytesFreed = 0; Path path(canonPath(_path)); assertStorePath(path); @@ -763,7 +764,7 @@ void deleteFromStore(const Path & _path) } txn.commit(); - deletePath(path); + deletePath(path, bytesFreed); } diff --git a/src/libstore/store.hh b/src/libstore/store.hh index 0f35ff0c626c..2d8018d5fabc 100644 --- a/src/libstore/store.hh +++ b/src/libstore/store.hh @@ -155,7 +155,7 @@ Path addTextToStore(const string & suffix, const string & s, const PathSet & references); /* Delete a value from the nixStore directory. */ -void deleteFromStore(const Path & path); +void deleteFromStore(const Path & path, unsigned long long & bytesFreed); void verifyStore(bool checkContents); -- cgit 1.4.1