diff --git a/cmd/helm/repo.go b/cmd/helm/repo.go index 73c6b0235e260194833ac9395b169ee2de28bc12..b39e9713a6b01107d3fbfbd9d1af1c2aff9fc552 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 2f70484d571dd7aeb79be382e1b1d1a6fb623aa8..d24f6f594d4f5cb2a7a3fa6f081ae2f5686e87c9 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 fce4838f43aaf2ead394b7f18c399f6ce0702ac9..f1d40040af8210e3c6edf308871f42b38724c235 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 a7c633c549e2fb63e6f2a1bf8ebce0d73eb8e67c..86f656d88d5bb285c0c48582334ac65d1c6f9005 100644 --- a/cmd/helm/update.go +++ b/cmd/helm/update.go @@ -77,8 +77,7 @@ func updateCharts(repos map[string]string, verbose bool, out io.Writer) { 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 := fmt.Sprintf("...Unable to get an update from the %q chart repository", n) if verbose {