50af1b9613
This should be the final code update before we start testing things. I think all the code is now in place to have the program function, barring any bugs in my code. So, with that said, here's the changelog: global changes: ``` - implement logger.go across the whole program ``` changes to main.go: ``` - add an import for strings - implement the roughed in handling functions ``` changes to logger.go: ``` - create this little helper package to just handle all our logging nice and gracefully ``` changes to all_updater.go: ``` - basically completely redone. Accomplishes the same thing, just in a different, more efficient way. ``` changes to aur.go: ``` - add a function to clear the AllPac build cache for aur ``` changes to install.go: ``` - removed a duplicate function, set install.go to call the right one ``` changes to pacman.go: ``` - removed GetVersionFromPacman function (it shouldn't be here, it should be in search.go) ``` changes to search.go: ``` - add functions for getting info from, and parsing output from Snap, Pacman, Flatpak, and aur ```
61 lines
2.1 KiB
Go
61 lines
2.1 KiB
Go
package packagemanager
|
|
|
|
// This package is responsible for handling updating and uninstalling flatpak applications
|
|
|
|
import (
|
|
"os/exec"
|
|
"fmt"
|
|
"strings"
|
|
"pixelridgesoftworks.com/AllPac/pkg/logger"
|
|
)
|
|
|
|
// UpdateFlatpakPackages updates specified Flatpak packages or all if no specific package is provided
|
|
func UpdateFlatpakPackages(packageNames ...string) error {
|
|
var cmd *exec.Cmd
|
|
if len(packageNames) == 0 {
|
|
cmd = exec.Command("flatpak", "update", "-y")
|
|
} else {
|
|
args := append([]string{"update", "-y"}, packageNames...)
|
|
cmd = exec.Command("flatpak", args...)
|
|
}
|
|
|
|
if output, err := cmd.CombinedOutput(); err != nil {
|
|
logger.Errorf("error updating Flatpak packages: %s, %v", output, err)
|
|
return fmt.Errorf("error updating Flatpak packages: %s, %v", output, err)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// UninstallFlatpakPackage uninstalls a specified Flatpak package
|
|
func UninstallFlatpakPackage(packageName string) error {
|
|
cmd := exec.Command("flatpak", "uninstall", "-y", packageName)
|
|
if output, err := cmd.CombinedOutput(); err != nil {
|
|
logger.Errorf("error uninstalling Flatpak package: %s, %v", output, err)
|
|
return fmt.Errorf("error uninstalling Flatpak package: %s, %v", output, err)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// GetVersionFromFlatpak gets the installed version of a Flatpak package
|
|
func GetVersionFromFlatpak(applicationID string) (string, error) {
|
|
cmd := exec.Command("flatpak", "info", applicationID)
|
|
output, err := cmd.CombinedOutput()
|
|
if err != nil {
|
|
logger.Errorf("error getting flatpak package info: %v", err)
|
|
return "", fmt.Errorf("error getting flatpak package info: %v", err)
|
|
}
|
|
|
|
lines := strings.Split(string(output), "\n")
|
|
for _, line := range lines {
|
|
if strings.HasPrefix(line, "Version:") {
|
|
parts := strings.Fields(line)
|
|
if len(parts) >= 2 {
|
|
return parts[1], nil
|
|
}
|
|
break
|
|
}
|
|
}
|
|
logger.Errorf("version not found for flatpak package: %s", applicationID)
|
|
return "", fmt.Errorf("version not found for flatpak package: %s", applicationID)
|
|
}
|