From 383bef3914e705fc2513dfa446bd1a83b4b92a1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Fri, 22 May 2015 20:48:24 +0200 Subject: [PATCH] Always ensure that apps are sorted when loading an index --- cmd/fdroidcl/main.go | 8 -------- index.go | 9 +++++++++ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/cmd/fdroidcl/main.go b/cmd/fdroidcl/main.go index 01b101b..80198ff 100644 --- a/cmd/fdroidcl/main.go +++ b/cmd/fdroidcl/main.go @@ -8,7 +8,6 @@ import ( "fmt" "log" "os" - "sort" "strings" "github.com/mvdan/fdroidcl" @@ -63,12 +62,6 @@ func filterAppsInstalled(apps []fdroidcl.App, installed []string) []fdroidcl.App return result } -type appList []fdroidcl.App - -func (al appList) Len() int { return len(al) } -func (al appList) Swap(i, j int) { al[i], al[j] = al[j], al[i] } -func (al appList) Less(i, j int) bool { return al[i].ID < al[j].ID } - func printApp(app fdroidcl.App, IDLen int) { fmt.Printf("%s%s %s %s\n", app.ID, strings.Repeat(" ", IDLen-len(app.ID)), app.Name, app.CurApk.VName) @@ -82,7 +75,6 @@ func printApps(apps []fdroidcl.App) { maxIDLen = len(app.ID) } } - sort.Sort(appList(apps)) for _, app := range apps { printApp(app, maxIDLen) } diff --git a/index.go b/index.go index 92cecb7..6e1080a 100644 --- a/index.go +++ b/index.go @@ -13,6 +13,7 @@ import ( "io/ioutil" "net/http" "os" + "sort" "strings" ) @@ -216,6 +217,12 @@ func UpdateIndex(repoName, repoURL string) error { return nil } +type appList []App + +func (al appList) Len() int { return len(al) } +func (al appList) Swap(i, j int) { al[i], al[j] = al[j], al[i] } +func (al appList) Less(i, j int) bool { return al[i].ID < al[j].ID } + func LoadRepo(repoName string) (*Repo, error) { path := indexPath(repoName) r, err := zip.OpenReader(path) @@ -245,6 +252,8 @@ func LoadRepo(repoName string) (*Repo, error) { return nil, err } + sort.Sort(appList(repo.Apps)) + for i := range repo.Apps { app := &repo.Apps[i] app.prepareData()