From 2ba78f16dbf2157a9ddc648a2f1ac17edd8d34c4 Mon Sep 17 00:00:00 2001 From: EnumDev Date: Wed, 17 Dec 2025 12:16:45 +0200 Subject: [PATCH] Remove duplicate strings in packages slice from install and remove operations --- src/bpmlib/general.go | 7 ++++++- src/bpmlib/utils.go | 12 ++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/bpmlib/general.go b/src/bpmlib/general.go index 0a8c15b..ef66a14 100644 --- a/src/bpmlib/general.go +++ b/src/bpmlib/general.go @@ -21,7 +21,6 @@ const ( // InstallPackages installs the specified packages into the given root directory by fetching them from databases or directly from local bpm archives func InstallPackages(rootDir string, forceInstallationReason InstallationReason, reinstallMethod ReinstallMethod, installOptionalDependencies, forceInstallation, verbose bool, packages ...string) (operation *BPMOperation, err error) { - // Setup operation struct operation = &BPMOperation{ Actions: make([]OperationAction, 0), @@ -31,6 +30,9 @@ func InstallPackages(rootDir string, forceInstallationReason InstallationReason, compiledPackages: make(map[string]string), } + // Remove duplicates from packages + packages = removeDuplicates(packages) + // Resolve packages pkgsNotFound := make([]string, 0) for _, pkg := range packages { @@ -193,6 +195,9 @@ func RemovePackages(rootDir string, force, cleanupDependencies bool, packages .. compiledPackages: make(map[string]string), } + // Remove duplicates from packages + packages = removeDuplicates(packages) + // Search for packages for _, pkg := range packages { bpmpkg := GetPackage(pkg, rootDir) diff --git a/src/bpmlib/utils.go b/src/bpmlib/utils.go index 5c7027d..ab76323 100644 --- a/src/bpmlib/utils.go +++ b/src/bpmlib/utils.go @@ -134,6 +134,18 @@ func bytesToHumanReadable(b int64) string { return fmt.Sprintf("%.1fYiB", bf) } +func removeDuplicates[T comparable](sliceList []T) []T { + allKeys := make(map[T]bool) + list := []T{} + for _, item := range sliceList { + if _, value := allKeys[item]; !value { + allKeys[item] = true + list = append(list, item) + } + } + return list +} + func CompareVersions(version1, version2 string) int { v1 := version.NewVersion(version1) v2 := version.NewVersion(version2)