aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Magorsch <arzano@gentoo.org>2020-05-18 01:59:22 +0200
committerMax Magorsch <arzano@gentoo.org>2020-05-18 01:59:22 +0200
commitd26624b78e28992f14a91670b3b3c6155a6c24d8 (patch)
tree861c09a94a02aea83f07398b5015ce08e23d4326 /pkg/app/handler/packages/utils.go
parentRemove the space between the useflags (diff)
downloadsoko-d26624b78e28992f14a91670b3b3c6155a6c24d8.tar.gz
soko-d26624b78e28992f14a91670b3b3c6155a6c24d8.tar.bz2
soko-d26624b78e28992f14a91670b3b3c6155a6c24d8.zip
Hide global useflags that are defined locally
Signed-off-by: Max Magorsch <arzano@gentoo.org>
Diffstat (limited to 'pkg/app/handler/packages/utils.go')
-rw-r--r--pkg/app/handler/packages/utils.go25
1 files changed, 22 insertions, 3 deletions
diff --git a/pkg/app/handler/packages/utils.go b/pkg/app/handler/packages/utils.go
index 3553725..c2b22c1 100644
--- a/pkg/app/handler/packages/utils.go
+++ b/pkg/app/handler/packages/utils.go
@@ -247,7 +247,7 @@ func getParameterValue(parameterName string, r *http.Request) string {
// getPackageUseflags retrieves all local USE flags, global USE
// flags and use expands for a given package
func getPackageUseflags(gpackage *models.Package) ([]models.Useflag, []models.Useflag, map[string][]models.Useflag) {
- var localUseflags, globalUseflags []models.Useflag
+ var localUseflags, allGlobalUseflags, filteredGlobalUseflags []models.Useflag
useExpands := make(map[string][]models.Useflag)
for _, rawUseflag := range gpackage.Versions[0].Useflags {
@@ -264,7 +264,7 @@ func getPackageUseflags(gpackage *models.Package) ([]models.Useflag, []models.Us
for _, useflag := range tmp_useflags {
if useflag.Scope == "global" {
- globalUseflags = append(globalUseflags, useflag)
+ allGlobalUseflags = append(allGlobalUseflags, useflag)
} else if useflag.Scope == "local" {
if useflag.Package == gpackage.Atom {
localUseflags = append(localUseflags, useflag)
@@ -277,8 +277,16 @@ func getPackageUseflags(gpackage *models.Package) ([]models.Useflag, []models.Us
}
}
}
+
+ // Only add global useflags that are not present in the local useflags
+ for _, useflag := range allGlobalUseflags {
+ if !containsUseflag(useflag, localUseflags){
+ filteredGlobalUseflags = append(filteredGlobalUseflags, useflag)
+ }
+ }
+
}
- return localUseflags, globalUseflags, useExpands
+ return localUseflags, filteredGlobalUseflags, useExpands
}
// createPackageData creates the data used in the show package template
@@ -376,3 +384,14 @@ func sortVersionsDesc(versions []*models.Version) {
return versions[i].CompareTo(*versions[j])
})
}
+
+// containsUseflag returns true if the given list of useflags contains the
+// given userflag. Otherwise false will be returned.
+func containsUseflag(useflag models.Useflag, useflags []models.Useflag) bool {
+ for _, flag := range useflags {
+ if useflag.Id == flag.Id {
+ return true
+ }
+ }
+ return false
+} \ No newline at end of file