Skip to content

Commit 34cf7f1

Browse files
authored
Reset SDKMAN_DIR if it has wrong owner
When `su`-ing to another user, environment variables carry over. As a result, `sdk` will point to the installation of the original user, not the one running the current shell. Thus: Reset `$SDKMAN_DIR` if the directory it points at belongs to a user other than the current one.
1 parent 9c03510 commit 34cf7f1

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/main/bash/sdkman-init.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ if [ -z "$SDKMAN_CANDIDATES_API" ]; then
2525
export SDKMAN_CANDIDATES_API="@SDKMAN_CANDIDATES_API@"
2626
fi
2727

28-
if [ -z "$SDKMAN_DIR" ]; then
28+
if [ -z "$SDKMAN_DIR" ] || [ $(ls -ld "${SDKMAN_DIR}" | awk '{ print $3 }') != $(whoami) ]; then
2929
export SDKMAN_DIR="$HOME/.sdkman"
3030
fi
3131

0 commit comments

Comments
 (0)