summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2021-03-10 10:32:58 -0500
committerTavian Barnes <tavianator@tavianator.com>2021-03-10 10:32:58 -0500
commit75950323dcf086e89e23e923fa1e2bd31f1c2f62 (patch)
tree447052f910b5ab638ad26ac2d7a8d7030368b4be
parentf979df9ab11a2d7bbc6be15bd1f2734510bb4cb4 (diff)
downloadbfs-75950323dcf086e89e23e923fa1e2bd31f1c2f62.tar.xz
bftw: Fix bftw_type() for broken links and BFS_STAT_FOLLOW
This fixes link target coloring for broken links with -L.
-rw-r--r--bftw.c16
-rw-r--r--color.c13
2 files changed, 17 insertions, 12 deletions
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);
diff --git a/color.c b/color.c
index b003cff..f04bdf5 100644
--- a/color.c
+++ b/color.c
@@ -850,24 +850,21 @@ static int print_path(CFILE *cfile, const struct BFTW *ftwbuf) {
/** Print a link target with the appropriate colors. */
static int print_link_target(CFILE *cfile, const struct BFTW *ftwbuf) {
- int ret = -1;
-
const struct bfs_stat *statbuf = bftw_cached_stat(ftwbuf, BFS_STAT_NOFOLLOW);
size_t len = statbuf ? statbuf->size : 0;
char *target = xreadlinkat(ftwbuf->at_fd, ftwbuf->at_path, len);
if (!target) {
- goto done;
+ return -1;
}
- if (!cfile->colors) {
+ int ret;
+ if (cfile->colors) {
+ ret = print_path_colored(cfile, target, ftwbuf, BFS_STAT_FOLLOW);
+ } else {
ret = dstrcat(&cfile->buffer, target);
- goto done;
}
- ret = print_path_colored(cfile, target, ftwbuf, BFS_STAT_FOLLOW);
-
-done:
free(target);
return ret;
}