halcyon / asdf-java

A Java plugin for asdf-vm.
MIT License
454 stars 86 forks source link

Problems on Windows #26

Closed empjustine closed 4 years ago

empjustine commented 4 years ago

Expected Behavior:

asdf install java 'adopt-openjdk-11.0.5+10_openj9-0.17.0'

New Java installed.

Current Behavior

asdf install java 'adopt-openjdk-11.0.5+10_openj9-0.17.0' will move all non-hidden, non-locked files in ${HOME} if the tarfile fails to expand.

Possible Solutions

Escape all shell variable expansions.

Use the special parameter -- to avoid confusing filenames with command parameters.

Make script use 'set -e', to abort instead of moving/destroying data.

Detailed logs

(captured with set -x in script)

++ basename https://github.com/AdoptOpenJDK/openjdk11-binaries/releases/download/jdk-11.0.5%2B10_openj9-0.17.0/OpenJDK11U-jdk_x64_windows_openj9_11.0.5_10_openj9-0.17.0.zip
+ tar zxf OpenJDK11U-jdk_x64_windows_openj9_11.0.5_10_openj9-0.17.0.zip
gzip: stdin has more than one entry--rest ignored
tar: Child returned status 2
tar: Error is not recoverable: exiting now
+++ ls -d '*/'
ls: cannot access '*/': No such file or directory
++ set --
++ echo
+ dir=
+ cd
+ mkdir -p /c/Users/emp.justine/.local/share/_asdf/installs/java/adopt-openjdk-11.0.5+10_openj9-0.17.0
+ case ${OS} in
+ mv '3D Objects' AppData 'Application Data' Contacts Cookies Desktop Documents Downloads Favorites IdeaProjects Links 'Local Settings' Music 'My Documents' NTUSER.DAT 'NTUSER.DAT{8e1aa5aa-c2c4-11e9-af24-9b12f01b32be}.TM.blf' 'NTUSER.DAT{8e1aa5aa-c2c4-11e9-af24-9b12f01b32be}.TMContainer00000000000000000001.regtrans-ms' 'NTUSER.DAT{8e1aa5aa-c2c4-11e9-af24-9b12f01b32be}.TMContainer00000000000000000002.regtrans-ms' NetHood Nox_share OneDrive Pictures PrintHood PycharmProjects Recent 'Saved Games' Searches SendTo 'Start Menu' Start.exe Sti_Trace.log Templates Videos ansel file.exe.stackdump inittk.ini inst.ini nice.exe.stackdump ntuser.dat.LOG1 ntuser.dat.LOG2 ntuser.ini nuuid.ini sh.exe.stackdump useruid.ini /c/Users/emp.justine/.local/share/_asdf/installs/java/adopt-openjdk-11.0.5+10_openj9-0.17.0
mv: cannot move 'AppData' to '/c/Users/emp.justine/.local/share/_asdf/installs/java/adopt-openjdk-11.0.5+10_openj9-0.17.0/AppData': Permission denied
mv: cannot move 'NTUSER.DAT' to '/c/Users/emp.justine/.local/share/_asdf/installs/java/adopt-openjdk-11.0.5+10_openj9-0.17.0/NTUSER.DAT': Device or resource busy
mv: cannot move 'NTUSER.DAT{8e1aa5aa-c2c4-11e9-af24-9b12f01b32be}.TM.blf' to '/c/Users/emp.justine/.local/share/_asdf/installs/java/adopt-openjdk-11.0.5+10_openj9-0.17.0/NTUSER.DAT{8e1aa5aa-c2c4-11e9-af24-9b12f01b32be}.TM.blf': Device or resource busy
mv: cannot move 'NTUSER.DAT{8e1aa5aa-c2c4-11e9-af24-9b12f01b32be}.TMContainer00000000000000000001.regtrans-ms' to '/c/Users/emp.justine/.local/share/_asdf/installs/java/adopt-openjdk-11.0.5+10_openj9-0.17.0/NTUSER.DAT{8e1aa5aa-c2c4-11e9-af24-9b12f01b32be}.TMContainer00000000000000000001.regtrans-ms': Device or resource busy
mv: cannot move 'NTUSER.DAT{8e1aa5aa-c2c4-11e9-af24-9b12f01b32be}.TMContainer00000000000000000002.regtrans-ms' to '/c/Users/emp.justine/.local/share/_asdf/installs/java/adopt-openjdk-11.0.5+10_openj9-0.17.0/NTUSER.DAT{8e1aa5aa-c2c4-11e9-af24-9b12f01b32be}.TMContainer00000000000000000002.regtrans-ms': Device or resource busy
mv: cannot move 'ntuser.dat.LOG1' to '/c/Users/emp.justine/.local/share/_asdf/installs/java/adopt-openjdk-11.0.5+10_openj9-0.17.0/ntuser.dat.LOG1': Device or resource busy
mv: cannot move 'ntuser.dat.LOG2' to '/c/Users/emp.justine/.local/share/_asdf/installs/java/adopt-openjdk-11.0.5+10_openj9-0.17.0/ntuser.dat.LOG2': Device or resource busy
+ cd /c/Users/emp.justine/.local/share/_asdf/plugins/java/bin
+ rm -rf /tmp/asdf-java.3wteNNs4

Context (Environment)

https://github.com/halcyon/asdf-java/blob/master/bin/functions#L113

dir is set to "", because $(set -- $(ls -d */) ; echo ${1}) failed

https://github.com/halcyon/asdf-java/blob/master/bin/functions#L114

cd ${dir} is the same as cd

https://github.com/halcyon/asdf-java/blob/master/bin/functions#L122

mv * ${ASDF_INSTALL_PATH} means merge everything in last path to single file.

halcyon commented 4 years ago

It's moving files out of your home directory because it failed to find mktemp, where it would normally do all its work in a temp directory. I'm pretty sure asdf doesn't officially support Windows, and at this time the asdf-java plugin officially supports linux and MacOS. You are welcome to attempt to add support for Windows if you'd like.

I'm not using set -e because the check-jq the check failing would cause the script to exit before the usage could be printed.

In the mean time, I can add a default case for unsupported operating systems that will exit early as opposed to damaging one's home directory.

empjustine commented 4 years ago

mktemp actually works, and it's set (in this example run) to /tmp/asdf-java.3wteNNs4

I think at least enabling set -e before the untar/move part (near the offending dir=$(set -- $(ls -d */) ; echo ${1}) line) would help a lot already.

I don't think attempting to progress if any of the following steps failed is safe in any environment after that point.

halcyon commented 4 years ago

I'll consider it. In the mean time, could you tell me what the result of running uname -s is on your system? I suspect your Windows system is not identifying itself as Windows. The untar is failing, because as your logs have indicated, it's not downloading a tar file - it's downloading a zip file.

halcyon commented 4 years ago

How does it know to look for the Windows build? The only options for it to set the OS variable to are "mac" and "linux". So if it sets it to one of those, then it would never be able to query for the Windows build. Could you tell me more about your environment? Did you modify the script?

empjustine commented 4 years ago

I had to modify the uname -s case with

    # MSYS2 MinGW 64-bit or 64-bit Git for Windows => MINGW64_NT-10.0-18362
    # MSYS2 MSYS =>  MSYS_NT-10.0-18362
    MINGW64_NT*|MSYS_NT*) OS="windows"
                          SHA256SUM="sha256sum"
                          STAT="stat -c %Z ${CACHE_DIR}/*"
                          TEMP_DIR="$(mktemp -dp /tmp 'asdf-java.XXXXXXXX')"
                          set -x
                          ;;

To get that part working. Also the reason why I had the set -x logs activated, to test what was gonna break next.

To get the symlinks working I first tried a shim exec shell script but that was a mess so I'm for now just using cp. Not sure how to solve this problem in a elegant and cross-platform way.

halcyon commented 4 years ago

@empjustine Please feel free to re-open this issue if you have any updates/PRs/etc. For now I'll be closing this issue (so that I can more readily see when new issues crop up). Thanks in advance for your understanding and efforts!

Kaylebor commented 4 years ago

Well, for me, not only is that issue happening too, but some downloads fail with a message like so:

❯ asdf install java adopt-openjdk-9.0.4+1
curl: no URL specified!
curl: try 'curl --help' or 'curl --manual' for more information

It's not consistent, since Java 10 and above fails with an error like described in this issue, complete with all not-dotfile elements on my home folder disappearing.

It also seems to happen only with AdoptOpenJDK versions: Amazon Corretto seems to install and work properly.

I looked into the uname fix by @empjustine, but when I run uname -s WSL already returns Linux...

Kaylebor commented 4 years ago

As an aside, I don't agree with that idea of closing an issue for increasing visibility of other issues, specially after just one or two months, and specially when there's currently only one single open issue right now.

I'd prefer tagging for that, if classifying issues is a problem; it's pretty easy to filter issues by their tags.

halcyon commented 4 years ago

@Kaylebor If you'd like to commit to resolve this issue, I'll gladly reopen it for you.

asdf does not officially support Windows, so it's difficult for me to consider this a real issue. While I won't object to a "fix", to leave this hanging around as if it's some issue for me to resolve does not seem fair.

There is only one single open issue because of the very fact that even though I have a full time job and am the maintainer of more than one open source project, when an issue is open I drop almost everything I'm doing and work on the issue until it is resolved. If I were to become accustomed to having issues open (especially one's that I can not resolve and don't expect to resolve) then I would be less likely to notice new issues, and issues would not be resolved as quickly as they are.

halcyon commented 4 years ago

@Kaylebor I use an API at https://adoptopenjdk.net/. Not every build of the JDK on adoptopenjdk.net is available for every platform.