From b27e9fb0dffc73b8ce8ea8ba1599ca716164100e Mon Sep 17 00:00:00 2001 From: EnumDev Date: Wed, 29 Oct 2025 18:02:42 +0200 Subject: [PATCH] Show optionally dependant packages in readable info --- src/bpmlib/databases.go | 33 +++++++++++++++++++++++++++++ src/bpmlib/dependencies.go | 43 ++++++++++++++++++++++++++++++++++++++ src/bpmlib/packages.go | 4 ++++ 3 files changed, 80 insertions(+) diff --git a/src/bpmlib/databases.go b/src/bpmlib/databases.go index 5f64efa..c27e278 100644 --- a/src/bpmlib/databases.go +++ b/src/bpmlib/databases.go @@ -300,6 +300,35 @@ func (entry *BPMDatabaseEntry) GetEntryDependants() (dependants []string) { return dependants } +func (entry *BPMDatabaseEntry) GetEntryOptionalDependants() (dependants []string) { + dependantsMap := make(map[string][]string) + for _, db := range BPMDatabases { + for _, e := range db.Entries { + if slices.Contains(e.Info.OptionalDepends, entry.Info.Name) { + dependantsMap[e.Info.Name] = append(dependantsMap[e.Info.Name], e.Database.Name) + } + } + } + + // Get keys + keySlice := slices.Collect(maps.Keys(dependantsMap)) + slices.Sort(keySlice) + + // Add all dependant entries to slice in alphabetical order + for _, entryName := range keySlice { + dbs := dependantsMap[entryName] + if len(dbs) > 1 { + for _, db := range dbs { + dependants = append(dependants, db+"/"+entryName) + } + } else { + dependants = append(dependants, entryName) + } + } + + return dependants +} + func (entry *BPMDatabaseEntry) CreateReadableInfo(rootDir string, humanReadableSize bool) string { ret := make([]string, 0) appendArray := func(label string, array []string, sort bool) { @@ -339,6 +368,10 @@ func (entry *BPMDatabaseEntry) CreateReadableInfo(rootDir string, humanReadableS if len(dependants) > 0 { appendArray("Dependant packages", dependants, false) } + optionalDependants := entry.GetEntryOptionalDependants() + if len(optionalDependants) > 0 { + appendArray("Optionally dependant packages", optionalDependants, false) + } appendArray("Conflicting packages", entry.Info.Conflicts, true) appendArray("Provided packages", entry.Info.Provides, true) appendArray("Replaces packages", entry.Info.Replaces, true) diff --git a/src/bpmlib/dependencies.go b/src/bpmlib/dependencies.go index 241694a..5e623c2 100644 --- a/src/bpmlib/dependencies.go +++ b/src/bpmlib/dependencies.go @@ -217,3 +217,46 @@ func (pkgInfo *PackageInfo) GetPackageDependants(rootDir string) (dependants []s return dependants } + +func (pkgInfo *PackageInfo) GetPackageOptionalDependants(rootDir string) (dependants []string) { + // Get installed package names + pkgs, err := GetInstalledPackages(rootDir) + if err != nil { + return nil + } + + // Loop through all installed packages + for _, installedPkgName := range pkgs { + // Get installed BPM package + installedPkg := GetPackage(installedPkgName, rootDir) + if installedPkg == nil { + return nil + } + + // Skip iteration if comparing the same packages + if installedPkg.PkgInfo.Name == pkgInfo.Name { + continue + } + + // Add installed package to list if its optional dependencies include pkgName + if slices.ContainsFunc(installedPkg.PkgInfo.OptionalDepends, func(n string) bool { + return n == pkgInfo.Name + }) { + dependants = append(dependants, installedPkgName) + continue + } + + // Loop through each virtual package + for _, vpkg := range pkgInfo.Provides { + // Add installed package to list if its optional dependencies contain a provided virtual package + if slices.ContainsFunc(installedPkg.PkgInfo.OptionalDepends, func(n string) bool { + return n == vpkg + }) { + dependants = append(dependants, installedPkgName) + break + } + } + } + + return dependants +} diff --git a/src/bpmlib/packages.go b/src/bpmlib/packages.go index be79da0..654d801 100644 --- a/src/bpmlib/packages.go +++ b/src/bpmlib/packages.go @@ -545,6 +545,10 @@ func (bpmpkg *BPMPackage) CreateReadableInfo(rootDir string, humanReadableSize b if len(dependants) > 0 { appendArray("Dependant packages", dependants) } + optionalDependants := bpmpkg.PkgInfo.GetPackageOptionalDependants(rootDir) + if len(optionalDependants) > 0 { + appendArray("Optionally dependant packages", optionalDependants) + } appendArray("Conflicting packages", bpmpkg.PkgInfo.Conflicts) appendArray("Provided packages", bpmpkg.PkgInfo.Provides) appendArray("Replaces packages", bpmpkg.PkgInfo.Replaces)