-
Notifications
You must be signed in to change notification settings - Fork 14
fix: replace dirname with parameter expansion for stripped PATH compatibility #2608
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -28,7 +28,7 @@ _ISSUE_SYNC_LIB_LOADED=1 | |||||||||||||
| # Source shared-constants.sh to make the library self-contained. | ||||||||||||||
| # Resolves SCRIPT_DIR from BASH_SOURCE so it works when sourced from any location. | ||||||||||||||
| if [[ -z "${SCRIPT_DIR:-}" ]]; then | ||||||||||||||
| SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | ||||||||||||||
| SCRIPT_DIR="$(cd "${BASH_SOURCE[0]%/*}" && pwd)" | ||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The parameter expansion A more robust approach is to check if the expansion modified the string and fall back to
Suggested change
|
||||||||||||||
| fi | ||||||||||||||
| source "${SCRIPT_DIR}/shared-constants.sh" | ||||||||||||||
|
|
||||||||||||||
|
|
||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -19,7 +19,7 @@ set -euo pipefail | |||||||||||||
|
|
||||||||||||||
| # --- Configuration --- | ||||||||||||||
|
|
||||||||||||||
| SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | ||||||||||||||
| SCRIPT_DIR="$(cd "${BASH_SOURCE[0]%/*}" && pwd)" | ||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The parameter expansion A more robust approach is to check if the expansion modified the string and fall back to
Suggested change
|
||||||||||||||
| MINER_DIR="${HOME}/.aidevops/.agent-workspace/work/session-miner" | ||||||||||||||
| # Shipped with aidevops; copied to workspace on first run | ||||||||||||||
| EXTRACTOR_SRC="${SCRIPT_DIR}/session-miner/extract.py" | ||||||||||||||
|
|
||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The parameter expansion
${BASH_SOURCE[0]%/*}can be problematic. If the script is invoked from thePATHwithout a directory prefix (e.g.,myscript.shinstead of./myscript.sh), this expansion results in the script's filename itself. The subsequentcdcommand will then fail because it's a file, not a directory.A more robust approach is to check if the expansion modified the string and fall back to
.if it didn't, which correctly handles all invocation scenarios.