Commit a3d56852 authored by joe2far's avatar joe2far

fix(helm): make repo remove clear cache

parent 56500729
......@@ -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 {
......
......@@ -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)
......
......@@ -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...)
......
......@@ -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 {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment