[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
81/118: findRoots(): Prevent a call to lstat()
From: |
Ludovic Courtès |
Subject: |
81/118: findRoots(): Prevent a call to lstat() |
Date: |
Tue, 19 May 2015 14:45:49 +0000 |
civodul pushed a commit to branch nix
in repository guix.
commit 666c9b7108e460f0d3450015a3379bfeb3e3a497
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.
---
nix/libstore/gc.cc | 23 ++++++++++++++---------
1 files changed, 14 insertions(+), 9 deletions(-)
diff --git a/nix/libstore/gc.cc b/nix/libstore/gc.cc
index e869745..00bf152 100644
--- a/nix/libstore/gc.cc
+++ b/nix/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;
}
- 84/118: Remove ugly hack for detecting build environment setup errors, (continued)
- 84/118: Remove ugly hack for detecting build environment setup errors, Ludovic Courtès, 2015/05/19
- 85/118: Get rid of "killing <pid>" message for unused build hooks, Ludovic Courtès, 2015/05/19
- 93/118: Reduce verbosity, Ludovic Courtès, 2015/05/19
- 92/118: Propagate remote timeouts properly, Ludovic Courtès, 2015/05/19
- 87/118: Refactor, Ludovic Courtès, 2015/05/19
- 79/118: Allow regular files as GC roots, Ludovic Courtès, 2015/05/19
- 89/118: Doh, Ludovic Courtès, 2015/05/19
- 78/118: Remove some dead code, Ludovic Courtès, 2015/05/19
- 82/118: Eliminate redundant copy, Ludovic Courtès, 2015/05/19
- 95/118: Make hook shutdown more reliable, Ludovic Courtès, 2015/05/19
- 81/118: findRoots(): Prevent a call to lstat(),
Ludovic Courtès <=
- 101/118: On Linux, disable address space randomization, Ludovic Courtès, 2015/05/19
- 91/118: Use regular file GC roots if possible, Ludovic Courtès, 2015/05/19
- 102/118: Remove bogus comment, Ludovic Courtès, 2015/05/19
- 80/118: Make readDirectory() return inode / file type, Ludovic Courtès, 2015/05/19
- 94/118: Doh, Ludovic Courtès, 2015/05/19
- 96/118: fix disappearing bash arguments, Ludovic Courtès, 2015/05/19
- 104/118: createDirs(): Handle ‘path’ being a symlink, Ludovic Courtès, 2015/05/19
- 103/118: nix-daemon: Close unnecessary fd, Ludovic Courtès, 2015/05/19
- 97/118: Introduce allowedRequisites feature, Ludovic Courtès, 2015/05/19
- 113/118: Clean up temp roots in a more C++ way, Ludovic Courtès, 2015/05/19