From c7ce004912b62f24c177b58df17ffb8875ec36c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Fri, 22 May 2015 20:54:17 +0200 Subject: [PATCH] Load an index, not a repo --- cmd/fdroidcl/main.go | 22 +++++++++++----------- index.go | 26 +++++++++++++++++--------- 2 files changed, 28 insertions(+), 20 deletions(-) diff --git a/cmd/fdroidcl/main.go b/cmd/fdroidcl/main.go index 80198ff..c4728ce 100644 --- a/cmd/fdroidcl/main.go +++ b/cmd/fdroidcl/main.go @@ -157,12 +157,12 @@ func init() { } } -func mustLoadRepo(repoName string) *fdroidcl.Repo { - repo, err := fdroidcl.LoadRepo(repoName) +func mustLoadIndex(repoName string) *fdroidcl.Index { + index, err := fdroidcl.LoadIndex(repoName) if err != nil { log.Fatalf("Could not load apps: %v", err) } - return repo + return index } func mustInstalled(device adb.Device) []string { @@ -208,19 +208,19 @@ func main() { log.Fatalf("Could not update index: %v", err) } case "list": - repo := mustLoadRepo(repoName) - printApps(repo.Apps) + index := mustLoadIndex(repoName) + printApps(index.Apps) case "search": - repo := mustLoadRepo(repoName) - apps := filterAppsSearch(repo.Apps, args) + index := mustLoadIndex(repoName) + apps := filterAppsSearch(index.Apps, args) printApps(apps) case "show": - repo := mustLoadRepo(repoName) + index := mustLoadIndex(repoName) found := make(map[string]*fdroidcl.App, len(args)) for _, appID := range args { found[appID] = nil } - for _, app := range repo.Apps { + for _, app := range index.Apps { _, e := found[app.ID] if !e { continue @@ -243,10 +243,10 @@ func main() { fmt.Printf("%s - %s (%s)\n", device.Id, device.Model, device.Product) } case "installed": - repo := mustLoadRepo(repoName) + index := mustLoadIndex(repoName) device := oneDevice() installed := mustInstalled(device) - apps := filterAppsInstalled(repo.Apps, installed) + apps := filterAppsInstalled(index.Apps, installed) printApps(apps) default: log.Printf("Unrecognised command '%s'\n\n", cmd) diff --git a/index.go b/index.go index 6e1080a..9204fac 100644 --- a/index.go +++ b/index.go @@ -17,9 +17,17 @@ import ( "strings" ) -// Repo is an F-Droid repository holding apps and apks -type Repo struct { +type Index struct { Apps []App `xml:"application"` + Repo struct { + Name string `xml:"name,attr"` + PubKey string `xml:"pubkey,attr"` + Timestamp int `xml:"timestamp,attr"` + URL string `xml:"url,attr"` + Version int `xml:"version,attr"` + MaxAge int `xml:"maxage,attr"` + Description string `xml:"description"` + } `repo` } type CommaList []string @@ -223,7 +231,7 @@ 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) { +func LoadIndex(repoName string) (*Index, error) { path := indexPath(repoName) r, err := zip.OpenReader(path) if err != nil { @@ -247,16 +255,16 @@ func LoadRepo(repoName string) (*Repo, error) { break } - var repo Repo - if err := xml.Unmarshal(buf.Bytes(), &repo); err != nil { + var index Index + if err := xml.Unmarshal(buf.Bytes(), &index); err != nil { return nil, err } - sort.Sort(appList(repo.Apps)) + sort.Sort(appList(index.Apps)) - for i := range repo.Apps { - app := &repo.Apps[i] + for i := range index.Apps { + app := &index.Apps[i] app.prepareData() } - return &repo, nil + return &index, nil }