sdkman / sdkman-cli

The SDKMAN! Command Line Interface
https://sdkman.io
Apache License 2.0
6.05k stars 628 forks source link

Bug: Permission denied when mv-ing the contents installer zip to ~/.sdkman #1086

Open JohnLBergqvist opened 2 years ago

JohnLBergqvist commented 2 years ago

Bug report When running the sdkman installer, the mv command contained in that script, sometimes fails with a Permission Denied error, yet the installer doesn't realise and continues on, seemginly completing successfully, but resulting in a corrupt sdkman install

To reproduce Install on Windows (Git bash) via curl curl -s "https://get.sdkman.io" | bash In my case, I had made sure that /c/Windows/ServiceProfiles/NetworkService/.sdkman was removed before running the above curl command:

Looking for a previous installation of SDKMAN...
Looking for unzip...
Looking for zip...
Looking for curl...
Looking for sed...
Installing SDKMAN scripts...
Create distribution directories...
Getting available candidates...
Prime the config file...
Download script archive...

######################################################################## 100.0%
######################################################################## 100.0%
Extract script archive...
Install scripts...
mv: cannot move '/c/Windows/ServiceProfiles/NetworkService/.sdkman/tmp/sdkman-5.15.0/src' to '/c/Windows/ServiceProfiles/NetworkService/.sdkman/src': Permission denied
Set version to 5.15.0 ...
Attempt update of interactive bash profile on regular UNIX...
Added sdkman init snippet to /c/Windows/ServiceProfiles/NetworkService/.bashrc
Attempt update of zsh profile...
Updated existing /c/Windows/ServiceProfiles/NetworkService/.zshrc

All done!
You are subscribed to the STABLE channel.
Please open a new terminal, or run the following in the existing one:
    source "/c/Windows/ServiceProfiles/NetworkService/.sdkman/bin/sdkman-init.sh"
Then issue the following command:
    sdk help
Enjoy!!!

Essentially, the bin & contrib were moved from the zip's location OK, just not he src directory, which means sourcing the sdk-init.sh script fails:

/c/Windows/ServiceProfiles/NetworkService/.sdkman/bin/sdkman-init.sh: line 199: __sdkman_echo_debug: command not found

I'm surprised that a permissions error exists, given the install script has literally only just created the directory... Simply re-running the install script was enough to work around the error, but as I'm using sdkman in an unattended/automated environment, this issue randomly appearing is a tad awkard to work-around, especially as the installer was happily exiting with 0.

Could the mv command be hardened somewhat to either retry the move, or simply quit, if it's unable to move the full contents of the zip?

System info

marc0der commented 2 years ago

Hi @JohnLBergqvist, it seems very odd that you get a permission denied error as the script should always be run as a standard user. Could it be that you have some antivirus software running that prevents bash from moving the files?

As a sidenote, I currently have a fix out on the beta channel that will prevent install and selfupdate scripts from continuing when an error occurred. Would you be able to test that to see if it solves that problem?

JohnLBergqvist commented 2 years ago

@marc0der I don't have any anti-virus software running (It's running on an Azure VM). I'm not sure how easily i'll be able to verify your changes though, as the problem doesn't always occur.

marc0der commented 2 years ago

@JohnLBergqvist, the bug that you reported above (script keeps running after error condition) was fixed by this commit and released on 1 April 2022. After this fix, the bug you reported can technically not happen anymore. Have you seen this occur since that date?

As for the permissions issue, this is beyond our control and is specific to your operating system. Please let me know if you experience any further occurrences of the error trapping issue. Otherwise, please feel free to close this bug report.

JohnLBergqvist commented 2 years ago

@marc0der Hi, unfortunately i'm still seeing this "permission deined" bug occur from time to time with SDKMAN 5.15.0 on Windows.

I first run sdk install maven 3.8.6

Installing: maven 3.8.6
mv: cannot move '/c/Windows/ServiceProfiles/NetworkService/.sdkman/tmp/out/apache-maven-3.8.6' to '/c/Windows/ServiceProfiles/NetworkService/.sdkman/candidates/maven/3.8.6': Permission denied
Done installing!

Unfortunately despite the above error, the sdk install command exits with 0 - which under the circumstances is still a bug - you should detect the file was unable to be moved and at least exit with non-zero here IMO.

If I then do sdk default maven 3.8.6, I then get this.

ln: failed to create symbolic link '/c/Windows/ServiceProfiles/NetworkService/.sdkman/candidates/maven/current': No such file or directory
Stop! Candidate version is not installed.

If I erase my sdkman directory and try again, then problem goes away, but you should still not display Done installing! and exit with 0 if clearly the sdk was not correctly installed.

The vast majority of the time, these all succeed as expected, yet sometimes I get this spurious permissions error.