AllPac/pkg/packagemanager/flatpak.go
VetheonGames ab2582dc60 Main Update 1
Install.go Changes
```
- Add comments to each file/package to elaborate on their purpose
- Add package list functions to install.go to keep track of installed packages and their sources
- Remove the dependancy on YAY, we are just gonna handle AUR operations ourselves.
- Remove YAY methods from install.go
- Add calls to the package install logger to the end of each install functions
- Add dependancy install functions to install.go
```

flatpak.go Changes:
```
- Completely write flatpak.go
- Include functions for uninstalling flatpak programs
- Include functions for updating flatpak programs
```

pacman.go Changes:
```
- Completely write pacman.go
- Include functions for uninstalling pacman packages
- Include functions for updating pacman packages
```

yay.go Changes:
```
- Completely removed
```

search.go Changes:
```
- Completely write search.go
- Include functions for searching pacman
- Include functions for searching snap
- Include functions for searching flatpak
```

toolcheck.go Changes:
```
- Completely write toolcheck.go
- Include functions for checking for Git
- Include functions for checking for base-devel group
- Include functions for checking for pacman
- Include functions for checking for Snapd
- Include functions for checking for flatpak
- Include function to ask to install flatpak
- Include function to ask to install Snapd
- Include function to ask to install Git
- Include function to ask to install the base-devel group
```
2024-01-04 09:49:03 -07:00

71 lines
2.0 KiB
Go

package packagemanager
// This package is responsible for handling updating and uninstalling flatpak applications
import (
"os/exec"
"encoding/json"
"io/ioutil"
"fmt"
"path/filepath"
"os/user"
)
// PackageList represents the mapping of installed packages to their sources
type PackageList map[string]string
// getPkgListPath returns the file path for the package list
func getPkgListPath() (string, error) {
usr, err := user.Current()
if err != nil {
return "", fmt.Errorf("error getting current user: %v", err)
}
return filepath.Join(usr.HomeDir, ".allpac", "pkg.list"), nil
}
// readPackageList reads the package list from the file
func readPackageList() (PackageList, error) {
pkgListPath, err := getPkgListPath()
if err != nil {
return nil, err
}
file, err := ioutil.ReadFile(pkgListPath)
if err != nil {
return nil, fmt.Errorf("error reading package list file: %v", err)
}
var pkgList PackageList
err = json.Unmarshal(file, &pkgList)
if err != nil {
return nil, fmt.Errorf("error decoding package list: %v", err)
}
return pkgList, nil
}
// 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 {
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 {
return fmt.Errorf("error uninstalling Flatpak package: %s, %v", output, err)
}
return nil
}