fix(helm): make repo remove clear cache

pull/1109/head
joe2far 8 years ago
parent 5650072999
commit a3d56852f1

@ -20,6 +20,7 @@ import (
"errors" "errors"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"os"
"path/filepath" "path/filepath"
"github.com/gosuri/uitable" "github.com/gosuri/uitable"
@ -129,7 +130,7 @@ func index(dir, url string) error {
} }
func addRepository(name, 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()) 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 { if err := ioutil.WriteFile(repositoriesFile(), b, 0666); err != nil {
return err return err
} }
if err := removeRepoCache(name); err != nil {
return err
}
} else { } else {
return fmt.Errorf("The repository, %s, does not exist in your repositories list", name) 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 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 { func insertRepoLine(name, url string) error {
f, err := repo.LoadRepositoriesFile(repositoriesFile()) f, err := repo.LoadRepositoriesFile(repositoriesFile())
if err != nil { if err != nil {

@ -82,10 +82,17 @@ func TestRepoRemove(t *testing.T) {
t.Errorf("%s", err) t.Errorf("%s", err)
} }
mf, _ := os.Create(cacheIndexFile(testName))
mf.Close()
if err := removeRepoLine(testName); err != nil { if err := removeRepoLine(testName); err != nil {
t.Errorf("Error removing %s from repositories", testName) 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()) f, err := repo.LoadRepositoriesFile(repositoriesFile())
if err != nil { if err != nil {
t.Errorf("%s", err) t.Errorf("%s", err)

@ -43,6 +43,10 @@ func cacheDirectory(paths ...string) string {
return filepath.Join(fragments...) return filepath.Join(fragments...)
} }
func cacheIndexFile(repoName string) string {
return cacheDirectory(repoName + "-index.yaml")
}
func localRepoDirectory(paths ...string) string { func localRepoDirectory(paths ...string) string {
fragments := append([]string{repositoryDirectory(), localRepoPath}, paths...) fragments := append([]string{repositoryDirectory(), localRepoPath}, paths...)
return filepath.Join(fragments...) return filepath.Join(fragments...)

@ -62,8 +62,7 @@ func updateCharts(repos map[string]string, verbose bool) {
wg.Add(1) wg.Add(1)
go func(n, u string) { go func(n, u string) {
defer wg.Done() defer wg.Done()
indexFileName := cacheDirectory(n + "-index.yaml") err := repo.DownloadIndexFile(n, u, cacheIndexFile(n))
err := repo.DownloadIndexFile(n, u, indexFileName)
if err != nil { if err != nil {
updateErr := "...Unable to get an update from the " + n + " chart repository" updateErr := "...Unable to get an update from the " + n + " chart repository"
if verbose { if verbose {

Loading…
Cancel
Save