Skip to content

Commit

Permalink
cmd/install: Download and extract to tmp dir
Browse files Browse the repository at this point in the history
  • Loading branch information
jmooring committed Sep 10, 2023
1 parent 2ed9af3 commit 73ee7d2
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions cmd/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package cmd

import (
"fmt"
"log"
"os"
"path/filepath"
"runtime"
Expand Down Expand Up @@ -52,17 +53,10 @@ func init() {
// install sets the version of the Hugo executable to use when version
// management is disabled in the current directory.
func install() error {
repo, err := newRepository("gohugoio", "hugo")
if err != nil {
return err
}

asset, err := newAsset(runtime.GOOS, runtime.GOARCH)
if err != nil {
return err
}
repo := newRepository("gohugoio", "hugo")
asset := newAsset(runtime.GOOS, runtime.GOARCH)

err = asset.fetchTags(repo)
err := asset.fetchTags(repo)
if err != nil {
return err
}
Expand All @@ -87,12 +81,28 @@ func install() error {
return err
}

asset.archiveDirPath, err = os.MkdirTemp("", "")
if err != nil {
return err
}
defer func() {
err := os.RemoveAll(asset.archiveDirPath)
if err != nil {
log.Fatal(err)
}
}()

err = asset.downloadAsset()
if err != nil {
return err
}

err = archive.Extract(asset.archivePath, filepath.Dir(asset.archivePath), true)
err = archive.Extract(asset.archiveFilePath, asset.archiveDirPath, true)
if err != nil {
return err
}

err = helpers.CopyDirectoryContent(asset.archiveDirPath, filepath.Join(cacheDir, asset.tag))
if err != nil {
return err
}
Expand Down

0 comments on commit 73ee7d2

Please sign in to comment.