[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
105/376: findRoots(): Prevent a call to lstat()
From: |
Ludovic Courtès |
Subject: |
105/376: findRoots(): Prevent a call to lstat() |
Date: |
Wed, 28 Jan 2015 22:04:21 +0000 |
civodul pushed a commit to tag 1.8
in repository guix.
commit e0d7d0e45c5652bccc160ec49fc0c2c26d9c4d4e
Author: Eelco Dolstra <address@hidden>
Date: Fri Aug 1 17:20:25 2014 +0200
findRoots(): Prevent a call to lstat()
This means that getting the roots from /nix/var/nix/.../hydra-roots
doesn't need any I/O other than reading the directory.
---
src/libstore/gc.cc | 23 ++++++++++++++---------
1 files changed, 14 insertions(+), 9 deletions(-)
diff --git a/src/libstore/gc.cc b/src/libstore/gc.cc
index df6f26c..e583615 100644
--- a/src/libstore/gc.cc
+++ b/src/libstore/gc.cc
@@ -294,18 +294,23 @@ static void foundRoot(StoreAPI & store,
}
-static void findRoots(StoreAPI & store, const Path & path, Roots & roots)
+static void findRoots(StoreAPI & store, const Path & path, unsigned char type,
Roots & roots)
{
try {
- struct stat st = lstat(path);
+ if (type == DT_UNKNOWN) {
+ struct stat st = lstat(path);
+ if (S_ISDIR(st.st_mode)) type = DT_DIR;
+ else if (S_ISLNK(st.st_mode)) type = DT_LNK;
+ else if (S_ISREG(st.st_mode)) type = DT_REG;
+ }
- if (S_ISDIR(st.st_mode)) {
+ if (type == DT_DIR) {
for (auto & i : readDirectory(path))
- findRoots(store, path + "/" + i.name, roots);
+ findRoots(store, path + "/" + i.name, i.type, roots);
}
- else if (S_ISLNK(st.st_mode)) {
+ else if (type == DT_LNK) {
Path target = readLink(path);
if (isInStore(target))
foundRoot(store, path, target, roots);
@@ -327,7 +332,7 @@ static void findRoots(StoreAPI & store, const Path & path,
Roots & roots)
}
}
- else if (S_ISREG(st.st_mode)) {
+ else if (type == DT_REG) {
Path storePath = settings.nixStore + "/" + baseNameOf(path);
if (store.isValidPath(storePath))
roots[path] = storePath;
@@ -350,9 +355,9 @@ Roots LocalStore::findRoots()
Roots roots;
/* Process direct roots in {gcroots,manifests,profiles}. */
- nix::findRoots(*this, settings.nixStateDir + "/" + gcRootsDir, roots);
- nix::findRoots(*this, settings.nixStateDir + "/manifests", roots);
- nix::findRoots(*this, settings.nixStateDir + "/profiles", roots);
+ nix::findRoots(*this, settings.nixStateDir + "/" + gcRootsDir, DT_UNKNOWN,
roots);
+ nix::findRoots(*this, settings.nixStateDir + "/manifests", DT_UNKNOWN,
roots);
+ nix::findRoots(*this, settings.nixStateDir + "/profiles", DT_UNKNOWN,
roots);
return roots;
}
- 90/376: Implement nix-copy-closure --from via nix-store --serve, (continued)
- 90/376: Implement nix-copy-closure --from via nix-store --serve, Ludovic Courtès, 2015/01/28
- 97/376: Remove outdated AUTHORS file, Ludovic Courtès, 2015/01/28
- 92/376: Fix NIX_SSHOPTS, Ludovic Courtès, 2015/01/28
- 103/376: Allow regular files as GC roots, Ludovic Courtès, 2015/01/28
- 94/376: nix-copy-closure: Drop --bzip2, --xz, --show-progress, Ludovic Courtès, 2015/01/28
- 84/376: Use pthread_cancel instead of a signal, Ludovic Courtès, 2015/01/28
- 102/376: Restore default SIGPIPE handler before invoking ‘man’, Ludovic Courtès, 2015/01/28
- 98/376: nix-profile.sh: Set $SSL_CERT_FILE, Ludovic Courtès, 2015/01/28
- 96/376: nix-daemon: Pass on the user's $SSH_AUTH_SOCK to the SSH substituter, Ludovic Courtès, 2015/01/28
- 101/376: make clean: Remove Makefile.config, Ludovic Courtès, 2015/01/28
- 105/376: findRoots(): Prevent a call to lstat(),
Ludovic Courtès <=
- 108/376: Remove ugly hack for detecting build environment setup errors, Ludovic Courtès, 2015/01/28
- 107/376: Call commonChildInit() before doing chroot init, Ludovic Courtès, 2015/01/28
- 104/376: Make readDirectory() return inode / file type, Ludovic Courtès, 2015/01/28
- 106/376: Eliminate redundant copy, Ludovic Courtès, 2015/01/28
- 110/376: Make chroot builds easier to set up, Ludovic Courtès, 2015/01/28
- 109/376: Speed up nix-shell, Ludovic Courtès, 2015/01/28
- 121/376: nix-install-package: Use extra-binary-caches, Ludovic Courtès, 2015/01/28
- 119/376: Add support for order-only dependencies, Ludovic Courtès, 2015/01/28
- 118/376: install-nix-from-closure.sh: Use https channel if possible, Ludovic Courtès, 2015/01/28
- 114/376: Refactor, Ludovic Courtès, 2015/01/28