mirror of
https://github.com/EnumeratedDev/bpm.git
synced 2026-09-16 02:26:12 +00:00
Cache installed virtual packages
This commit is contained in:
+3
-3
@@ -260,8 +260,8 @@ func showPackageInfo() {
|
||||
}
|
||||
isFile = true
|
||||
} else {
|
||||
if isVirtual, p := bpmlib.IsVirtualPackage(pkg, rootDir); isVirtual {
|
||||
bpmpkg = bpmlib.GetPackage(p, rootDir)
|
||||
if providers := bpmlib.GetVirtualPackageInfo(pkg, rootDir); len(providers) > 0 {
|
||||
bpmpkg = bpmlib.GetPackage(providers[0].Name, rootDir)
|
||||
} else {
|
||||
bpmpkg = bpmlib.GetPackage(pkg, rootDir)
|
||||
}
|
||||
@@ -1293,7 +1293,7 @@ func compilePackage() {
|
||||
for i := len(unmetDepends) - 1; i >= 0; i-- {
|
||||
if slices.Contains(installedPackages, unmetDepends[i]) {
|
||||
unmetDepends = append(unmetDepends[:i], unmetDepends[i+1:]...)
|
||||
} else if ok, _ := bpmlib.IsVirtualPackage(unmetDepends[i], rootDir); ok {
|
||||
} else if providers := bpmlib.GetVirtualPackageInfo(unmetDepends[i], rootDir); len(providers) > 0 {
|
||||
unmetDepends = append(unmetDepends[:i], unmetDepends[i+1:]...)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,8 +101,8 @@ func (pkgInfo *PackageInfo) getDependenciesRecursive(resolved *[]string, unresol
|
||||
for _, pkgIR := range pkgInfo.GetDependencies(includeMakeDepends, includeCheckDepends, includeRuntimeDepends, false) {
|
||||
depend := pkgIR.PkgName
|
||||
|
||||
if isVirtual, p := IsVirtualPackage(depend, rootDir); isVirtual {
|
||||
depend = p
|
||||
if providers := GetVirtualPackageInfo(depend, rootDir); len(providers) > 0 {
|
||||
depend = providers[0].Name
|
||||
}
|
||||
|
||||
if !slices.Contains(*resolved, depend) {
|
||||
@@ -177,7 +177,7 @@ func resolvePackageDependenciesFromDatabase(resolved *[]pkgInstallationReason, u
|
||||
}
|
||||
|
||||
// Skip dependency if it is already installed or provided
|
||||
if ignoreInstalled && IsPackageProvided(pkgIR.PkgName, rootDir) {
|
||||
if providers := GetVirtualPackageInfo(pkgIR.PkgName, rootDir); ignoreInstalled && len(providers) > 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
|
||||
@@ -93,8 +93,8 @@ func InstallPackages(rootDir string, forceInstallationReason InstallationReason,
|
||||
|
||||
if e, _, err := GetDatabaseEntry(pkg); err == nil {
|
||||
entry = e
|
||||
} else if isVirtual, p := IsVirtualPackage(pkg, rootDir); isVirtual {
|
||||
entry, _, err = GetDatabaseEntry(p)
|
||||
} else if providers := GetVirtualPackageInfo(pkg, rootDir); len(providers) > 0 {
|
||||
entry, _, err = GetDatabaseEntry(providers[0].Name)
|
||||
if err != nil {
|
||||
pkgsNotFound = append(pkgsNotFound, pkg)
|
||||
continue
|
||||
@@ -202,8 +202,8 @@ func RemovePackages(rootDir string, force, cleanupDependencies bool, packages ..
|
||||
// Search for packages
|
||||
for _, pkg := range packages {
|
||||
bpmpkg := GetPackage(pkg, rootDir)
|
||||
if isVirutal, vpkg := IsVirtualPackage(pkg, rootDir); isVirutal {
|
||||
bpmpkg = GetPackage(vpkg, rootDir)
|
||||
if providers := GetVirtualPackageInfo(pkg, rootDir); len(providers) > 0 {
|
||||
bpmpkg = GetPackage(providers[0].Name, rootDir)
|
||||
}
|
||||
if bpmpkg == nil {
|
||||
continue
|
||||
|
||||
@@ -14,6 +14,7 @@ import (
|
||||
var persistentDataVersion int = 1
|
||||
|
||||
var localPackageInformation map[string]map[string]*PackageInfo = make(map[string]map[string]*PackageInfo)
|
||||
var installedVirtualPackages map[string]map[string][]*PackageInfo = make(map[string]map[string][]*PackageInfo)
|
||||
|
||||
func InitializeLocalPackageInformation(rootDir string) (err error) {
|
||||
// Return if information is already initialized
|
||||
@@ -22,6 +23,7 @@ func InitializeLocalPackageInformation(rootDir string) (err error) {
|
||||
}
|
||||
|
||||
tempPackageInformation := make(map[string]*PackageInfo)
|
||||
tempInstalledVirtualPackages := make(map[string][]*PackageInfo)
|
||||
|
||||
// Get paths
|
||||
persistentDataDir := path.Join(rootDir, "var/lib/bpm")
|
||||
@@ -71,9 +73,15 @@ func InitializeLocalPackageInformation(rootDir string) (err error) {
|
||||
|
||||
// Add package to slice
|
||||
tempPackageInformation[info.Name] = info
|
||||
|
||||
// Add virtual packages
|
||||
for _, vpkg := range info.Provides {
|
||||
tempInstalledVirtualPackages[vpkg] = append(tempInstalledVirtualPackages[vpkg], info)
|
||||
}
|
||||
}
|
||||
|
||||
localPackageInformation[rootDir] = tempPackageInformation
|
||||
installedVirtualPackages[rootDir] = tempInstalledVirtualPackages
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -108,44 +116,13 @@ func IsPackageInstalled(pkg, rootDir string) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func IsVirtualPackage(pkg, rootDir string) (bool, string) {
|
||||
pkgs, err := GetInstalledPackages(rootDir)
|
||||
func GetVirtualPackageInfo(vpkg, rootDir string) []*PackageInfo {
|
||||
err := InitializeLocalPackageInformation(rootDir)
|
||||
if err != nil {
|
||||
return false, ""
|
||||
}
|
||||
for _, p := range pkgs {
|
||||
if p == pkg {
|
||||
return false, ""
|
||||
}
|
||||
i := GetPackageInfo(p, rootDir)
|
||||
if i == nil {
|
||||
continue
|
||||
}
|
||||
if slices.Contains(i.Provides, pkg) {
|
||||
return true, p
|
||||
}
|
||||
}
|
||||
return false, ""
|
||||
return nil
|
||||
}
|
||||
|
||||
func IsPackageProvided(pkg, rootDir string) bool {
|
||||
pkgs, err := GetInstalledPackages(rootDir)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
for _, p := range pkgs {
|
||||
if p == pkg {
|
||||
return true
|
||||
}
|
||||
i := GetPackageInfo(p, rootDir)
|
||||
if i == nil {
|
||||
continue
|
||||
}
|
||||
if slices.Contains(i.Provides, pkg) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
return installedVirtualPackages[rootDir][vpkg]
|
||||
}
|
||||
|
||||
func GetPackageInfo(pkg string, rootDir string) *PackageInfo {
|
||||
|
||||
Reference in New Issue
Block a user