Skip to content

Commit

Permalink
Merge pull request #146 from jody-frankowski/fix/capa-color-non-linux
Browse files Browse the repository at this point in the history
Fix bfs coloring all files as if they had a capability, on non-Linux systems
  • Loading branch information
tavianator authored Oct 31, 2024
2 parents 515cda3 + 7152645 commit e831a39
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/color.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions tests/bfs/color_ca.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.
./link
./capable
./normal
10 changes: 10 additions & 0 deletions tests/bfs/color_ca.sh
Original file line number Diff line number Diff line change
@@ -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
27 changes: 27 additions & 0 deletions tests/bfs/color_ca_incapable.out
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions tests/bfs/color_ca_incapable.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
LS_COLORS="ca=30;41:" bfs_diff rainbow -color

0 comments on commit e831a39

Please sign in to comment.