summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2024-10-31 12:24:01 -0400
committerGitHub <noreply@github.com>2024-10-31 12:24:01 -0400
commite831a394426e19c39f94d9e8802aead7f25ba00d (patch)
tree04e9063206c54d9cad005903a5efbfe279a6826f
parent515cda3e3763484af448ad1bc599d583eeeadb18 (diff)
parent7152645618fc22766f5c954d12e9489866633e26 (diff)
downloadbfs-e831a394426e19c39f94d9e8802aead7f25ba00d.tar.xz
Merge pull request #146 from jody-frankowski/fix/capa-color-non-linux
Fix bfs coloring all files as if they had a capability, on non-Linux systems
-rw-r--r--src/color.c2
-rw-r--r--tests/bfs/color_ca.out4
-rw-r--r--tests/bfs/color_ca.sh10
-rw-r--r--tests/bfs/color_ca_incapable.out27
-rw-r--r--tests/bfs/color_ca_incapable.sh1
5 files changed, 43 insertions, 1 deletions
diff --git a/src/color.c b/src/color.c
index 036dda5..e7f0973 100644
--- a/src/color.c
+++ b/src/color.c
@@ -939,7 +939,7 @@ static const struct bfs_stat *cpath_stat(const struct cpath *cpath) {
/** Check if a path has non-trivial capabilities. */
static bool cpath_has_capabilities(const struct cpath *cpath) {
if (cpath->valid == cpath->len) {
- return bfs_check_capabilities(cpath->ftwbuf);
+ return bfs_check_capabilities(cpath->ftwbuf) > 0;
} else {
// TODO: implement capability checks for arbitrary paths
return false;
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