aboutsummaryrefslogtreecommitdiff
path: root/src/libstore/optimise-store.cc
diff options
context:
space:
mode:
authorWout Mertens <Wout.Mertens@gmail.com>2014-05-14 22:52:10 +0200
committerWout Mertens <Wout.Mertens@gmail.com>2014-05-14 22:52:10 +0200
commitd73ffc552f78e0d9048e3bcc1e84452d1e8d2ede (patch)
tree0273f4f7d4f73b92cd77a03f14f8170aee5d0c3f /src/libstore/optimise-store.cc
parente974f20c9811c3efe09cfca9bda7816f9091c0d5 (diff)
Use the inodes given by readdir directly
Diffstat (limited to 'src/libstore/optimise-store.cc')
-rw-r--r--src/libstore/optimise-store.cc38
1 files changed, 21 insertions, 17 deletions
diff --git a/src/libstore/optimise-store.cc b/src/libstore/optimise-store.cc
index 78174e177..ed4180190 100644
--- a/src/libstore/optimise-store.cc
+++ b/src/libstore/optimise-store.cc
@@ -39,22 +39,28 @@ struct MakeReadOnly
}
};
-// TODO Make this a map and keep count and size stats, for giggles
-void LocalStore::loadHashes(Hashes & hashes)
+LocalStore::InodeHash LocalStore::loadInodeHash()
{
printMsg(lvlDebug, "loading hash inodes in memory");
- Strings names = readDirectory(linksDir);
- foreach (Strings::iterator, i, names) {
- struct stat st;
- string path = linksDir + "/" + *i;
- if (lstat(path.c_str(), &st))
- throw SysError(format("getting attributes of path `%1%'") % path);
- hashes.insert(st.st_ino);
+ InodeHash hashes;
+
+ AutoCloseDir dir = opendir(linksDir.c_str());
+ if (!dir) throw SysError(format("opening directory `%1%'") % linksDir);
+
+ struct dirent * dirent;
+ while (errno = 0, dirent = readdir(dir)) { /* sic */
+ checkInterrupt();
+ // We don't care if we hit non-hash files, anything goes
+ hashes.insert(dirent->d_ino);
}
- printMsg(lvlDebug, format("loaded %1% hashes") % hashes.size());
+ if (errno) throw SysError(format("reading directory `%1%'") % linksDir);
+
+ printMsg(lvlInfo, format("loaded %1% hash inodes") % hashes.size());
+
+ return hashes;
}
-void LocalStore::optimisePath_(OptimiseStats & stats, const Path & path, Hashes & hashes)
+void LocalStore::optimisePath_(OptimiseStats & stats, const Path & path, InodeHash & hashes)
{
checkInterrupt();
@@ -183,15 +189,13 @@ void LocalStore::optimisePath_(OptimiseStats & stats, const Path & path, Hashes
void LocalStore::optimiseStore(OptimiseStats & stats)
{
PathSet paths = queryAllValidPaths();
- Hashes hashes;
-
- loadHashes(hashes);
+ InodeHash inodeHash = loadInodeHash();
foreach (PathSet::iterator, i, paths) {
addTempRoot(*i);
if (!isValidPath(*i)) continue; /* path was GC'ed, probably */
startNest(nest, lvlChatty, format("hashing files in `%1%'") % *i);
- optimisePath_(stats, *i, hashes);
+ optimisePath_(stats, *i, inodeHash);
}
}
@@ -199,9 +203,9 @@ void LocalStore::optimiseStore(OptimiseStats & stats)
void LocalStore::optimisePath(const Path & path)
{
OptimiseStats stats;
- Hashes hashes;
+ InodeHash inodeHash;
- if (settings.autoOptimiseStore) optimisePath_(stats, path, hashes);
+ if (settings.autoOptimiseStore) optimisePath_(stats, path, inodeHash);
}