summaryrefslogtreecommitdiffstats
path: root/bftw.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2016-02-20 17:10:19 -0500
committerTavian Barnes <tavianator@tavianator.com>2016-02-20 17:10:19 -0500
commit0193e24a32a3b3663cf8a55a89e3f2a1dcfa7ff7 (patch)
tree05d10c9e808c06b12142e810f1e26a4e2c34d2a4 /bftw.c
parent806e8504a374c7cf546a1ce0a81ed2ba954c3096 (diff)
downloadbfs-0193e24a32a3b3663cf8a55a89e3f2a1dcfa7ff7.tar.xz
bftw: Shrink the LRU before finding the parent.
Otherwise we might close the found parent.
Diffstat (limited to 'bftw.c')
-rw-r--r--bftw.c16
1 files changed, 6 insertions, 10 deletions
diff --git a/bftw.c b/bftw.c
index 22dfe41..34303c7 100644
--- a/bftw.c
+++ b/bftw.c
@@ -328,16 +328,14 @@ static bool dircache_should_retry(struct dircache *cache, const struct dircache_
static DIR *dircache_entry_open(struct dircache *cache, struct dircache_entry *entry, const char *path) {
assert(!entry->fd);
- DIR *dir = NULL;
+ if (cache->lru_remaining == 0) {
+ dircache_entry_close(cache, cache->lru_tail);
+ }
int at_fd = AT_FDCWD;
const char *at_path = path;
struct dircache_entry *base = dircache_entry_base(cache, entry, &at_fd, &at_path);
- if (cache->lru_remaining == 0) {
- dircache_entry_close(cache, cache->lru_tail);
- }
-
int flags = O_DIRECTORY;
int fd = openat(at_fd, at_path, flags);
@@ -345,7 +343,7 @@ static DIR *dircache_entry_open(struct dircache *cache, struct dircache_entry *e
fd = openat(at_fd, at_path, flags);
}
if (fd < 0) {
- goto done;
+ return NULL;
}
entry->fd = fd;
@@ -362,15 +360,13 @@ static DIR *dircache_entry_open(struct dircache *cache, struct dircache_entry *e
fd = dup(entry->fd);
}
if (fd < 0) {
- goto done;
+ return NULL;
}
- dir = fdopendir(fd);
+ DIR *dir = fdopendir(fd);
if (!dir) {
close(fd);
}
-
-done:
return dir;
}