Simplify Entry.URLWithTrailingSlash implementation and usage

Signed-off-by: Dominik Braun <mail@dominikbraun.io>
pull/9095/head
Dominik Braun 5 years ago
parent 2ed0081b92
commit ea119d0dc5

@ -160,15 +160,13 @@ func (o *repoAddOptions) run(out io.Writer) error {
// 2. When the config is different require --force-update // 2. When the config is different require --force-update
if !o.forceUpdate && f.Has(o.name) { if !o.forceUpdate && f.Has(o.name) {
existing := f.Get(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 // 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 // one doesn't, the config is considered to be different even though they
// refer to the same repository. // refer to the same repository.
// Only fail with an error if the configs actually are different. // Only fail with an error if the configs actually are different.
if c.URLWithTrailingSlash() != existing.URLWithTrailingSlash() { if c != *existing && c.URLWithTrailingSlash() != existing.URLWithTrailingSlash() {
return errors.Errorf("repository name (%s) already exists, please specify a different name", o.name) return errors.Errorf("repository name (%s) already exists, please specify a different name", o.name)
} }
}
// The add is idempotent so do nothing // The add is idempotent so do nothing
fmt.Fprintf(out, "%q already exists with the same configuration, skipping\n", o.name) fmt.Fprintf(out, "%q already exists with the same configuration, skipping\n", o.name)

@ -296,9 +296,5 @@ func (e *Entry) String() string {
// URLWithTrailingSlash returns the repository URL with a trailing slash. // URLWithTrailingSlash returns the repository URL with a trailing slash.
// If the URL already ends with a slash, it will be returned unchanged. // If the URL already ends with a slash, it will be returned unchanged.
func (e *Entry) URLWithTrailingSlash() string { func (e *Entry) URLWithTrailingSlash() string {
if e.URL[len(e.URL)-1:] == "/" { return strings.TrimSuffix(e.URL, "/") + "/"
return e.URL
}
return e.URL + "/"
} }

Loading…
Cancel
Save