From de5a0ef71437f8de4b612a66b4ee81f9911b9a62 Mon Sep 17 00:00:00 2001 From: Linus789 Date: Tue, 28 Feb 2023 06:31:00 +0100 Subject: [PATCH] uninstall: if -user is specified, make sure that the app is installed for that user --- uninstall.go | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/uninstall.go b/uninstall.go index ebbb66f..8cd7e40 100644 --- a/uninstall.go +++ b/uninstall.go @@ -53,11 +53,31 @@ func runUninstall(args []string) error { for _, id := range args { var err error fmt.Printf("Uninstalling %s\n", id) - if _, installed := inst[id]; installed { + app, installed := inst[id] + if installed { + installedForUser := false if *uninstallUser == "all" { - err = device.Uninstall(id) + installedForUser = true } else { - err = device.UninstallUser(id, *uninstallUser) + uid, err := strconv.Atoi(*uninstallUser) + if err != nil { + return err + } + for _, appUser := range app.InstalledForUsers { + if appUser == uid { + installedForUser = true + break + } + } + } + if installedForUser { + if *uninstallUser == "all" { + err = device.Uninstall(id) + } else { + err = device.UninstallUser(id, *uninstallUser) + } + } else { + err = errors.New("not installed for user") } } else { err = errors.New("not installed")