Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add directory creation for installation path in install.sh#62

Merged
andy1li merged 4 commits intomainfrom
andy/tweak
Nov 26, 2025
Merged

Add directory creation for installation path in install.sh#62
andy1li merged 4 commits intomainfrom
andy/tweak

Conversation

@andy1li
Copy link
Member

@andy1li andy1li commented Nov 24, 2025

Context:

https://forum.codecrafters.io/t/build-your-own-shell-single-quote-permission-denied/15571/5

image

Also added an echo to explain why the script needs user's password:

image

Note

Ensure install.sh creates INSTALL_DIR (with sudo fallback) before moving the codecrafters binary.

Written by Cursor Bugbot for commit 2667a1a. This will update automatically on new commits. Configure here.

@andy1li andy1li self-assigned this Nov 24, 2025
@andy1li andy1li requested a review from rohitpaulk November 24, 2025 22:29
@andy1li
Copy link
Member Author

andy1li commented Nov 24, 2025

Thanks to @gillouche for highlighting the issue!

@andy1li andy1li removed the request for review from rohitpaulk November 24, 2025 22:31
@andy1li andy1li requested a review from rohitpaulk November 24, 2025 23:01
install.sh Outdated

chmod 0755 "$TEMP_FOLDER/codecrafters"

ASKED_FOR_PASSWORD=false # Don't want to ask for password more than once
Copy link
Member

Choose a reason for hiding this comment

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

We don't need to store this state, can just rely on the existing text above ("You will be prompted for your password by sudo if needed."). Most users are not going to run into this mkdir step anyway, so don't think we have to worry about this too much

@rohitpaulk
Copy link
Member

(Please send this back for review once again - want to take a look at the final change)

@andy1li andy1li requested a review from rohitpaulk November 26, 2025 09:57
install.sh Outdated
chmod 0755 "$TEMP_FOLDER/codecrafters"

if ! mkdir -p "$INSTALL_DIR" 2>/dev/null; then
echo "Password required to create directory ${INSTALL_DIR}"
Copy link
Member

Choose a reason for hiding this comment

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

@andy1li let's remove this message (and the one below) altogether - the message at the start of the script ("sudo will prompt if required") is sufficient.


if ! mkdir -p "$INSTALL_DIR" 2>/dev/null; then
sudo -k mkdir -p "$INSTALL_DIR"
fi
Copy link

Choose a reason for hiding this comment

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

Bug: Double password prompts when directory creation requires sudo

When the installation directory doesn't exist (the exact scenario this PR fixes), both mkdir and mv will require sudo. Since both commands use sudo -k, the second command's -k flag invalidates the credentials cached from the first command, causing the user to be prompted for their password twice. The -k flag forces credential re-entry; using plain sudo for at least one command would allow credential caching.

Additional Locations (1)

Fix in Cursor Fix in Web

Copy link
Member Author

Choose a reason for hiding this comment

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

@rohitpaulk Just curious, why did we have the -k flag in the first place? 🤔 I assume sudo without -k would prompt for the password as well?

@andy1li andy1li merged commit 34f1d55 into main Nov 26, 2025
3 checks passed
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.

2 participants