Show optionally dependant packages in readable info

This commit is contained in:
2025-10-29 18:02:42 +02:00
parent 089bc61d58
commit b27e9fb0df
3 changed files with 80 additions and 0 deletions
+33
View File
@@ -300,6 +300,35 @@ func (entry *BPMDatabaseEntry) GetEntryDependants() (dependants []string) {
return dependants 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 { func (entry *BPMDatabaseEntry) CreateReadableInfo(rootDir string, humanReadableSize bool) string {
ret := make([]string, 0) ret := make([]string, 0)
appendArray := func(label string, array []string, sort bool) { appendArray := func(label string, array []string, sort bool) {
@@ -339,6 +368,10 @@ func (entry *BPMDatabaseEntry) CreateReadableInfo(rootDir string, humanReadableS
if len(dependants) > 0 { if len(dependants) > 0 {
appendArray("Dependant packages", dependants, false) 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("Conflicting packages", entry.Info.Conflicts, true)
appendArray("Provided packages", entry.Info.Provides, true) appendArray("Provided packages", entry.Info.Provides, true)
appendArray("Replaces packages", entry.Info.Replaces, true) appendArray("Replaces packages", entry.Info.Replaces, true)
+43
View File
@@ -217,3 +217,46 @@ func (pkgInfo *PackageInfo) GetPackageDependants(rootDir string) (dependants []s
return dependants 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
}
+4
View File
@@ -545,6 +545,10 @@ func (bpmpkg *BPMPackage) CreateReadableInfo(rootDir string, humanReadableSize b
if len(dependants) > 0 { if len(dependants) > 0 {
appendArray("Dependant packages", dependants) 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("Conflicting packages", bpmpkg.PkgInfo.Conflicts)
appendArray("Provided packages", bpmpkg.PkgInfo.Provides) appendArray("Provided packages", bpmpkg.PkgInfo.Provides)
appendArray("Replaces packages", bpmpkg.PkgInfo.Replaces) appendArray("Replaces packages", bpmpkg.PkgInfo.Replaces)