diff --git a/CHANGELOG.md b/CHANGELOG.md index fe87e4a97..b63cf5ac0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +## [2.5.1] + +### Windows Fixes + +- Resolved issues with windows downloading logic +- Resolved issues with windows path resolution in static asset serving + ## [2.5.0] ### Spire Binary Size Reduction diff --git a/internal/assets/spire_assets.go b/internal/assets/spire_assets.go index 20e974dd0..d33ba53dc 100644 --- a/internal/assets/spire_assets.go +++ b/internal/assets/spire_assets.go @@ -55,7 +55,7 @@ func (a SpireAssets) ServeStatic() echo.MiddlewareFunc { // serve return appmiddleware.StaticAsset(appmiddleware.StaticConfig{ Root: "/", - StripPrefix: "/eq-asset-preview-master", + StripPrefix: string(filepath.Separator) + "eq-asset-preview-master", Filesystem: http.Dir(r.ZippedPath), }) } diff --git a/internal/download/file.go b/internal/download/file.go index e0bae2dfe..30a0d90dc 100644 --- a/internal/download/file.go +++ b/internal/download/file.go @@ -16,12 +16,20 @@ func WithProgress(destinationPath, downloadUrl string) error { fmt.Printf("[Downloading] URL [%v]\n", downloadUrl) fmt.Printf("[Downloading] To [%v]\n\n", destinationPath) - tempDestinationPath := destinationPath + ".tmp" - req, _ := http.NewRequest("GET", downloadUrl, nil) - resp, _ := http.DefaultClient.Do(req) - defer resp.Body.Close() + //tempDestinationPath := destinationPath + ".tmp" + req, err := http.NewRequest("GET", downloadUrl, nil) + if err != nil { + return err + } + resp, err := http.DefaultClient.Do(req) + if err != nil { + return err + } - f, _ := os.OpenFile(tempDestinationPath, os.O_CREATE|os.O_WRONLY, 0644) + f, err := os.OpenFile(destinationPath, os.O_CREATE|os.O_WRONLY, 0644) + if err != nil { + return err + } bar := progressbar.NewOptions64( resp.ContentLength, @@ -37,10 +45,27 @@ func WithProgress(destinationPath, downloadUrl string) error { progressbar.OptionSetRenderBlankState(true), ) - io.Copy(io.MultiWriter(f, bar), resp.Body) - os.Rename(tempDestinationPath, destinationPath) + _, err = io.Copy(io.MultiWriter(f, bar), resp.Body) + if err != nil { + return err + } - fmt.Println("") + err = resp.Body.Close() + if err != nil { + return err + } + + err = f.Close() + if err != nil { + return err + } + + //err = os.Rename(tempDestinationPath, destinationPath) + //if err != nil { + // return err + //} + + fmt.Printf("\n") return nil } diff --git a/internal/github/github_source_downloader.go b/internal/github/github_source_downloader.go index ae3d3188b..17f53807a 100644 --- a/internal/github/github_source_downloader.go +++ b/internal/github/github_source_downloader.go @@ -47,7 +47,7 @@ func (g *GithubSourceDownloader) Source(org string, repo string, branch string, // repo params repoDir := g.GetSourcedDirPath(repo, branch) repoZipUrl := fmt.Sprintf("https://github.com/%v/%v/archive/%v.zip", org, repo, branch) - zipFileLocalLoc := fmt.Sprintf("%v/%v.zip", g.GetSourceRoot(), repo) + zipFileLocalLoc := filepath.Join(g.GetSourceRoot(), fmt.Sprintf("%v.zip", repo)) if forceRefresh { err := os.RemoveAll(repoDir) diff --git a/internal/unzip/unzip.go b/internal/unzip/unzip.go index 97636ba8c..ac7e9caf1 100644 --- a/internal/unzip/unzip.go +++ b/internal/unzip/unzip.go @@ -21,19 +21,17 @@ func New(src string, dest string) Unzip { func (uz Unzip) Extract() error { - fmt.Println("Extraction of " + uz.Src + " started!") + fmt.Println("[Zip] Extraction of [" + uz.Src + "] started!") r, err := zip.OpenReader(uz.Src) if err != nil { return err } - defer func() { - if err := r.Close(); err != nil { - panic(err) - } - }() - os.MkdirAll(uz.Dest, 0755) + err = os.MkdirAll(uz.Dest, 0755) + if err != nil { + return err + } // Closure to address file descriptors issue with all the deferred .Close() methods extractAndWriteFile := func(f *zip.File) error { @@ -41,11 +39,6 @@ func (uz Unzip) Extract() error { if err != nil { return err } - defer func() { - if err := rc.Close(); err != nil { - panic(err) - } - }() path := filepath.Join(uz.Dest, f.Name) if !strings.HasPrefix(path, filepath.Clean(uz.Dest)+string(os.PathSeparator)) { @@ -53,24 +46,36 @@ func (uz Unzip) Extract() error { } if f.FileInfo().IsDir() { - os.MkdirAll(path, f.Mode()) + err := os.MkdirAll(path, f.Mode()) + if err != nil { + return err + } } else { - os.MkdirAll(filepath.Dir(path), f.Mode()) + err := os.MkdirAll(filepath.Dir(path), f.Mode()) + if err != nil { + return err + } f, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, f.Mode()) if err != nil { return err } - defer func() { - if err := f.Close(); err != nil { - panic(err) - } - }() _, err = io.Copy(f, rc) if err != nil { return err } + + if err := f.Close(); err != nil { + if err != nil { + return err + } + } + } + + if err := rc.Close(); err != nil { + return err } + return nil } @@ -84,7 +89,12 @@ func (uz Unzip) Extract() error { } } - fmt.Println("Extraction of " + uz.Src + " finished!") + err = r.Close() + if err != nil { + return err + } + + fmt.Printf("[Zip] Extracted (%v) files in [%v]!\n\n", len(r.File), uz.Src) return nil } diff --git a/package.json b/package.json index 3e6c2a64b..9d1903373 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "spire", - "version": "2.5.0", + "version": "2.5.1", "repository": { "type": "git", "url": "https://github.com/Akkadius/spire.git"