summaryrefslogtreecommitdiffstats
path: root/src/bftw.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2023-07-17 19:58:39 -0400
committerTavian Barnes <tavianator@tavianator.com>2023-07-17 20:03:33 -0400
commitd24941bb85f8ccc41a9894871e7cca7a02de066c (patch)
tree5670e58bc52132d953dce2349e09e36f7ef7c367 /src/bftw.c
parent196c36bb13de94c977a3e360dc5fa529efe2c5ca (diff)
downloadbfs-d24941bb85f8ccc41a9894871e7cca7a02de066c.tar.xz
bftw: Check that file->fd == bfs_dirfd(file->dir) earlier
This has the potential to fail on at least one known platform: macports with the legacysupport implementation of fdopendir(). Link: https://github.com/macports/macports-ports/pull/19047#issuecomment-1636059809
Diffstat (limited to 'src/bftw.c')
-rw-r--r--src/bftw.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/src/bftw.c b/src/bftw.c
index 9d85966..f8d0ac5 100644
--- a/src/bftw.c
+++ b/src/bftw.c
@@ -219,7 +219,6 @@ static void bftw_file_close(struct bftw_cache *cache, struct bftw_file *file) {
bfs_assert(file->pincount == 0);
if (file->dir) {
- bfs_assert(file->fd == bfs_dirfd(file->dir));
bfs_closedir(file->dir);
bftw_freedir(cache, file->dir);
file->dir = NULL;
@@ -354,7 +353,9 @@ static void bftw_file_set_dir(struct bftw_cache *cache, struct bftw_file *file,
bfs_assert(!file->dir);
file->dir = dir;
- if (file->fd < 0) {
+ if (file->fd >= 0) {
+ bfs_assert(file->fd == bfs_dirfd(dir));
+ } else {
file->fd = bfs_dirfd(dir);
bftw_cache_add(cache, file);
}