mirror of
https://github.com/EnumeratedDev/bpm.git
synced 2026-09-21 13:06:12 +00:00
Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2f9487affe
|
||
|
|
596d8753a7
|
||
|
|
2de4eea7a4
|
||
|
|
5d0312856d
|
@@ -765,6 +765,7 @@ func removePackages() {
|
|||||||
return
|
return
|
||||||
} else if errors.As(err, &bpmlib.PackageRemovalDependencyErr{}) {
|
} else if errors.As(err, &bpmlib.PackageRemovalDependencyErr{}) {
|
||||||
for pkg, dependants := range err.(bpmlib.PackageRemovalDependencyErr).RequiredPackages {
|
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, ", "))
|
fmt.Printf("The following packages depend on package (%s): %s\n", pkg, strings.Join(dependants, ", "))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (pkgInfo *PackageInfo) GetPackageDependants(rootDir string) (dependants []string) {
|
func (pkgInfo *PackageInfo) GetPackageDependants(rootDir string, skipMultipleProviders bool) (dependants []string) {
|
||||||
// Get installed package names
|
// Get installed package names
|
||||||
pkgs, ok := localPackageInformation[rootDir]
|
pkgs, ok := localPackageInformation[rootDir]
|
||||||
if !ok {
|
if !ok {
|
||||||
@@ -37,6 +37,10 @@ func (pkgInfo *PackageInfo) GetPackageDependants(rootDir string) (dependants []s
|
|||||||
|
|
||||||
// Loop through each virtual package
|
// Loop through each virtual package
|
||||||
for _, vpkg := range pkgInfo.Provides {
|
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
|
// Add installed package to list if its dependencies contain a provided virtual package
|
||||||
if slices.ContainsFunc(installedPkg.Depends, func(n string) bool {
|
if slices.ContainsFunc(installedPkg.Depends, func(n string) bool {
|
||||||
return n == vpkg
|
return n == vpkg
|
||||||
@@ -129,6 +133,11 @@ func ResolveDependencies(pkgInfo *PackageInfo, resolvedVirtualPackages map[strin
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Skip ignored packages in config
|
||||||
|
if slices.Contains(MainBPMConfig.IgnorePackages, dependEntry.Info.Name) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
if !slices.Contains(visited, dependEntry.Info.Name) {
|
if !slices.Contains(visited, dependEntry.Info.Name) {
|
||||||
dfs(dependEntry.Info)
|
dfs(dependEntry.Info)
|
||||||
resolved = append(resolved, ResolvedPackage{DatabaseEntry: dependEntry, InstallationReason: installationReason})
|
resolved = append(resolved, ResolvedPackage{DatabaseEntry: dependEntry, InstallationReason: installationReason})
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package bpmlib
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -10,6 +11,7 @@ type PackageNotFoundErr struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (e PackageNotFoundErr) Error() string {
|
func (e PackageNotFoundErr) Error() string {
|
||||||
|
slices.Sort(e.packages)
|
||||||
return "The following packages were not found in any databases: " + strings.Join(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 {
|
func (e DependencyNotFoundErr) Error() string {
|
||||||
|
slices.Sort(e.dependencies)
|
||||||
return "The following dependencies were not found in any databases: " + strings.Join(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 {
|
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, ", "))
|
return fmt.Sprintf("Package (%s) is in conflict with the following packages: %s", e.pkg, strings.Join(e.conflicts, ", "))
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+71
-10
@@ -213,12 +213,12 @@ func RemovePackages(rootDir string, force, cleanupDependencies bool, packages ..
|
|||||||
// Get packages and their dependants
|
// Get packages and their dependants
|
||||||
packageDepndants := make(map[string][]string, 0)
|
packageDepndants := make(map[string][]string, 0)
|
||||||
for _, action := range operation.Actions {
|
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) {
|
if slices.Contains(MainBPMConfig.IgnorePackages, action.(*RemovePackageAction).BpmPackage.PkgInfo.Name) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
dependants := action.(*RemovePackageAction).BpmPackage.PkgInfo.GetPackageDependants(rootDir)
|
dependants := action.(*RemovePackageAction).BpmPackage.PkgInfo.GetPackageDependants(rootDir, true)
|
||||||
packageDepndants[action.(*RemovePackageAction).BpmPackage.PkgInfo.Name] = dependants
|
packageDepndants[action.(*RemovePackageAction).BpmPackage.PkgInfo.Name] = dependants
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -393,6 +393,7 @@ func UpdatePackages(rootDir string, syncDatabase, allowDowngrades, forceInstalla
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Search for packages
|
// Search for packages
|
||||||
|
pkgsNotFound := make([]string, 0)
|
||||||
for _, pkg := range pkgs {
|
for _, pkg := range pkgs {
|
||||||
if slices.Contains(MainBPMConfig.IgnorePackages, pkg) {
|
if slices.Contains(MainBPMConfig.IgnorePackages, pkg) {
|
||||||
continue
|
continue
|
||||||
@@ -416,17 +417,77 @@ func UpdatePackages(rootDir string, syncDatabase, allowDowngrades, forceInstalla
|
|||||||
DatabaseEntry: entry,
|
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
|
// Return error if not all packages are found
|
||||||
operation.ResolveDependencies(true)
|
if len(pkgsNotFound) != 0 {
|
||||||
if len(operation.UnresolvedDepends) != 0 {
|
return nil, PackageNotFoundErr{pkgsNotFound}
|
||||||
if !forceInstallation {
|
|
||||||
return nil, DependencyNotFoundErr{operation.UnresolvedDepends}
|
|
||||||
} else if verbose {
|
|
||||||
log.Printf("Warning: %s", DependencyNotFoundErr{operation.UnresolvedDepends})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Replace obsolete packages
|
// Replace obsolete packages
|
||||||
|
|||||||
@@ -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 {
|
func (operation *BPMOperation) Cleanup(cleanupMakeDepends bool) error {
|
||||||
// Get all installed packages
|
// Get all installed packages
|
||||||
installedPackageNames, err := GetInstalledPackages(operation.RootDir)
|
installedPackageNames, err := GetInstalledPackages(operation.RootDir)
|
||||||
|
|||||||
@@ -627,7 +627,7 @@ func (pkgInfo *PackageInfo) CreateReadableInfo(rootDir string) string {
|
|||||||
builder.WriteString("\n")
|
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)
|
builderWriteArray("Optionally dependant packages", pkgInfo.GetPackageOptionalDependants(rootDir), true)
|
||||||
|
|
||||||
// Other package relations
|
// Other package relations
|
||||||
|
|||||||
Reference in New Issue
Block a user