Skip to content

Commit

Permalink
Apply rule: first package found served (#546)
Browse files Browse the repository at this point in the history
* Apply rule: first package found served

* Update CHANGELOG
  • Loading branch information
mtojek authored Jun 24, 2020
1 parent 80aeb3f commit 5b436bf
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
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

0 comments on commit 5b436bf

Please sign in to comment.