fix(binary-installer): correct grep -q usage to avoid duplicate PATH / duplicate PATH entries#13410
Conversation
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
|
All contributors have signed the CLA ✍️ ✅ |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughReplaces command-substitution grep checks with direct exit-status tests, adds quoting around Changes
Estimated Code Review Effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
I have read the CLA Document and I hereby sign the CLA |
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
binary-installer/install.sh (1)
72-90:⚠️ Potential issue | 🟠 MajorRemove the duplicated
ifon line 72; it breaks fallback control flow.The double condition (
if [[ -r $SHELL_CONFIG ]]; then if [[ -r $SHELL_CONFIG ]]; then) causes theelseon line 77 to bind to the innerifinstead of the outer one. When.bash_profileis unreadable, the entireelseblock (lines 78–88) that handles fallback to.bash_loginand.profileis skipped, breaking the intended cascade through shell startup files.Proposed fix
SHELL_CONFIG=$HOME/.bash_profile - if [[ -r $SHELL_CONFIG ]]; then if [[ -r $SHELL_CONFIG ]]; then + if [[ -r $SHELL_CONFIG ]]; then if ! grep -q '.serverless/bin' "$SHELL_CONFIG"; then add_to_path $SHELL_CONFIG fi else SHELL_CONFIG=$HOME/.bash_login🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@binary-installer/install.sh` around lines 72 - 90, Remove the duplicated nested "if [[ -r $SHELL_CONFIG ]]" so the fallback else branch correctly pairs with the outer test; locate the block using the SHELL_CONFIG variable and add_to_path function references, delete the inner redundant if that starts the duplicate check, and ensure the remaining if/else cascade checks $HOME/.bash_profile then falls back to $HOME/.bash_login and $HOME/.profile while calling add_to_path when a target file does not already contain '.serverless/bin'.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@binary-installer/install.sh`:
- Around line 63-69: The script uses unquoted SHELL_CONFIG in assignments,
conditional tests and when calling add_to_path which can break on spaces or glob
chars; update all occurrences to quote the variable (e.g., use "SHELL_CONFIG" in
assignments, "[ ! -r "$SHELL_CONFIG" ]" and "grep -q '.serverless/bin'
"$SHELL_CONFIG"" tests, and call add_to_path "$SHELL_CONFIG") so every reference
to SHELL_CONFIG is wrapped in double quotes; ensure you update every use in the
if/else blocks and any other occurrences in the file (references: SHELL_CONFIG,
add_to_path, grep -q).
---
Outside diff comments:
In `@binary-installer/install.sh`:
- Around line 72-90: Remove the duplicated nested "if [[ -r $SHELL_CONFIG ]]" so
the fallback else branch correctly pairs with the outer test; locate the block
using the SHELL_CONFIG variable and add_to_path function references, delete the
inner redundant if that starts the duplicate check, and ensure the remaining
if/else cascade checks $HOME/.bash_profile then falls back to $HOME/.bash_login
and $HOME/.profile while calling add_to_path when a target file does not already
contain '.serverless/bin'.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 892ffadd-d22e-48b4-8c0e-572ca6c0453d
📒 Files selected for processing (1)
binary-installer/install.sh
…ofile fallback The doubled `if [[ -r "$SHELL_CONFIG" ]]; then` on the same line caused the else branch to bind to the inner if, making the fallback cascade to .bash_login and .profile unreachable when .bash_profile does not exist.
d122c20 to
109788a
Compare
|
@cursor review |
Bugbot couldn't runBugbot is not enabled for your user on this team. Ask your team administrator to increase your team's hard limit for Bugbot seats or add you to the allowlist in the Cursor dashboard. |
Problem
The installer script incorrectly checks for
.serverless/binin shell configuration files using command substitution with
grep -q.grep -qreturns an exit status but produces no output, so usingcommand substitution (
$()or backticks) always results in an emptystring. This causes the condition to always evaluate true and results
in duplicate PATH entries being appended on repeated installs.
Solution
Check the exit status of
grep -qdirectly instead of using commandsubstitution. Also added proper quoting for
$SHELL_CONFIG.Result
The installer now correctly avoids adding duplicate
.serverless/binentries to shell configuration files.
Fixes #13394
Summary by CodeRabbit