From f6cb2d8d12cd2797e04a3b5ef5c8be1ddda39e14 Mon Sep 17 00:00:00 2001 From: Mikhail Klementev Date: Thu, 11 May 2023 21:20:00 +0000 Subject: [PATCH] Check if package already in slice --- distro/debian/snapshot/snapshot.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/distro/debian/snapshot/snapshot.go b/distro/debian/snapshot/snapshot.go index f32ba4d..2082acd 100644 --- a/distro/debian/snapshot/snapshot.go +++ b/distro/debian/snapshot/snapshot.go @@ -274,6 +274,15 @@ func httpGetWithRetry(query string) (resp *http.Response, err error) { return } +func contains(pkgs []Package, pkg Package) bool { + for _, p := range pkgs { + if p.Name == pkg.Name { + return true + } + } + return false +} + func Packages(srcname, version, arch, regex string) (pkgs []Package, err error) { binpkgs, err := mr.GetBinpackages(srcname, version) if err != nil { @@ -295,6 +304,11 @@ func Packages(srcname, version, arch, regex string) (pkgs []Package, err error) return } + if contains(pkgs, pkg) { + log.Trace().Msgf("%v already in slice O_o", pkg.Name) + continue + } + log.Trace().Msgf("append %v", pkg.Name) pkgs = append(pkgs, pkg) }