Skip to content

Commit

Permalink
[2.5.1] Windows Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Akkadius committed Dec 23, 2022
1 parent 5e2a532 commit e105b9e
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 31 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion internal/assets/spire_assets.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
})
}
41 changes: 33 additions & 8 deletions internal/download/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
}
2 changes: 1 addition & 1 deletion internal/github/github_source_downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
50 changes: 30 additions & 20 deletions internal/unzip/unzip.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,56 +21,61 @@ 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 {
rc, err := f.Open()
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)) {
return fmt.Errorf("%s: Illegal file path", path)
}

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
}

Expand All @@ -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
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "spire",
"version": "2.5.0",
"version": "2.5.1",
"repository": {
"type": "git",
"url": "https://github.com/Akkadius/spire.git"
Expand Down

0 comments on commit e105b9e

Please sign in to comment.