Add directory creation for installation path in install.sh#62
Conversation
|
Thanks to @gillouche for highlighting the issue! |
install.sh
Outdated
|
|
||
| chmod 0755 "$TEMP_FOLDER/codecrafters" | ||
|
|
||
| ASKED_FOR_PASSWORD=false # Don't want to ask for password more than once |
There was a problem hiding this comment.
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
|
(Please send this back for review once again - want to take a look at the final change) |
…ecrafters binary installation
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}" |
There was a problem hiding this comment.
@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 |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
@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?
Context:
https://forum.codecrafters.io/t/build-your-own-shell-single-quote-permission-denied/15571/5
Also added an echo to explain why the script needs user's password:
Note
Ensure
install.shcreatesINSTALL_DIR(with sudo fallback) before moving thecodecraftersbinary.Written by Cursor Bugbot for commit 2667a1a. This will update automatically on new commits. Configure here.