summaryrefslogtreecommitdiffstats
path: root/src/bftw.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2024-02-01 09:46:04 -0500
committerTavian Barnes <tavianator@tavianator.com>2024-02-01 12:44:58 -0500
commit710c083ff02eb1cc5b8daa6778784f3d1cd3c08d (patch)
treef4cbbf9eca8b06f904d3bc58d9450de847becafc /src/bftw.c
parent76ffc8d30cb1160d55d855d8ac630a2b9075fbcf (diff)
downloadbfs-710c083ff02eb1cc5b8daa6778784f3d1cd3c08d.tar.xz
bftw: Don't immediately pin open directories
It is undesirable to close a directory that we haven't read yet to free up cache capacity, but it's worse to fail to open the next directory because too many upcoming directories are pinned. This could happen when sorting, because then we can't prioritize the already-opened ones.
Diffstat (limited to 'src/bftw.c')
-rw-r--r--src/bftw.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/src/bftw.c b/src/bftw.c
index b3c0ba7..e29bd27 100644
--- a/src/bftw.c
+++ b/src/bftw.c
@@ -659,8 +659,6 @@ static void bftw_file_set_dir(struct bftw_cache *cache, struct bftw_file *file,
file->fd = bfs_dirfd(dir);
bftw_cache_add(cache, file);
}
-
- bftw_cache_pin(cache, file);
}
/** Free a bftw_file. */
@@ -1318,7 +1316,7 @@ static int bftw_opendir(struct bftw_state *state) {
struct bftw_file *file = state->file;
state->dir = file->dir;
if (state->dir) {
- return 0;
+ goto pin;
}
if (bftw_build_path(state, NULL) != 0) {
@@ -1328,8 +1326,11 @@ static int bftw_opendir(struct bftw_state *state) {
state->dir = bftw_file_opendir(state, file, state->path);
if (!state->dir) {
state->direrror = errno;
+ return 0;
}
+pin:
+ bftw_cache_pin(&state->cache, file);
return 0;
}
@@ -1577,7 +1578,7 @@ static int bftw_gc(struct bftw_state *state, enum bftw_gc_flags flags) {
int ret = 0;
struct bftw_file *file = state->file;
- if (file && file->dir) {
+ if (file && state->dir) {
bftw_unpin_dir(state, file, true);
}
state->dir = NULL;