Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-11-18 20:13:22 -06:00
parent 82c559e657
commit 0ad4ffd0c6
2 changed files with 23 additions and 36 deletions

34
apt.go
View File

@ -37,37 +37,3 @@ func addNew(name string, version string) bool {
new1.Version = version
return me.packages.Append(new1)
}
func updatePackagesOld() {
// Get the list of installed packages for the detected distro
newP, err := getPackageList(me.distro)
if err != nil {
fmt.Println("Error:", err)
return
}
var newCounter, changeCounter int
// Print the installed packages and their versions
for pkg, version := range newP {
found := me.packages.FindByName(pkg)
if found == nil {
log.Info("adding new", pkg, version)
addNew(pkg, version)
newCounter += 1
} else {
found.Version = version
if me.packages.Update(found) {
changeCounter += 1
}
}
}
footer := fmt.Sprintf("%s has distro %s with %d packages installed", me.hostname, me.distro, me.packages.Len())
if changeCounter != 0 {
footer += fmt.Sprintf(" (%d changed)", changeCounter)
}
if newCounter != 0 {
footer += fmt.Sprintf(" (%d new)", newCounter)
}
log.Info(footer)
}

View File

@ -38,8 +38,11 @@ func updateMachine(u *zoopb.Machine) string {
if u.Packages == nil {
u.Packages = new(zoopb.Packages)
}
if zood := m.FindPackageByName("zood"); zood != nil {
log.Log(ZOOD, m.Hostname, "has zood version", zood.Version)
}
updatePackages(m.Packages, u.Packages)
updatePackages(m, u.Packages)
return "upgrade"
}
@ -47,8 +50,26 @@ func updateMachine(u *zoopb.Machine) string {
// changed versions
// were newly installed
// were uninstalled
func updatePackages(p *zoopb.Packages, u *zoopb.Packages) bool {
func updatePackages(m *zoopb.Machine, newp *zoopb.Packages) bool {
var changed bool = false
loop := newp.SortByName()
for loop.Scan() {
p := loop.Package()
if p.Name == "zood" {
if pold := m.FindPackageByName("zood"); pold == nil {
changed = true
log.Log(ZOOD, m.Hostname, "updatePackages() new package", p.Name , "version", p.Version)
m.Packages.Append(p)
} else {
if p.Version == pold.Version {
log.Log(ZOOD, m.Hostname, "updatePackages() unchanged", p.Version)
} else {
changed = true
log.Log(ZOOD, m.Hostname, "updatePackages() package", p.Name , "version changed", pold.Version, "to", p.Version)
}
}
}
}
return changed
}