diff --git a/cmd/helm/repo.go b/cmd/helm/repo.go index 73c6b0235..b39e9713a 100644 --- a/cmd/helm/repo.go +++ b/cmd/helm/repo.go @@ -20,6 +20,7 @@ import ( "errors" "fmt" "io/ioutil" + "os" "path/filepath" "github.com/gosuri/uitable" @@ -129,7 +130,7 @@ func index(dir, url string) error { } func addRepository(name, url string) error { - if err := repo.DownloadIndexFile(name, url, cacheDirectory(name+"-index.yaml")); err != nil { + if err := repo.DownloadIndexFile(name, url, cacheIndexFile(name)); err != nil { return errors.New("Looks like " + url + " is not a valid chart repository or cannot be reached: " + err.Error()) } @@ -152,6 +153,9 @@ func removeRepoLine(name string) error { if err := ioutil.WriteFile(repositoriesFile(), b, 0666); err != nil { return err } + if err := removeRepoCache(name); err != nil { + return err + } } else { return fmt.Errorf("The repository, %s, does not exist in your repositories list", name) @@ -160,6 +164,16 @@ func removeRepoLine(name string) error { return nil } +func removeRepoCache(name string) error { + if _, err := os.Stat(cacheIndexFile(name)); err == nil { + err = os.Remove(cacheIndexFile(name)) + if err != nil { + return err + } + } + return nil +} + func insertRepoLine(name, url string) error { f, err := repo.LoadRepositoriesFile(repositoriesFile()) if err != nil { diff --git a/cmd/helm/repo_test.go b/cmd/helm/repo_test.go index 2f70484d5..d24f6f594 100644 --- a/cmd/helm/repo_test.go +++ b/cmd/helm/repo_test.go @@ -82,10 +82,17 @@ func TestRepoRemove(t *testing.T) { t.Errorf("%s", err) } + mf, _ := os.Create(cacheIndexFile(testName)) + mf.Close() + if err := removeRepoLine(testName); err != nil { t.Errorf("Error removing %s from repositories", testName) } + if _, err := os.Stat(cacheIndexFile(testName)); err == nil { + t.Errorf("Error cache file was not removed for repository %s", testName) + } + f, err := repo.LoadRepositoriesFile(repositoriesFile()) if err != nil { t.Errorf("%s", err) diff --git a/cmd/helm/structure.go b/cmd/helm/structure.go index fce4838f4..f1d40040a 100644 --- a/cmd/helm/structure.go +++ b/cmd/helm/structure.go @@ -43,6 +43,10 @@ func cacheDirectory(paths ...string) string { return filepath.Join(fragments...) } +func cacheIndexFile(repoName string) string { + return cacheDirectory(repoName + "-index.yaml") +} + func localRepoDirectory(paths ...string) string { fragments := append([]string{repositoryDirectory(), localRepoPath}, paths...) return filepath.Join(fragments...) diff --git a/cmd/helm/update.go b/cmd/helm/update.go index ecd4710da..1cbb56f34 100644 --- a/cmd/helm/update.go +++ b/cmd/helm/update.go @@ -62,8 +62,7 @@ func updateCharts(repos map[string]string, verbose bool) { wg.Add(1) go func(n, u string) { defer wg.Done() - indexFileName := cacheDirectory(n + "-index.yaml") - err := repo.DownloadIndexFile(n, u, indexFileName) + err := repo.DownloadIndexFile(n, u, cacheIndexFile(n)) if err != nil { updateErr := "...Unable to get an update from the " + n + " chart repository" if verbose {