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