mirror of
https://github.com/EnumeratedDev/bpm.git
synced 2026-09-16 02:26:12 +00:00
Improve update operation new dependency resolution
This commit is contained in:
+9
-107
@@ -411,12 +411,12 @@ func UpdatePackages(rootDir string, syncDatabase, allowDowngrades, forceInstalla
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Search for packages
|
// Search for packages
|
||||||
pkgsNotFound := make([]string, 0)
|
|
||||||
resolvedVirtualPackages := make(map[string]string)
|
resolvedVirtualPackages := make(map[string]string)
|
||||||
for _, pkg := range pkgs {
|
for _, pkg := range pkgs {
|
||||||
if rootDir == "/" && slices.Contains(MainBPMConfig.IgnorePackages, pkg) {
|
if rootDir == "/" && slices.Contains(MainBPMConfig.IgnorePackages, pkg) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
var entry *BPMDatabaseEntry
|
var entry *BPMDatabaseEntry
|
||||||
// Check if installed package can be replaced and install that instead
|
// Check if installed package can be replaced and install that instead
|
||||||
if e := FindReplacement(pkg); e != nil {
|
if e := FindReplacement(pkg); e != nil {
|
||||||
@@ -443,115 +443,17 @@ func UpdatePackages(rootDir string, syncDatabase, allowDowngrades, forceInstalla
|
|||||||
DatabaseEntry: entry,
|
DatabaseEntry: entry,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for missing dependencies
|
|
||||||
for _, depend := range entry.Info.Depends {
|
|
||||||
// Split package name and required version
|
|
||||||
dependName, _, _ := SplitPkgNameAndVersion(depend)
|
|
||||||
|
|
||||||
if IsPackageInstalled(dependName, rootDir) && EvaluateDependency(depend, GetPackageInfo(dependName, rootDir).Version) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if len(GetVirtualPackageInfo(dependName, rootDir)) > 0 {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check resolved virtual packages
|
|
||||||
if resolvedPkg, ok := resolvedVirtualPackages[dependName]; ok {
|
|
||||||
dependName = resolvedPkg
|
|
||||||
}
|
|
||||||
|
|
||||||
// Find database entry for missing dependency
|
|
||||||
dependEntry := ResolveDatabaseEntry(dependName, rootDir)
|
|
||||||
if dependEntry == nil {
|
|
||||||
pkgsNotFound = append(pkgsNotFound, depend)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
// Skip dependency if action already exists
|
|
||||||
if ActionSliceIndex(operation.Actions, dependEntry.Info.Name) != -1 {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
// Skip dependency if ignored in config
|
|
||||||
if rootDir == "/" && slices.Contains(MainBPMConfig.IgnorePackages, dependEntry.Info.Name) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ensure entry has required version
|
|
||||||
if !EvaluateDependency(depend, dependEntry.Info.Version) {
|
|
||||||
pkgsNotFound = append(pkgsNotFound, depend)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
// Resolve virtual packages
|
|
||||||
for _, vpkg := range dependEntry.Info.Provides {
|
|
||||||
if _, ok := resolvedVirtualPackages[vpkg]; !ok {
|
|
||||||
resolvedVirtualPackages[vpkg] = dependEntry.Info.Name
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fetch dependency
|
|
||||||
operation.Actions = append(operation.Actions, &FetchPackageAction{
|
|
||||||
InstallationReason: InstallationReasonDependency,
|
|
||||||
DatabaseEntry: dependEntry,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check for missing runtime dependencies
|
|
||||||
for _, depend := range entry.Info.RuntimeDepends {
|
|
||||||
// Split package name and required version
|
|
||||||
dependName, _, _ := SplitPkgNameAndVersion(depend)
|
|
||||||
|
|
||||||
if IsPackageInstalled(dependName, rootDir) && EvaluateDependency(depend, GetPackageInfo(dependName, rootDir).Version) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if len(GetVirtualPackageInfo(dependName, rootDir)) > 0 {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check resolved virtual packages
|
|
||||||
if resolvedPkg, ok := resolvedVirtualPackages[dependName]; ok {
|
|
||||||
dependName = resolvedPkg
|
|
||||||
}
|
|
||||||
|
|
||||||
// Find database entry for missing dependency
|
|
||||||
dependEntry := ResolveDatabaseEntry(dependName, rootDir)
|
|
||||||
if dependEntry == nil {
|
|
||||||
pkgsNotFound = append(pkgsNotFound, depend)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
// Skip dependency if ignored in config
|
|
||||||
if rootDir == "/" && slices.Contains(MainBPMConfig.IgnorePackages, dependEntry.Info.Name) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ensure entry has required version
|
|
||||||
if !EvaluateDependency(depend, dependEntry.Info.Version) {
|
|
||||||
pkgsNotFound = append(pkgsNotFound, depend)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
// Resolve virtual packages
|
|
||||||
for _, vpkg := range dependEntry.Info.Provides {
|
|
||||||
if _, ok := resolvedVirtualPackages[vpkg]; !ok {
|
|
||||||
resolvedVirtualPackages[vpkg] = dependEntry.Info.Name
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fetch dependency
|
|
||||||
operation.Actions = append(operation.Actions, &FetchPackageAction{
|
|
||||||
InstallationReason: InstallationReasonDependency,
|
|
||||||
DatabaseEntry: dependEntry,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return error if not all packages are found
|
// Resolve dependencies
|
||||||
if len(pkgsNotFound) != 0 {
|
operation.ResolveDependencies(true)
|
||||||
return nil, PackageNotFoundErr{pkgsNotFound}
|
if len(operation.UnresolvedDepends) != 0 {
|
||||||
|
if !forceInstallation {
|
||||||
|
return nil, DependencyNotFoundErr{operation.UnresolvedDepends}
|
||||||
|
} else if verbose {
|
||||||
|
log.Printf("Warning: %s", DependencyNotFoundErr{operation.UnresolvedDepends})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Replace obsolete packages
|
// Replace obsolete packages
|
||||||
|
|||||||
Reference in New Issue
Block a user