MCPcopy
hub / github.com/PatchMon/PatchMon / CombinePackageData

Function CombinePackageData

agent-source-code/internal/packages/packages.go:161–194  ·  view source on GitHub ↗

CombinePackageData combines and deduplicates installed and upgradable package lists. installedPackages must contain full package info (including Description from dpkg-query). Descriptions and SourceRepository are preserved from installed packages for both upgradable and non-upgradable.

(installedPackages map[string]models.Package, upgradablePackages []models.Package)

Source from the content-addressed store, hash-verified

159// installedPackages must contain full package info (including Description from dpkg-query).
160// Descriptions and SourceRepository are preserved from installed packages for both upgradable and non-upgradable.
161func CombinePackageData(installedPackages map[string]models.Package, upgradablePackages []models.Package) []models.Package {
162 packages := make([]models.Package, 0)
163 upgradableMap := make(map[string]bool)
164
165 // First, add upgradable packages, merging in description and repo from installed if available
166 for _, pkg := range upgradablePackages {
167 if installed, ok := installedPackages[pkg.Name]; ok {
168 if installed.Description != "" {
169 pkg.Description = installed.Description
170 }
171 if pkg.SourceRepository == "" && installed.SourceRepository != "" {
172 pkg.SourceRepository = installed.SourceRepository
173 }
174 }
175 packages = append(packages, pkg)
176 upgradableMap[pkg.Name] = true
177 }
178
179 // Then add installed packages that are not upgradable (with full info including description)
180 for packageName, installed := range installedPackages {
181 if !upgradableMap[packageName] {
182 packages = append(packages, models.Package{
183 Name: packageName,
184 Description: installed.Description,
185 CurrentVersion: installed.CurrentVersion,
186 SourceRepository: installed.SourceRepository,
187 NeedsUpdate: false,
188 IsSecurityUpdate: false,
189 })
190 }
191 }
192
193 return packages
194}

Callers 6

GetPackagesMethod · 0.85
GetPackagesMethod · 0.85
GetPackagesMethod · 0.85
GetPackagesMethod · 0.85
getPkgPackagesMethod · 0.85
TestCombinePackageDataFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestCombinePackageDataFunction · 0.68