diff --git a/go.mod b/go.mod index 00ab7813..c0a9a53a 100644 --- a/go.mod +++ b/go.mod @@ -16,7 +16,7 @@ require ( github.com/tatsushid/go-prettytable v0.0.0-20141013043238-ed2d14c29939 github.com/urfave/cli v0.0.0-20160620154522-6011f165dc28 go.uber.org/atomic v1.3.2 // indirect - go.uber.org/multierr v1.1.0 // indirect + go.uber.org/multierr v1.1.0 go.uber.org/zap v1.8.0 gopkg.in/yaml.v2 v2.2.1 gotest.tools v2.2.0+incompatible diff --git a/pkg/remote/remote.go b/pkg/remote/remote.go index 0f70dc4a..f81c44f7 100644 --- a/pkg/remote/remote.go +++ b/pkg/remote/remote.go @@ -6,8 +6,10 @@ import ( "fmt" "github.com/hashicorp/go-getter" "github.com/hashicorp/go-getter/helper/url" + "go.uber.org/multierr" "go.uber.org/zap" "gopkg.in/yaml.v2" + "os" "path/filepath" "strings" ) @@ -180,8 +182,10 @@ func (r *Remote) Fetch(goGetterSrc string) (string, error) { cached := false + // e.g. .helmfile/cache/https_github_com_cloudposse_helmfiles_git.ref=0.xx.0 getterDst := filepath.Join(cacheBaseDir, cacheKey) + // e.g. $PWD/.helmfile/cache/https_github_com_cloudposse_helmfiles_git.ref=0.xx.0 cacheDirPath := filepath.Join(r.Home, getterDst) r.Logger.Debugf("home: %s", r.Home) @@ -217,6 +221,10 @@ func (r *Remote) Fetch(goGetterSrc string) (string, error) { r.Logger.Debugf("downloading %s to %s", getterSrc, getterDst) if err := r.Getter.Get(r.Home, getterSrc, getterDst); err != nil { + rmerr := os.RemoveAll(cacheDirPath) + if rmerr != nil { + return "", multierr.Append(err, rmerr) + } return "", err } }