fix: removeAlreadyInstalled before FindPkgs

This commit is contained in:
2025-01-19 11:49:00 +03:00
parent e497d41030
commit 2d6504b329
13 changed files with 386 additions and 156 deletions

View File

@ -149,6 +149,21 @@ func (a *APK) ListInstalled(opts *Opts) (map[string]string, error) {
return out, nil
}
func (a *APK) IsInstalled(pkg string) (bool, error) {
cmd := exec.Command("apk", "info", "--installed", pkg)
output, err := cmd.CombinedOutput()
if err != nil {
if exitErr, ok := err.(*exec.ExitError); ok {
// Exit code 1 means the package is not installed
if exitErr.ExitCode() == 1 {
return false, nil
}
}
return false, fmt.Errorf("apk: isinstalled: %w, output: %s", err, output)
}
return true, nil
}
func (a *APK) getCmd(opts *Opts, mgrCmd string, args ...string) *exec.Cmd {
var cmd *exec.Cmd
if opts.AsRoot {