aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2012-08-01 19:01:50 -0400
committerEelco Dolstra <eelco.dolstra@logicblox.com>2012-08-01 19:01:50 -0400
commit1df702d34733e69599a6ae21cb366348a2534b7d (patch)
treeaf3509aa2cf03afa27ef5c08126404305db0ed01
parent234ce610e0671410cb8a9ce4d8725e55472e8d47 (diff)
removeUnusedLinks(): Print stats on disk space saved by hard linking
-rw-r--r--src/libstore/gc.cc17
1 files changed, 16 insertions, 1 deletions
diff --git a/src/libstore/gc.cc b/src/libstore/gc.cc
index 874efe4d3..a7547d079 100644
--- a/src/libstore/gc.cc
+++ b/src/libstore/gc.cc
@@ -581,6 +581,8 @@ void LocalStore::removeUnusedLinks()
AutoCloseDir dir = opendir(linksDir.c_str());
if (!dir) throw SysError(format("opening directory `%1%'") % linksDir);
+ unsigned long long actualSize = 0, unsharedSize = 0;
+
struct dirent * dirent;
while (errno = 0, dirent = readdir(dir)) {
checkInterrupt();
@@ -592,13 +594,26 @@ void LocalStore::removeUnusedLinks()
if (lstat(path.c_str(), &st) == -1)
throw SysError(format("statting `%1%'") % path);
- if (st.st_nlink != 1) continue;
+ if (st.st_nlink != 1) {
+ unsigned long long size = st.st_blocks * 512ULL;
+ actualSize += size;
+ unsharedSize += (st.st_nlink - 1) * size;
+ continue;
+ }
printMsg(lvlTalkative, format("deleting unused link `%1%'") % path);
if (unlink(path.c_str()) == -1)
throw SysError(format("deleting `%1%'") % path);
}
+
+ struct stat st;
+ if (stat(linksDir.c_str(), &st) == -1)
+ throw SysError(format("statting `%1%'") % linksDir);
+ unsigned long long overhead = st.st_blocks * 512ULL;
+
+ printMsg(lvlInfo, format("note: currently hard linking saves %.2f MiB")
+ % ((unsharedSize - actualSize - overhead) / (1024.0 * 1024.0)));
}