Browse Source

Start using apps from multiple repos

pull/8/head
Daniel Martí 11 years ago
parent
commit
faf9594205
  1. 3
      cmd/fdroidcl/search.go
  2. 3
      cmd/fdroidcl/show.go
  3. 60
      cmd/fdroidcl/update.go
  4. 20
      index.go

3
cmd/fdroidcl/search.go

@ -37,8 +37,7 @@ func runSearch(args []string) {
if *installed || *updates {
device = mustOneDevice()
}
index := mustLoadIndex()
apps := filterAppsSearch(index.Apps, args)
apps := filterAppsSearch(mustLoadIndexes(), args)
instPkgs := mustInstalled(device)
if *installed {
apps = filterAppsInstalled(apps, instPkgs)

3
cmd/fdroidcl/show.go

@ -41,8 +41,7 @@ func appsMap(apps []fdroidcl.App) map[string]*fdroidcl.App {
}
func findApps(ids []string) []*fdroidcl.App {
index := mustLoadIndex()
apps := appsMap(index.Apps)
apps := appsMap(mustLoadIndexes())
result := make([]*fdroidcl.App, len(ids))
for i, id := range ids {
app, e := apps[id]

60
cmd/fdroidcl/update.go

@ -14,6 +14,7 @@ import (
"net/http"
"os"
"path/filepath"
"sort"
"github.com/mvdan/fdroidcl"
)
@ -43,6 +44,27 @@ func (r *repo) updateIndex() error {
return nil
}
func (r *repo) loadIndex() (*fdroidcl.Index, error) {
p := indexPath(r.ID)
f, err := os.Open(p)
if err != nil {
return nil, fmt.Errorf("could not open index: %v", err)
}
stat, err := f.Stat()
if err != nil {
return nil, fmt.Errorf("could not stat index: %v", err)
}
//pubkey, err := hex.DecodeString(repoPubkey)
//if err != nil {
// return nil, fmt.Errorf("could not decode public key: %v", err)
//}
index, err := fdroidcl.LoadIndexJar(f, stat.Size(), nil)
if err != nil {
return nil, fmt.Errorf("could not load index: %v", err)
}
return index, nil
}
func respEtag(resp *http.Response) string {
etags, e := resp.Header["Etag"]
if !e || len(etags) == 0 {
@ -106,24 +128,26 @@ func indexPath(name string) string {
return filepath.Join(mustConfig(), name+".jar")
}
func mustLoadIndex() *fdroidcl.Index {
r := mustOneRepo()
p := indexPath(r.ID)
f, err := os.Open(p)
if err != nil {
log.Fatalf("Could not open index file: %v", err)
}
stat, err := f.Stat()
if err != nil {
log.Fatalf("Could not stat index file: %v", err)
func mustLoadIndexes() []fdroidcl.App {
var m map[string]*fdroidcl.App
for _, r := range config.Repos {
index, err := r.loadIndex()
if err != nil {
log.Fatalf("Error while loading %s: %v", r.ID, err)
}
for _, a := range index.Apps {
_, e := m[a.ID]
if !e {
m[a.ID] = &a
continue
}
// TODO: merge apks
}
}
//pubkey, err := hex.DecodeString(repoPubkey)
//if err != nil {
// log.Fatalf("Could not decode public key: %v", err)
//}
index, err := fdroidcl.LoadIndexJar(f, stat.Size(), nil)
if err != nil {
log.Fatalf("Could not load index: %v", err)
apps := make([]fdroidcl.App, 0, len(m))
for _, a := range m {
apps = append(apps, *a)
}
return index
sort.Sort(fdroidcl.AppList(apps))
return apps
}

20
index.go

@ -208,17 +208,17 @@ func (a *Apk) SrcURL() string {
return fmt.Sprintf("%s/%s", a.Repo.URL, a.SrcName)
}
type appList []App
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 (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 }
type apkList []Apk
type ApkList []Apk
func (al apkList) Len() int { return len(al) }
func (al apkList) Swap(i, j int) { al[i], al[j] = al[j], al[i] }
func (al apkList) Less(i, j int) bool { return al[i].VCode > al[j].VCode }
func (al ApkList) Len() int { return len(al) }
func (al ApkList) Swap(i, j int) { al[i], al[j] = al[j], al[i] }
func (al ApkList) Less(i, j int) bool { return al[i].VCode > al[j].VCode }
func LoadIndexXml(r io.Reader) (*Index, error) {
var index Index
@ -227,11 +227,11 @@ func LoadIndexXml(r io.Reader) (*Index, error) {
return nil, err
}
sort.Sort(appList(index.Apps))
sort.Sort(AppList(index.Apps))
for i := range index.Apps {
app := &index.Apps[i]
sort.Sort(apkList(app.Apks))
sort.Sort(ApkList(app.Apks))
for j := range app.Apks {
apk := &app.Apks[j]
apk.Repo = &index.Repo

Loading…
Cancel
Save