diff --git a/cmd/fdroidcl/download.go b/cmd/fdroidcl/download.go index f3937c7..42e128a 100644 --- a/cmd/fdroidcl/download.go +++ b/cmd/fdroidcl/download.go @@ -24,7 +24,7 @@ func runDownload(args []string) { } apps := findApps(args) for _, app := range apps { - apk := app.CurApk + apk := app.CurApk() url := apk.URL() path := apkPath(apk.ApkName) if err := downloadEtag(url, path, apk.Hash.Data); err != nil { diff --git a/cmd/fdroidcl/install.go b/cmd/fdroidcl/install.go index cf5f438..27b49f9 100644 --- a/cmd/fdroidcl/install.go +++ b/cmd/fdroidcl/install.go @@ -25,7 +25,7 @@ func runInstall(args []string) { apps := findApps(args) paths := make([]string, len(apps)) for i, app := range apps { - apk := app.CurApk + apk := app.CurApk() url := apk.URL() path := apkPath(apk.ApkName) if err := downloadEtag(url, path, apk.Hash.Data); err != nil { diff --git a/cmd/fdroidcl/search.go b/cmd/fdroidcl/search.go index 73929b8..c5da6d2 100644 --- a/cmd/fdroidcl/search.go +++ b/cmd/fdroidcl/search.go @@ -106,7 +106,7 @@ func printApps(apps []fdroidcl.App, inst map[string]adb.Package) { } func descVersion(app fdroidcl.App, inst *adb.Package) string { - cur := app.CurApk + cur := app.CurApk() if inst == nil { return fmt.Sprintf("%s (%d)", cur.VName, cur.VCode) } @@ -152,7 +152,7 @@ func filterAppsUpdates(apps []fdroidcl.App, inst map[string]adb.Package) []fdroi if !e { continue } - if p.VCode >= app.CurApk.VCode { + if p.VCode >= app.CurApk().VCode { continue } result = append(result, app) diff --git a/cmd/fdroidcl/show.go b/cmd/fdroidcl/show.go index 4d1796b..19a6617 100644 --- a/cmd/fdroidcl/show.go +++ b/cmd/fdroidcl/show.go @@ -64,7 +64,8 @@ func printAppDetailed(app fdroidcl.App) { p("Package :", "%s", app.ID) p("Name :", "%s", app.Name) p("Summary :", "%s", app.Summary) - p("Current Version :", "%s (%d)", app.CurApk.VName, app.CurApk.VCode) + cur := app.CurApk() + p("Current Version :", "%s (%d)", cur.VName, cur.VCode) p("Upstream Version :", "%s (%d)", app.CVName, app.CVCode) p("License :", "%s", app.License) if app.Categs != nil { diff --git a/index.go b/index.go index 93d7db3..34947bc 100644 --- a/index.go +++ b/index.go @@ -47,7 +47,6 @@ type App struct { Apks []Apk `xml:"package"` CVName string `xml:"marketversion"` CVCode int `xml:"marketvercode"` - CurApk *Apk `xml:"-"` } type IconDensity uint @@ -81,10 +80,11 @@ func getIconsDir(density IconDensity) string { } func (a *App) IconURLForDensity(density IconDensity) string { - if a.CurApk == nil { + cur := a.CurApk() + if cur == nil { return "" } - return fmt.Sprintf("%s/%s/%s", a.CurApk.Repo.URL, getIconsDir(density), a.Icon) + return fmt.Sprintf("%s/%s/%s", cur.Repo.URL, getIconsDir(density), a.Icon) } func (a *App) IconURL() string { @@ -236,16 +236,16 @@ func LoadIndexXml(r io.Reader) (*Index, error) { apk := &app.Apks[j] apk.Repo = &index.Repo } - app.calcCurApk() } return &index, nil } -func (app *App) calcCurApk() { - for _, apk := range app.Apks { - app.CurApk = &apk +func (app *App) CurApk() *Apk { + for i := range app.Apks { + apk := app.Apks[i] if app.CVCode >= apk.VCode { - break + return &apk } } + return nil }