diff --git a/main.go b/main.go index fbda0c6..73460e5 100644 --- a/main.go +++ b/main.go @@ -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) @@ -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 } diff --git a/utils/jdk/jdk.go b/utils/jdk/jdk.go index 5c7547d..1900c75 100644 --- a/utils/jdk/jdk.go +++ b/utils/jdk/jdk.go @@ -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())