Skip to content

Commit

Permalink
fix: find jdk home
Browse files Browse the repository at this point in the history
  • Loading branch information
ystyle committed Jun 29, 2023
1 parent 3e8c7f7 commit 6c251a2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
10 changes: 8 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,12 @@ func commands() []cli.Command {

// Copy the jdk files to the installation directory
temJavaHome := getJavaHome(jdktempfile)
if file.Exists(temJavaHome) {
err := os.RemoveAll(temJavaHome)
if err != nil {
panic(err)
}
}
err = os.Rename(temJavaHome, filepath.Join(config.store, v))
if err != nil {
return fmt.Errorf("unzip failed: %w", err)
Expand Down Expand Up @@ -315,8 +321,8 @@ func commands() []cli.Command {
func getJavaHome(jdkTempFile string) string {
var javaHome string
fs.WalkDir(os.DirFS(jdkTempFile), ".", func(path string, d fs.DirEntry, err error) error {
if filepath.Base(path) == "java.exe" {
temPath := strings.Replace(path, "bin/java.exe", "", -1)
if filepath.Base(path) == "javac.exe" {
temPath := strings.Replace(path, "bin/javac.exe", "", -1)
javaHome = filepath.Join(jdkTempFile, temPath)
return fs.SkipDir
}
Expand Down
6 changes: 3 additions & 3 deletions utils/jdk/jdk.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package jdk

import (
"io/ioutil"
"github.com/ystyle/jvms/utils/file"
"fmt"
"github.com/ystyle/jvms/utils/file"
"os"
)

func GetInstalled(root string) []string {
list := make([]string, 0)
files, _ := ioutil.ReadDir(root)
files, _ := os.ReadDir(root)
for i := len(files) - 1; i >= 0; i-- {
if files[i].IsDir() {
list = append(list, files[i].Name())
Expand Down

0 comments on commit 6c251a2

Please sign in to comment.