Skip to content

Commit

Permalink
fix: use the correct cache path
Browse files Browse the repository at this point in the history
  • Loading branch information
ekristen committed Jan 23, 2025
1 parent d77a946 commit e88ad17
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 38 deletions.
9 changes: 2 additions & 7 deletions pkg/provider/gpg_asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/sirupsen/logrus"

"github.com/ekristen/distillery/pkg/asset"
"github.com/ekristen/distillery/pkg/common"
)

type GPGAsset struct {
Expand All @@ -33,18 +32,14 @@ func (a *GPGAsset) Path() string {
}

func (a *GPGAsset) Download(ctx context.Context) error {
cacheDir, err := os.UserCacheDir()
if err != nil {
return err
}

var err error
a.KeyID, err = a.MatchedAsset.GetGPGKeyID()
if err != nil {
logrus.WithError(err).Trace("unable to get GPG key")
return err
}

downloadsDir := filepath.Join(cacheDir, common.NAME, "downloads")
downloadsDir := a.Source.GetOptions().Config.GetDownloadsPath()
filename := strconv.FormatUint(a.KeyID, 10)

assetFile := filepath.Join(downloadsDir, filename)
Expand Down
1 change: 1 addition & 0 deletions pkg/provider/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ type ISource interface {
GetVersion() string
PreRun(context.Context) error
Run(context.Context) error
GetOptions() *Options
}
4 changes: 4 additions & 0 deletions pkg/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ func (p *Provider) GetVersion() string {
return "not-implemented"
}

func (p *Provider) GetOptions() *Options {
return p.Options
}

// CommonRun - common run logic for all sources that includes download, extract, install and cleanup
func (p *Provider) CommonRun(ctx context.Context) error {
if err := p.Download(ctx); err != nil {
Expand Down
7 changes: 1 addition & 6 deletions pkg/source/github_asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/sirupsen/logrus"

"github.com/ekristen/distillery/pkg/asset"
"github.com/ekristen/distillery/pkg/common"
)

type GitHubAsset struct {
Expand Down Expand Up @@ -43,11 +42,7 @@ func (a *GitHubAsset) Download(ctx context.Context) error {
logrus.Tracef("url: %s", url)
}

cacheDir, err := os.UserCacheDir()
if err != nil {
return err
}
downloadsDir := filepath.Join(cacheDir, common.NAME, "downloads")
downloadsDir := a.GitHub.Options.Config.GetDownloadsPath()

filename := a.ID()

Expand Down
7 changes: 1 addition & 6 deletions pkg/source/gitlab_asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,7 @@ func (a *GitLabAsset) Path() string {
}

func (a *GitLabAsset) Download(ctx context.Context) error { //nolint:dupl,nolintlint
cacheDir, err := os.UserCacheDir()
if err != nil {
return err
}

downloadsDir := filepath.Join(cacheDir, common.NAME, "downloads")
downloadsDir := a.GitLab.Options.Config.GetDownloadsPath()
filename := filepath.Base(a.Link.URL)

assetFile := filepath.Join(downloadsDir, filename)
Expand Down
7 changes: 1 addition & 6 deletions pkg/source/hashicorp_asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,7 @@ func (a *HashicorpAsset) Path() string {
}

func (a *HashicorpAsset) Download(ctx context.Context) error {
cacheDir, err := os.UserCacheDir()
if err != nil {
return err
}

downloadsDir := filepath.Join(cacheDir, common.NAME, "downloads")
downloadsDir := a.Hashicorp.Options.Config.GetDownloadsPath()
filename := filepath.Base(a.Build.URL)

assetFile := filepath.Join(downloadsDir, filename)
Expand Down
8 changes: 1 addition & 7 deletions pkg/source/homebrew_asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (

"github.com/ekristen/distillery/pkg/asset"
"github.com/ekristen/distillery/pkg/clients/homebrew"
"github.com/ekristen/distillery/pkg/common"
)

type HomebrewAsset struct {
Expand Down Expand Up @@ -71,12 +70,7 @@ func (a *HomebrewAsset) getAuthToken() (*GHCRAuth, error) {
}

func (a *HomebrewAsset) Download(ctx context.Context) error {
cacheDir, err := os.UserCacheDir()
if err != nil {
return err
}

downloadsDir := filepath.Join(cacheDir, common.NAME, "downloads")
downloadsDir := a.Homebrew.Options.Config.GetDownloadsPath()
filename := filepath.Base(a.Name + ".tar.gz")

assetFile := filepath.Join(downloadsDir, filename)
Expand Down
7 changes: 1 addition & 6 deletions pkg/source/http_asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,7 @@ func (a *HTTPAsset) Path() string {
}

func (a *HTTPAsset) Download(ctx context.Context) error {
cacheDir, err := os.UserCacheDir()
if err != nil {
return err
}

downloadsDir := filepath.Join(cacheDir, common.NAME, "downloads")
downloadsDir := a.Source.GetOptions().Config.GetDownloadsPath()
filename := filepath.Base(a.URL)

assetFile := filepath.Join(downloadsDir, filename)
Expand Down

0 comments on commit e88ad17

Please sign in to comment.