From 7152645618fc22766f5c954d12e9489866633e26 Mon Sep 17 00:00:00 2001 From: Jody Frankowski Date: Thu, 31 Oct 2024 13:13:20 +0100 Subject: color: Handle bfs_check_capabilities error code (-1) in cpath_has_capabilities On non-Linux systems, bfs_check_capabilities always returned -1, so cpath_has_capabilities would always return true. If bfs was called with an LS_COLORS containing the `ca` statement, e.g. `ca=30;41`, bfs would color ALL the files. While including the `ca` statement in LS_COLORS on non-Linux systems is unusual, this is not an error and is a valid use-case (e.g. Using GNU ls or lsd). Fixes: 1520d4d3 ("color: Don't color files like directories on ENOTDIR") --- tests/bfs/color_ca.out | 4 ++++ tests/bfs/color_ca.sh | 10 ++++++++++ tests/bfs/color_ca_incapable.out | 27 +++++++++++++++++++++++++++ tests/bfs/color_ca_incapable.sh | 1 + 4 files changed, 42 insertions(+) create mode 100644 tests/bfs/color_ca.out create mode 100644 tests/bfs/color_ca.sh create mode 100644 tests/bfs/color_ca_incapable.out create mode 100644 tests/bfs/color_ca_incapable.sh (limited to 'tests/bfs') diff --git a/tests/bfs/color_ca.out b/tests/bfs/color_ca.out new file mode 100644 index 0000000..bf74202 --- /dev/null +++ b/tests/bfs/color_ca.out @@ -0,0 +1,4 @@ +. +./link +./capable +./normal diff --git a/tests/bfs/color_ca.sh b/tests/bfs/color_ca.sh new file mode 100644 index 0000000..3aaaaf1 --- /dev/null +++ b/tests/bfs/color_ca.sh @@ -0,0 +1,10 @@ +test "$UNAME" = "Linux" || skip +invoke_bfs . -quit -capable || skip + +cd "$TEST" + +"$XTOUCH" normal capable +bfs_sudo setcap all+ep capable || skip +ln -s capable link + +LS_COLORS="ca=30;41:" bfs_diff . -color diff --git a/tests/bfs/color_ca_incapable.out b/tests/bfs/color_ca_incapable.out new file mode 100644 index 0000000..a439814 --- /dev/null +++ b/tests/bfs/color_ca_incapable.out @@ -0,0 +1,27 @@ +$'rainbow/\e[1m' +$'rainbow/\e[1m/'$'\e[0m' +rainbow +rainbow/exec.sh +rainbow/socket +rainbow/broken +rainbow/chardev_link +rainbow/link.txt +rainbow/sticky_ow +rainbow/sgid +rainbow/pipe +rainbow/ow +rainbow/sugid +rainbow/suid +rainbow/sticky +rainbow/file.dat +rainbow/file.txt +rainbow/lower.gz +rainbow/lower.tar +rainbow/lower.tar.gz +rainbow/lu.tar.GZ +rainbow/mh1 +rainbow/mh2 +rainbow/ul.TAR.gz +rainbow/upper.GZ +rainbow/upper.TAR +rainbow/upper.TAR.GZ diff --git a/tests/bfs/color_ca_incapable.sh b/tests/bfs/color_ca_incapable.sh new file mode 100644 index 0000000..f46a127 --- /dev/null +++ b/tests/bfs/color_ca_incapable.sh @@ -0,0 +1 @@ +LS_COLORS="ca=30;41:" bfs_diff rainbow -color -- cgit v1.2.3