Skip to content

Commit b4c3201

Browse files
committed
color: Only highlight the trailing slash on ENOTDIR
1 parent 0e4dffe commit b4c3201

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

src/color.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -982,8 +982,10 @@ static ssize_t first_broken_offset(const char *path, const struct BFTW *ftwbuf,
982982
while (ret && at_path[len - 1] == '/') {
983983
--len, --ret;
984984
}
985-
while (ret && at_path[len - 1] != '/') {
986-
--len, --ret;
985+
if (errno != ENOTDIR) {
986+
while (ret && at_path[len - 1] != '/') {
987+
--len, --ret;
988+
}
987989
}
988990

989991
dstresize(&at_path, len);

tests/bfs/color_ls.out

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
scratch/foo/bar
33
/__bfs__/nowhere
44
/__bfs__/nowhere
5-
foo/bar/baz/qux
6-
foo/bar/baz/qux
75
foo/bar/nowhere
86
foo/bar/nowhere
97
foo/bar/nowhere/nothing
108
foo/bar/nowhere/nothing
119
foo/bar/baz
1210
foo/bar/baz
11+
foo/bar/baz//qux
12+
foo/bar/baz//qux

tests/bfs/color_ls.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ clean_scratch
33
ln -s foo/bar/baz scratch/link
44
ln -s foo/bar/nowhere scratch/broken
55
ln -s foo/bar/nowhere/nothing scratch/nested
6-
ln -s foo/bar/baz/qux scratch/notdir
6+
ln -s foo/bar/baz//qux scratch/notdir
77
ln -s scratch/foo/bar scratch/relative
88
mkdir scratch/__bfs__
99
ln -s /__bfs__/nowhere scratch/absolute
1010

11-
LS_COLORS="or=01;31:" invoke_bfs scratch/{,link,broken,nested,notdir,relative,absolute} -color -type l -ls \
11+
export LS_COLORS="or=01;31:"
12+
invoke_bfs scratch/{,link,broken,nested,notdir,relative,absolute} -color -type l -ls \
1213
| sed 's/.* -> //' \
1314
| sort >"$OUT"
14-
1515
diff_output

0 commit comments

Comments
 (0)