From 490b8bdfe2cf04b7e96fcdf9cc8c4382dddb7186 Mon Sep 17 00:00:00 2001 From: Wanderxjtu Date: Wed, 2 Aug 2023 16:28:10 +0800 Subject: [PATCH 1/2] install: create download folder only if file downloadable --- pkg/commands/install.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/pkg/commands/install.go b/pkg/commands/install.go index 0ec1e44..f1e5d7e 100644 --- a/pkg/commands/install.go +++ b/pkg/commands/install.go @@ -108,10 +108,6 @@ func install(source, version string) error { return nil } - if err := os.MkdirAll(targetDir, 0o755); err != nil { - return err - } - // Get download url rs := registedReleaseSources[source] @@ -135,6 +131,11 @@ func install(source, version string) error { return fmt.Errorf("server returned %v checking size of %v", http.StatusText(res.StatusCode), downloadURL) } + // Create download dir + if err := os.MkdirAll(targetDir, 0o755); err != nil { + return err + } + // Download base := path.Base(downloadURL) archiveFile := filepath.Join(targetDir, base) From 61ed1b5227a5edc7a9e826747f167fda3d6d640d Mon Sep 17 00:00:00 2001 From: Wanderxjtu Date: Wed, 2 Aug 2023 16:43:54 +0800 Subject: [PATCH 2/2] show: only show successfully installed version --- pkg/commands/show.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pkg/commands/show.go b/pkg/commands/show.go index fc2fb31..c364914 100644 --- a/pkg/commands/show.go +++ b/pkg/commands/show.go @@ -2,7 +2,6 @@ package commands import ( "fmt" - "io/ioutil" "os" "os/exec" "path/filepath" @@ -66,7 +65,7 @@ type goVer struct { } func listKusionVers() ([]goVer, error) { - files, err := ioutil.ReadDir(KusionupDir()) + files, err := os.ReadDir(KusionupDir()) if err != nil { return nil, err } @@ -79,7 +78,11 @@ func listKusionVers() ([]goVer, error) { var vers []goVer for _, file := range files { - if strings.HasPrefix(file.Name(), "kusion") { + if file.IsDir() && strings.HasPrefix(file.Name(), "kusion") { + if _, err := os.Stat(KusionupDir(file.Name(), unpackedOkay)); err != nil { + // only list successfully unpacked verions + continue + } vers = append(vers, goVer{ Ver: strings.TrimPrefix(file.Name(), "kusion-"), Current: current == file.Name(),