From b18687f4550bd81c4ad431b924d3cf3d9e261eac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Sat, 24 Oct 2015 11:52:11 +0200 Subject: [PATCH] adb: add Upgrade --- adb/adb.go | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/adb/adb.go b/adb/adb.go index e0fd1d5..dd2b5eb 100644 --- a/adb/adb.go +++ b/adb/adb.go @@ -236,8 +236,13 @@ func getFailureCode(r *regexp.Regexp, line string) string { var installFailureRegex = regexp.MustCompile(`^Failure \[INSTALL_(.+)\]$`) -func (d *Device) Install(path string) error { - cmd := d.AdbCmd("install", path) +func withOpts(cmd string, opts []string, args ...string) []string { + v := append([]string{"install"}, opts...) + return append(v, args...) +} + +func (d *Device) install(opts []string, path string) error { + cmd := d.AdbCmd(withOpts("install", opts, path)...) stdout, err := cmd.StdoutPipe() if err != nil { return err @@ -252,6 +257,14 @@ func (d *Device) Install(path string) error { return parseError(getFailureCode(installFailureRegex, line)) } +func (d *Device) Install(path string) error { + return d.install(nil, path) +} + +func (d *Device) Upgrade(path string) error { + return d.install([]string{"-r"}, path) +} + func getResultLine(out io.ReadCloser) string { scanner := bufio.NewScanner(out) for scanner.Scan() {