Browse Source

Always ensure that apps are sorted when loading an index

pull/8/head
Daniel Martí 11 years ago
parent
commit
383bef3914
  1. 8
      cmd/fdroidcl/main.go
  2. 9
      index.go

8
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)
}

9
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()

Loading…
Cancel
Save