From b191eec3483d23237e4ff05359fccc47c48a464b Mon Sep 17 00:00:00 2001 From: relan Date: Mon, 17 Oct 2016 16:43:57 +0300 Subject: [PATCH] Check that app is installed before uninstalling it When trying to uninstall an app that is not installed adb prints just "Failure". This causes output parsing to fail and results in "panic: runtime error: index out of range" in adb.getFailureCode(). Check whether an app is installed first and print an appropriate message if it's not. --- cmd/fdroidcl/uninstall.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/cmd/fdroidcl/uninstall.go b/cmd/fdroidcl/uninstall.go index 82bfb38..d427570 100644 --- a/cmd/fdroidcl/uninstall.go +++ b/cmd/fdroidcl/uninstall.go @@ -4,6 +4,7 @@ package main import ( + "errors" "fmt" "log" ) @@ -22,9 +23,16 @@ func runUninstall(args []string) { log.Fatalf("No package names given") } device := mustOneDevice() + inst := mustInstalled(device) for _, id := range args { + var err error fmt.Printf("Uninstalling %s... ", id) - if err := device.Uninstall(id); err != nil { + if _, installed := inst[id]; installed { + err = device.Uninstall(id) + } else { + err = errors.New("not installed") + } + if err != nil { fmt.Println() log.Fatalf("Could not uninstall %s: %v", id, err) }