From 0193e24a32a3b3663cf8a55a89e3f2a1dcfa7ff7 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Sat, 20 Feb 2016 17:10:19 -0500 Subject: bftw: Shrink the LRU before finding the parent. Otherwise we might close the found parent. --- bftw.c | 16 ++++++---------- 1 file 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; } -- cgit v1.2.3