mirror of
https://github.com/EnumeratedDev/bpm.git
synced 2026-09-16 02:26:12 +00:00
Use package info instead of BPMPackage for the local package information map
This commit is contained in:
@@ -9,7 +9,7 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
var localPackageInformation map[string]map[string]*BPMPackage = make(map[string]map[string]*BPMPackage)
|
||||
var localPackageInformation map[string]map[string]*PackageInfo = make(map[string]map[string]*PackageInfo)
|
||||
|
||||
func initializeLocalPackageInformation(rootDir string) (err error) {
|
||||
// Return if information is already initialized
|
||||
@@ -17,7 +17,7 @@ func initializeLocalPackageInformation(rootDir string) (err error) {
|
||||
return nil
|
||||
}
|
||||
|
||||
tempPackageInformation := make(map[string]*BPMPackage)
|
||||
tempPackageInformation := make(map[string]*PackageInfo)
|
||||
|
||||
// Get path to installed package information directory
|
||||
installedDir := path.Join(rootDir, "var/lib/bpm/installed/")
|
||||
@@ -25,7 +25,7 @@ func initializeLocalPackageInformation(rootDir string) (err error) {
|
||||
// Get directory content
|
||||
items, err := os.ReadDir(installedDir)
|
||||
if os.IsNotExist(err) {
|
||||
localPackageInformation[rootDir] = make(map[string]*BPMPackage)
|
||||
localPackageInformation[rootDir] = make(map[string]*PackageInfo)
|
||||
return nil
|
||||
}
|
||||
if err != nil {
|
||||
@@ -49,14 +49,8 @@ func initializeLocalPackageInformation(rootDir string) (err error) {
|
||||
return err
|
||||
}
|
||||
|
||||
// Read package files
|
||||
files := getPackageFiles(info.Name, rootDir)
|
||||
|
||||
// Add package to slice
|
||||
tempPackageInformation[info.Name] = &BPMPackage{
|
||||
PkgInfo: info,
|
||||
PkgFiles: files,
|
||||
}
|
||||
tempPackageInformation[info.Name] = info
|
||||
}
|
||||
|
||||
localPackageInformation[rootDir] = tempPackageInformation
|
||||
@@ -71,8 +65,8 @@ func GetInstalledPackages(rootDir string) (ret []string, err error) {
|
||||
}
|
||||
|
||||
// Loop through each package and add it to slice
|
||||
for _, bpmpkg := range localPackageInformation[rootDir] {
|
||||
ret = append(ret, bpmpkg.PkgInfo.Name)
|
||||
for _, pkgInfo := range localPackageInformation[rootDir] {
|
||||
ret = append(ret, pkgInfo.Name)
|
||||
}
|
||||
|
||||
// Sort packages
|
||||
@@ -94,18 +88,6 @@ func IsPackageInstalled(pkg, rootDir string) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func GetPackageInfo(pkg string, rootDir string) *PackageInfo {
|
||||
// Get BPM package
|
||||
bpmpkg := GetPackage(pkg, rootDir)
|
||||
|
||||
// Return nil if not found
|
||||
if bpmpkg == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return bpmpkg.PkgInfo
|
||||
}
|
||||
|
||||
func IsVirtualPackage(pkg, rootDir string) (bool, string) {
|
||||
pkgs, err := GetInstalledPackages(rootDir)
|
||||
if err != nil {
|
||||
@@ -146,15 +128,27 @@ func IsPackageProvided(pkg, rootDir string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func GetPackage(pkg, rootDir string) *BPMPackage {
|
||||
func GetPackageInfo(pkg string, rootDir string) *PackageInfo {
|
||||
err := initializeLocalPackageInformation(rootDir)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
bpmpkg := localPackageInformation[rootDir][pkg]
|
||||
return localPackageInformation[rootDir][pkg]
|
||||
}
|
||||
|
||||
return bpmpkg
|
||||
func GetPackage(pkg, rootDir string) *BPMPackage {
|
||||
pkgInfo := GetPackageInfo(pkg, rootDir)
|
||||
if pkgInfo == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
files := getPackageFiles(pkgInfo.Name, rootDir)
|
||||
|
||||
return &BPMPackage{
|
||||
PkgInfo: pkgInfo,
|
||||
PkgFiles: files,
|
||||
}
|
||||
}
|
||||
|
||||
func GetAllPackageFiles(rootDir string, excludePackages ...string) (map[string][]*BPMPackage, error) {
|
||||
|
||||
@@ -310,29 +310,29 @@ func (operation *BPMOperation) CheckForConflicts() map[string][]string {
|
||||
// Check for conflicts with installed packages
|
||||
for _, installedPkg := range installedPackages {
|
||||
// Skip if package is to be removed
|
||||
if slices.Contains(removedPackages, installedPkg.PkgInfo.Name) {
|
||||
if slices.Contains(removedPackages, installedPkg.Name) {
|
||||
continue
|
||||
}
|
||||
|
||||
// Skip if same package
|
||||
if pkgInfo.Name == installedPkg.PkgInfo.Name {
|
||||
if pkgInfo.Name == installedPkg.Name {
|
||||
continue
|
||||
}
|
||||
|
||||
// Check for new package conflicts
|
||||
if slices.Contains(pkgInfo.Conflicts, installedPkg.PkgInfo.Name) {
|
||||
conflicts[pkgInfo.Name] = append(conflicts[pkgInfo.Name], installedPkg.PkgInfo.Name)
|
||||
if slices.Contains(pkgInfo.Conflicts, installedPkg.Name) {
|
||||
conflicts[pkgInfo.Name] = append(conflicts[pkgInfo.Name], installedPkg.Name)
|
||||
}
|
||||
for _, vpkg := range installedPkg.PkgInfo.Provides {
|
||||
for _, vpkg := range installedPkg.Provides {
|
||||
if slices.Contains(pkgInfo.Conflicts, vpkg) {
|
||||
conflicts[pkgInfo.Name] = append(conflicts[pkgInfo.Name], vpkg+" ("+installedPkg.PkgInfo.Name+")")
|
||||
conflicts[pkgInfo.Name] = append(conflicts[pkgInfo.Name], vpkg+" ("+installedPkg.Name+")")
|
||||
}
|
||||
}
|
||||
|
||||
// Check for installed package conflicts
|
||||
for _, vpkg := range pkgInfo.Provides {
|
||||
if slices.Contains(installedPkg.PkgInfo.Conflicts, vpkg) {
|
||||
conflicts[installedPkg.PkgInfo.Name] = append(conflicts[installedPkg.PkgInfo.Name], vpkg+" ("+pkgInfo.Name+")")
|
||||
if slices.Contains(installedPkg.Conflicts, vpkg) {
|
||||
conflicts[installedPkg.Name] = append(conflicts[installedPkg.Name], vpkg+" ("+pkgInfo.Name+")")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1007,7 +1007,7 @@ func installPackage(filename, rootDir string, verbose, force bool) error {
|
||||
}
|
||||
|
||||
// Add or update package information for rootDir
|
||||
localPackageInformation[rootDir][bpmpkg.PkgInfo.Name] = bpmpkg
|
||||
localPackageInformation[rootDir][bpmpkg.PkgInfo.Name] = bpmpkg.PkgInfo
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user