Skip to content

Commit 6c251a2

Browse files
committed
fix: find jdk home
1 parent 3e8c7f7 commit 6c251a2

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

main.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,12 @@ func commands() []cli.Command {
172172

173173
// Copy the jdk files to the installation directory
174174
temJavaHome := getJavaHome(jdktempfile)
175+
if file.Exists(temJavaHome) {
176+
err := os.RemoveAll(temJavaHome)
177+
if err != nil {
178+
panic(err)
179+
}
180+
}
175181
err = os.Rename(temJavaHome, filepath.Join(config.store, v))
176182
if err != nil {
177183
return fmt.Errorf("unzip failed: %w", err)
@@ -315,8 +321,8 @@ func commands() []cli.Command {
315321
func getJavaHome(jdkTempFile string) string {
316322
var javaHome string
317323
fs.WalkDir(os.DirFS(jdkTempFile), ".", func(path string, d fs.DirEntry, err error) error {
318-
if filepath.Base(path) == "java.exe" {
319-
temPath := strings.Replace(path, "bin/java.exe", "", -1)
324+
if filepath.Base(path) == "javac.exe" {
325+
temPath := strings.Replace(path, "bin/javac.exe", "", -1)
320326
javaHome = filepath.Join(jdkTempFile, temPath)
321327
return fs.SkipDir
322328
}

utils/jdk/jdk.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
package jdk
22

33
import (
4-
"io/ioutil"
5-
"github.com/ystyle/jvms/utils/file"
64
"fmt"
5+
"github.com/ystyle/jvms/utils/file"
6+
"os"
77
)
88

99
func GetInstalled(root string) []string {
1010
list := make([]string, 0)
11-
files, _ := ioutil.ReadDir(root)
11+
files, _ := os.ReadDir(root)
1212
for i := len(files) - 1; i >= 0; i-- {
1313
if files[i].IsDir() {
1414
list = append(list, files[i].Name())

0 commit comments

Comments
 (0)