4 Commits
6 changed files with 87 additions and 36 deletions
+1
View File
@@ -765,6 +765,7 @@ func removePackages() {
return
} else if errors.As(err, &bpmlib.PackageRemovalDependencyErr{}) {
for pkg, dependants := range err.(bpmlib.PackageRemovalDependencyErr).RequiredPackages {
slices.Sort(dependants)
fmt.Printf("The following packages depend on package (%s): %s\n", pkg, strings.Join(dependants, ", "))
}
+10 -1
View File
@@ -5,7 +5,7 @@ import (
"strings"
)
func (pkgInfo *PackageInfo) GetPackageDependants(rootDir string) (dependants []string) {
func (pkgInfo *PackageInfo) GetPackageDependants(rootDir string, skipMultipleProviders bool) (dependants []string) {
// Get installed package names
pkgs, ok := localPackageInformation[rootDir]
if !ok {
@@ -37,6 +37,10 @@ func (pkgInfo *PackageInfo) GetPackageDependants(rootDir string) (dependants []s
// Loop through each virtual package
for _, vpkg := range pkgInfo.Provides {
if skipMultipleProviders && len(GetVirtualPackageInfo(vpkg, rootDir)) > 1 {
continue
}
// Add installed package to list if its dependencies contain a provided virtual package
if slices.ContainsFunc(installedPkg.Depends, func(n string) bool {
return n == vpkg
@@ -129,6 +133,11 @@ func ResolveDependencies(pkgInfo *PackageInfo, resolvedVirtualPackages map[strin
continue
}
// Skip ignored packages in config
if slices.Contains(MainBPMConfig.IgnorePackages, dependEntry.Info.Name) {
continue
}
if !slices.Contains(visited, dependEntry.Info.Name) {
dfs(dependEntry.Info)
resolved = append(resolved, ResolvedPackage{DatabaseEntry: dependEntry, InstallationReason: installationReason})
+4
View File
@@ -2,6 +2,7 @@ package bpmlib
import (
"fmt"
"slices"
"strings"
)
@@ -10,6 +11,7 @@ type PackageNotFoundErr struct {
}
func (e PackageNotFoundErr) Error() string {
slices.Sort(e.packages)
return "The following packages were not found in any databases: " + strings.Join(e.packages, ", ")
}
@@ -18,6 +20,7 @@ type DependencyNotFoundErr struct {
}
func (e DependencyNotFoundErr) Error() string {
slices.Sort(e.dependencies)
return "The following dependencies were not found in any databases: " + strings.Join(e.dependencies, ", ")
}
@@ -27,6 +30,7 @@ type PackageConflictErr struct {
}
func (e PackageConflictErr) Error() string {
slices.Sort(e.conflicts)
return fmt.Sprintf("Package (%s) is in conflict with the following packages: %s", e.pkg, strings.Join(e.conflicts, ", "))
}
+71 -10
View File
@@ -213,12 +213,12 @@ func RemovePackages(rootDir string, force, cleanupDependencies bool, packages ..
// Get packages and their dependants
packageDepndants := make(map[string][]string, 0)
for _, action := range operation.Actions {
// Skip package if ignored
// Skip package if ignored in config
if slices.Contains(MainBPMConfig.IgnorePackages, action.(*RemovePackageAction).BpmPackage.PkgInfo.Name) {
continue
}
dependants := action.(*RemovePackageAction).BpmPackage.PkgInfo.GetPackageDependants(rootDir)
dependants := action.(*RemovePackageAction).BpmPackage.PkgInfo.GetPackageDependants(rootDir, true)
packageDepndants[action.(*RemovePackageAction).BpmPackage.PkgInfo.Name] = dependants
}
@@ -393,6 +393,7 @@ func UpdatePackages(rootDir string, syncDatabase, allowDowngrades, forceInstalla
}
// Search for packages
pkgsNotFound := make([]string, 0)
for _, pkg := range pkgs {
if slices.Contains(MainBPMConfig.IgnorePackages, pkg) {
continue
@@ -416,17 +417,77 @@ func UpdatePackages(rootDir string, syncDatabase, allowDowngrades, forceInstalla
DatabaseEntry: entry,
})
}
// Check for missing dependencies
for _, dep := range entry.Info.Depends {
if IsPackageInstalled(dep, rootDir) {
continue
}
if len(GetVirtualPackageInfo(dep, rootDir)) > 0 {
continue
}
// Find database entry for missing dependency
depEntry, _, err := GetDatabaseEntry(dep)
if err != nil {
providers := GetDatabaseVirtualPackageEntry(dep)
if len(providers) == 0 {
pkgsNotFound = append(pkgsNotFound, dep)
continue
}
depEntry = providers[0]
}
// Skip dependency if ignored in config
if slices.Contains(MainBPMConfig.IgnorePackages, depEntry.Info.Name) {
continue
}
// Fetch dependency
operation.AppendAction(&FetchPackageAction{
InstallationReason: InstallationReasonDependency,
DatabaseEntry: depEntry,
})
}
// Check for missing runtime dependencies
for _, dep := range entry.Info.RuntimeDepends {
if IsPackageInstalled(dep, rootDir) {
continue
}
if len(GetVirtualPackageInfo(dep, rootDir)) > 0 {
continue
}
// Find database entry for missing dependency
depEntry, _, err := GetDatabaseEntry(dep)
if err != nil {
providers := GetDatabaseVirtualPackageEntry(dep)
if len(providers) == 0 {
pkgsNotFound = append(pkgsNotFound, dep)
continue
}
depEntry = providers[0]
}
// Skip dependency if ignored in config
if slices.Contains(MainBPMConfig.IgnorePackages, depEntry.Info.Name) {
continue
}
// Fetch dependency
operation.AppendAction(&FetchPackageAction{
InstallationReason: InstallationReasonDependency,
DatabaseEntry: depEntry,
})
}
}
}
// Check for new dependencies in updated packages
operation.ResolveDependencies(true)
if len(operation.UnresolvedDepends) != 0 {
if !forceInstallation {
return nil, DependencyNotFoundErr{operation.UnresolvedDepends}
} else if verbose {
log.Printf("Warning: %s", DependencyNotFoundErr{operation.UnresolvedDepends})
}
// Return error if not all packages are found
if len(pkgsNotFound) != 0 {
return nil, PackageNotFoundErr{pkgsNotFound}
}
// Replace obsolete packages
-24
View File
@@ -194,30 +194,6 @@ func (operation *BPMOperation) ResolveDependencies(installRuntimeDepends bool) {
}
}
func (operation *BPMOperation) RemoveNeededPackages() error {
removeActions := make(map[string]*RemovePackageAction)
for _, action := range slices.Clone(operation.Actions) {
if action.GetActionType() == "remove" {
removeActions[action.(*RemovePackageAction).BpmPackage.PkgInfo.Name] = action.(*RemovePackageAction)
}
}
for pkg, action := range removeActions {
dependants := action.BpmPackage.PkgInfo.GetPackageDependants(operation.RootDir)
dependants = slices.DeleteFunc(dependants, func(d string) bool {
if _, ok := removeActions[d]; ok {
return true
}
return false
})
if len(dependants) != 0 {
operation.RemoveAction(pkg, action.GetActionType())
}
}
return nil
}
func (operation *BPMOperation) Cleanup(cleanupMakeDepends bool) error {
// Get all installed packages
installedPackageNames, err := GetInstalledPackages(operation.RootDir)
+1 -1
View File
@@ -627,7 +627,7 @@ func (pkgInfo *PackageInfo) CreateReadableInfo(rootDir string) string {
builder.WriteString("\n")
}
}
builderWriteArray("Dependant packages", pkgInfo.GetPackageDependants(rootDir), true)
builderWriteArray("Dependant packages", pkgInfo.GetPackageDependants(rootDir, false), true)
builderWriteArray("Optionally dependant packages", pkgInfo.GetPackageOptionalDependants(rootDir), true)
// Other package relations