From 75950323dcf086e89e23e923fa1e2bd31f1c2f62 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Wed, 10 Mar 2021 10:32:58 -0500 Subject: bftw: Fix bftw_type() for broken links and BFS_STAT_FOLLOW This fixes link target coloring for broken links with -L. --- bftw.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'bftw.c') diff --git a/bftw.c b/bftw.c index 4c6c529..64b1120 100644 --- a/bftw.c +++ b/bftw.c @@ -698,12 +698,20 @@ const struct bfs_stat *bftw_cached_stat(const struct BFTW *ftwbuf, enum bfs_stat } enum bfs_type bftw_type(const struct BFTW *ftwbuf, enum bfs_stat_flags flags) { - if (ftwbuf->stat_flags & BFS_STAT_NOFOLLOW) { - if ((flags & BFS_STAT_NOFOLLOW) || ftwbuf->type != BFS_LNK) { + if (flags & BFS_STAT_NOFOLLOW) { + if (ftwbuf->type == BFS_LNK || (ftwbuf->stat_flags & BFS_STAT_NOFOLLOW)) { + return ftwbuf->type; + } + } else if (flags & BFS_STAT_TRYFOLLOW) { + if (ftwbuf->type != BFS_LNK || (ftwbuf->stat_flags & BFS_STAT_TRYFOLLOW)) { + return ftwbuf->type; + } + } else { + if (ftwbuf->type != BFS_LNK) { return ftwbuf->type; + } else if (ftwbuf->stat_flags & BFS_STAT_TRYFOLLOW) { + return BFS_ERROR; } - } else if ((flags & (BFS_STAT_NOFOLLOW | BFS_STAT_TRYFOLLOW)) == BFS_STAT_TRYFOLLOW || ftwbuf->type == BFS_LNK) { - return ftwbuf->type; } const struct bfs_stat *statbuf = bftw_stat(ftwbuf, flags); -- cgit v1.2.3