mirror of
https://github.com/EnumeratedDev/bpm.git
synced 2026-09-16 10:36:12 +00:00
Allow removal of packages that depend on virtual packages with more than 1 provider
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -218,7 +218,7 @@ func RemovePackages(rootDir string, force, cleanupDependencies bool, packages ..
|
||||
continue
|
||||
}
|
||||
|
||||
dependants := action.(*RemovePackageAction).BpmPackage.PkgInfo.GetPackageDependants(rootDir)
|
||||
dependants := action.(*RemovePackageAction).BpmPackage.PkgInfo.GetPackageDependants(rootDir, true)
|
||||
packageDepndants[action.(*RemovePackageAction).BpmPackage.PkgInfo.Name] = dependants
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user