MCPcopy Index your code
hub / github.com/PatchMon/PatchMon / GetPackages

Method GetPackages

agent-source-code/internal/packages/apk.go:29–74  ·  view source on GitHub ↗

GetPackages gets package information for APK-based systems

()

Source from the content-addressed store, hash-verified

27
28// GetPackages gets package information for APK-based systems
29func (m *APKManager) GetPackages() []models.Package {
30 // Update package index
31 m.logger.Debug("Updating package index...")
32 updateCmd := exec.Command("apk", "update", "-q")
33 if err := updateCmd.Run(); err != nil {
34 m.logger.WithError(err).Warn("Failed to update package index")
35 }
36
37 // Get installed packages
38 m.logger.Debug("Getting installed packages...")
39 installedCmd := exec.Command("apk", "list", "--installed")
40 installedOutput, err := installedCmd.Output()
41 var installedPackages map[string]models.Package
42 if err != nil {
43 m.logger.WithError(err).Warn("Failed to get installed packages")
44 installedPackages = make(map[string]models.Package)
45 } else {
46 m.logger.Debug("Parsing installed packages...")
47 installedPackages = m.parseInstalledPackages(string(installedOutput))
48 m.logger.WithField("count", len(installedPackages)).Debug("Found installed packages")
49 }
50
51 // Get upgradable packages (must run after apk update)
52 m.logger.Debug("Getting upgradable packages...")
53 upgradableCmd := exec.Command("apk", "-u", "list")
54 upgradableOutput, err := upgradableCmd.Output()
55 var upgradablePackages []models.Package
56 if err != nil {
57 m.logger.WithError(err).Warn("Failed to get upgradable packages")
58 upgradablePackages = []models.Package{}
59 } else {
60 m.logger.Debug("Parsing apk upgradable packages output...")
61 upgradablePackages = m.parseUpgradablePackages(string(upgradableOutput), installedPackages)
62 m.logger.WithField("count", len(upgradablePackages)).Debug("Found upgradable packages")
63 }
64
65 // Merge and deduplicate packages (pass full installed packages to preserve descriptions)
66 packages := CombinePackageData(installedPackages, upgradablePackages)
67
68 // Enrich packages with repository attribution
69 m.enrichWithRepoAttribution(packages)
70
71 m.logger.WithField("total", len(packages)).Debug("Total packages collected")
72
73 return packages
74}
75
76// enrichWithRepoAttribution populates SourceRepository for each package by running
77// apk policy in batches and extracting the logical repo name from the URL.

Callers

nothing calls this directly

Calls 4

CombinePackageDataFunction · 0.85

Tested by

no test coverage detected