diff options
-rw-r--r-- | bftw.c | 16 | ||||
-rw-r--r-- | color.c | 13 |
2 files changed, 17 insertions, 12 deletions
@@ -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); @@ -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; } |