Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply rule: first package found served #546

Merged
merged 3 commits into from
Jun 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Introduce development mode. [#543](https://github.com/elastic/package-registry/pull/543)
* Add additional supported categories to package. [#533](https://github.com/elastic/package-registry/pull/533)
* Add list of downloads to /search endpoint. [#512](https://github.com/elastic/package-registry/pull/512)
* Apply rule: first package found served. [#546](https://github.com/elastic/package-registry/pull/546)

### Deprecated

Expand Down
10 changes: 5 additions & 5 deletions categories.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ func categoriesHandler(packagesBasePaths []string, cacheTime time.Duration) func
}

// Check if the version exists and if it should be added or not.
if pp, ok := packageList[p.Name]; ok {
// If the package in the list is newer, do nothing. Otherwise delete and later add the new one.
if pp.IsNewer(p) {
continue
}
// If the package in the list is newer or equal, do nothing.
if pp, ok := packageList[p.Name]; ok && pp.IsNewerOrEqual(p) {
continue
}

// Otherwise delete and later add the new one.
packageList[p.Name] = p
}

Expand Down
5 changes: 3 additions & 2 deletions search.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,12 @@ func searchHandler(packagesBasePaths []string, cacheTime time.Duration) func(w h
for _, pp := range versions {
if pp.Name == p.Name {

// If the package in the list is newer, do nothing. Otherwise delete and later add the new one.
if pp.IsNewer(p) {
// If the package in the list is newer or equal, do nothing.
if pp.IsNewerOrEqual(p) {
continue
}

// Otherwise delete and later add the new one.
delete(packagesList[pp.Name], pp.Version)
}
}
Expand Down
4 changes: 2 additions & 2 deletions util/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,8 @@ func (p *Package) HasKibanaVersion(version *semver.Version) bool {
return true
}

func (p *Package) IsNewer(pp Package) bool {
return p.versionSemVer.GreaterThan(pp.versionSemVer)
func (p *Package) IsNewerOrEqual(pp Package) bool {
return !p.versionSemVer.LessThan(pp.versionSemVer)
}

// LoadAssets (re)loads all the assets of the package
Expand Down