From ea119d0dc58b0a999fe319390e98622f585ae3b8 Mon Sep 17 00:00:00 2001 From: Dominik Braun Date: Fri, 4 Dec 2020 23:15:45 +0100 Subject: [PATCH] Simplify Entry.URLWithTrailingSlash implementation and usage Signed-off-by: Dominik Braun --- cmd/helm/repo_add.go | 14 ++++++-------- pkg/repo/chartrepo.go | 6 +----- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/cmd/helm/repo_add.go b/cmd/helm/repo_add.go index 4c3e909d3..1e860aa27 100644 --- a/cmd/helm/repo_add.go +++ b/cmd/helm/repo_add.go @@ -160,14 +160,12 @@ func (o *repoAddOptions) run(out io.Writer) error { // 2. When the config is different require --force-update if !o.forceUpdate && f.Has(o.name) { existing := f.Get(o.name) - if c != *existing { - // In case of of the repo URLs ends with a trailing slash and the other - // one doesn't, the config is considered to be different even though they - // refer to the same repository. - // Only fail with an error if the configs actually are different. - if c.URLWithTrailingSlash() != existing.URLWithTrailingSlash() { - return errors.Errorf("repository name (%s) already exists, please specify a different name", o.name) - } + // In case of of the repo URLs ends with a trailing slash and the other + // one doesn't, the config is considered to be different even though they + // refer to the same repository. + // Only fail with an error if the configs actually are different. + if c != *existing && c.URLWithTrailingSlash() != existing.URLWithTrailingSlash() { + return errors.Errorf("repository name (%s) already exists, please specify a different name", o.name) } // The add is idempotent so do nothing diff --git a/pkg/repo/chartrepo.go b/pkg/repo/chartrepo.go index 3305bdf77..5a434eff7 100644 --- a/pkg/repo/chartrepo.go +++ b/pkg/repo/chartrepo.go @@ -296,9 +296,5 @@ func (e *Entry) String() string { // URLWithTrailingSlash returns the repository URL with a trailing slash. // If the URL already ends with a slash, it will be returned unchanged. func (e *Entry) URLWithTrailingSlash() string { - if e.URL[len(e.URL)-1:] == "/" { - return e.URL - } - - return e.URL + "/" + return strings.TrimSuffix(e.URL, "/") + "/" }