[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
58/64: Use the inodes given by readdir directly
From: |
Ludovic Courtès |
Subject: |
58/64: Use the inodes given by readdir directly |
Date: |
Mon, 05 Jan 2015 16:39:12 +0000 |
civodul pushed a commit to branch nix
in repository guix.
commit d73ffc552f78e0d9048e3bcc1e84452d1e8d2ede
Author: Wout Mertens <address@hidden>
Date: Wed May 14 22:52:10 2014 +0200
Use the inodes given by readdir directly
---
src/libstore/local-store.hh | 8 ++++----
src/libstore/optimise-store.cc | 38 +++++++++++++++++++++-----------------
2 files changed, 25 insertions(+), 21 deletions(-)
diff --git a/src/libstore/local-store.hh b/src/libstore/local-store.hh
index 71229f7..b335092 100644
--- a/src/libstore/local-store.hh
+++ b/src/libstore/local-store.hh
@@ -309,13 +309,13 @@ private:
void checkDerivationOutputs(const Path & drvPath, const Derivation & drv);
#if HAVE_TR1_UNORDERED_SET
- typedef std::tr1::unordered_set<ino_t> Hashes;
+ typedef std::tr1::unordered_set<ino_t> InodeHash;
#else
- typedef std::set<ino_t> Hashes;
+ typedef std::set<ino_t> InodeHash;
#endif
- void loadHashes(Hashes & hashes);
- void optimisePath_(OptimiseStats & stats, const Path & path, Hashes &
hashes);
+ InodeHash loadInodeHash();
+ void optimisePath_(OptimiseStats & stats, const Path & path, InodeHash &
inodeHash);
// Internal versions that are not wrapped in retry_sqlite.
bool isValidPath_(const Path & path);
diff --git a/src/libstore/optimise-store.cc b/src/libstore/optimise-store.cc
index 78174e1..ed41801 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);
}
- 46/64: Simplify multi-user installation instructions, (continued)
- 46/64: Simplify multi-user installation instructions, Ludovic Courtès, 2015/01/05
- 49/64: Add ubuntu 14.04, Ludovic Courtès, 2015/01/05
- 48/64: Don't install Upstart job on Fedora, Ludovic Courtès, 2015/01/05
- 51/64: Really fix the RPM builds, Ludovic Courtès, 2015/01/05
- 50/64: Fix RPM build, Ludovic Courtès, 2015/01/05
- 53/64: fix typo, Ludovic Courtès, 2015/01/05
- 52/64: Shortcut already-hardlinked files, Ludovic Courtès, 2015/01/05
- 54/64: nix-instantiate --eval: Apply auto-arguments if the result is a function, Ludovic Courtès, 2015/01/05
- 47/64: Fix Debian tests, Ludovic Courtès, 2015/01/05
- 60/64: Merge branch 'master' of github.com:wmertens/nix, Ludovic Courtès, 2015/01/05
- 58/64: Use the inodes given by readdir directly,
Ludovic Courtès <=
- 57/64: Remove redundant code, Ludovic Courtès, 2015/01/05
- 55/64: Prepare nix-mode to be uploaded to marmalade, Ludovic Courtès, 2015/01/05
- 56/64: Preload linked hashes to speed up lookups, Ludovic Courtès, 2015/01/05
- 63/64: lvlInfo -> lvlTalkative, Ludovic Courtès, 2015/01/05
- 42/64: When running as root, use build users by default, Ludovic Courtès, 2015/01/05
- 59/64: Shortcut store files before lstat, Ludovic Courtès, 2015/01/05
- 64/64: Merge commit '8d5f472f2c49c79a0d3ae2e506f4d4d76224b328' into nix, Ludovic Courtès, 2015/01/05
- 61/64: Remove tab, Ludovic Courtès, 2015/01/05
- 62/64: nix-store --optimise: Remove bogus statistics, Ludovic Courtès, 2015/01/05