halcyon / asdf-java

A Java plugin for asdf-vm.
MIT License
470 stars 87 forks source link

asdf java commands can delete a lot of stuff #63

Closed aheritier closed 4 years ago

aheritier commented 4 years ago

I am not sure how I got firstly this error:

asdf list-all java
mkdir: /tmpasdf-java.cache: Read-only file system
/Users/arnaud/.asdf/plugins/java/bin/list-all: line 1: TEMP_DIR: unbound variable

Stupidly I created TEMP_DIR but messed up it and in a way that TEMP_DIR=$HOME

Calling it again ...

asdf list-all java
mkdir: /Users/arnaudasdf-java.cache: Permission denied
rm: /Users/arnaud/.config/htop: Permission denied
rm: /Users/arnaud/.config: Directory not empty
rm: /Users/arnaud/Music: Permission denied

The script started to delete my HOME !!!

There are 2 issues in your script from my POV:

https://github.com/halcyon/asdf-java/blob/680e8f72e1143c86ac0cc887fa6fb6e2674d8d19/bin/functions#L7

trap shouldn't be called without ensuring first that you created TEMP_DIR. That's why I got

TEMP_DIR: unbound variable

Then I would advise to name the variable ASDF_JAVA_TEMP_DIR or something like that to be sure that you don't conflict with an end-user variable called TEMP_DIR

Thanks