Skip to content

macOS: consolidate the duplicated portable-find-executable detection - #3950

Draft
moflwi wants to merge 1 commit into
fix/macos-docker-mount-pathsfrom
cleanup/consolidate-portable-find
Draft

macOS: consolidate the duplicated portable-find-executable detection#3950
moflwi wants to merge 1 commit into
fix/macos-docker-mount-pathsfrom
cleanup/consolidate-portable-find

Conversation

@moflwi

@moflwi moflwi commented Aug 8, 2026

Copy link
Copy Markdown
Collaborator

Summary

`agent.sh`'s `_otel_find_type_executable` and `api.sh`'s `_otel_find_executables` each independently branched on `uname -s` Darwin to pick `-perm +111` (BSD find) vs `-executable` (GNU find) — same fact, duplicated, with the two definitions having drifted into slightly different shapes since each was fixed independently.

Moves the OS check to a single `_otel_find_executable_test` variable set once in `api.sh`. Both helpers now just splice it into their `find` invocation. Verified under `dash` that the unquoted-variable word-splitting works as intended (a zsh test run first gave a false negative, since zsh doesn't word-split unquoted variables by default).

Depends on #3947 (base branch, docker mount path fix).

Test plan

  • `dash -n` on both touched files (done locally)
  • Functional check under `dash`: both find invocations produce identical results to the pre-refactor Darwin/Linux branches

🤖 Generated with Claude Code

agent.sh's _otel_find_type_executable and api.sh's _otel_find_executables
each independently branched on uname -s Darwin to pick -perm +111 (BSD find)
vs -executable (GNU find) — same fact, duplicated, with the two definitions
drifting apart in shape as each was fixed in its own branch.

Moves the OS check to a single _otel_find_executable_test variable set once
in api.sh alongside the existing _otel_shell_home/_otel_shell_bin_home
Darwin checks. Both helpers now just splice it into their find invocation.
api.sh is unconditionally sourced before agent.sh uses the variable, so
ordering is not a concern.

Verified under dash (the two branch-specific find commands' actual argv,
extracted from the real function bodies) that the unquoted variable
word-splits into separate find arguments as intended, and that -perm +111
returns real results on this machine's system find matching the
un-refactored behavior.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@plengauer

Copy link
Copy Markdown
Owner

Hello, thanks for contributing for the first time!

@moflwi moflwi linked an issue Aug 8, 2026 that may be closed by this pull request
@plengauer
plengauer requested a lite review from Copilot August 9, 2026 19:59

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

This PR consolidates the platform-specific find “is executable” predicate so macOS (BSD find) vs Linux (GNU find) handling is defined once and reused by both api.sh and agent.sh.

Changes:

  • Introduces a shared _otel_find_executable_test predicate chosen by uname -s in api.sh.
  • Refactors _otel_find_executables in api.sh to use the shared predicate.
  • Refactors _otel_find_type_executable in agent.sh to use the shared predicate.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/usr/share/opentelemetry_shell/api.sh Defines _otel_find_executable_test once and uses it in _otel_find_executables to avoid duplicated Darwin branching.
src/usr/share/opentelemetry_shell/agent.sh Switches _otel_find_type_executable to use _otel_find_executable_test from api.sh to eliminate duplicated OS checks.
Suppressed comments (1)

src/usr/share/opentelemetry_shell/api.sh:1

  • uname -s is now executed three times during initialization. Consider caching once (e.g., _otel_uname_s=$(uname -s)) and reusing it for the subsequent conditionals to reduce process forks and ensure consistent evaluation.
#!/bin/false

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

# $_otel_find_executable_test (set by api.sh) is -executable on Linux and the portable -perm +111
# on Darwin, where BSD find errors out on -executable; that error would otherwise be silently
# swallowed by the redirect below and leave nothing to instrument
_otel_find_type_executable() { \find "$1" -maxdepth 1 -type "$2" $_otel_find_executable_test 2> /dev/null || \true; }
}
fi
_otel_find_executables() {
\find "$1" $_otel_find_executable_test -iname "$2"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MacOS support

3 participants