mirror of https://github.com/mvdan/fdroidcl.git
Browse Source
Now, install handles upgrades too. It will succeed if it can install a new app, upgrade an existing app, or if an app is already up to date. For the time being, this removes the "upgrade only if already installed" and "install only if not already installed" features, but those are very specific and likely not useful. They can be re-added as options if necessary. Fixes #23.pull/32/head
5 changed files with 34 additions and 93 deletions
@ -1,60 +0,0 @@
|
||||
// Copyright (c) 2015, Daniel Martí <mvdan@mvdan.cc>
|
||||
// See LICENSE for licensing information
|
||||
|
||||
package main |
||||
|
||||
import ( |
||||
"fmt" |
||||
|
||||
"mvdan.cc/fdroidcl" |
||||
"mvdan.cc/fdroidcl/adb" |
||||
) |
||||
|
||||
var cmdUpgrade = &Command{ |
||||
UsageLine: "upgrade <appid...>", |
||||
Short: "Upgrade an app", |
||||
} |
||||
|
||||
func init() { |
||||
cmdUpgrade.Run = runUpgrade |
||||
} |
||||
|
||||
func runUpgrade(args []string) error { |
||||
if len(args) < 1 { |
||||
return fmt.Errorf("no package names given") |
||||
} |
||||
apps, err := findApps(args) |
||||
if err != nil { |
||||
return err |
||||
} |
||||
device, err := oneDevice() |
||||
if err != nil { |
||||
return err |
||||
} |
||||
inst, err := device.Installed() |
||||
if err != nil { |
||||
return err |
||||
} |
||||
for _, app := range apps { |
||||
p, e := inst[app.ID] |
||||
if !e { |
||||
return fmt.Errorf("%s is not installed", app.ID) |
||||
} |
||||
suggested := app.SuggestedApk(device) |
||||
if suggested == nil { |
||||
return fmt.Errorf("no suitable APKs found for %s", app.ID) |
||||
} |
||||
if p.VCode >= suggested.VCode { |
||||
return fmt.Errorf("%s is up to date", app.ID) |
||||
} |
||||
} |
||||
return downloadAndDo(apps, device, upgradeApk) |
||||
} |
||||
|
||||
func upgradeApk(device *adb.Device, apk *fdroidcl.Apk, path string) error { |
||||
fmt.Fprintf(stdout, "Upgrading %s\n", apk.AppID) |
||||
if err := device.Upgrade(path); err != nil { |
||||
return fmt.Errorf("could not upgrade %s: %v", apk.AppID, err) |
||||
} |
||||
return nil |
||||
} |
||||
Loading…
Reference in new issue