diff options
| author | Jeff Carr <[email protected]> | 2025-10-05 11:26:17 -0500 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2025-10-05 11:26:17 -0500 |
| commit | 9da07a667a769d30be1841b39e29ae5f8e95d3e7 (patch) | |
| tree | 3f896fbd07a5f37bce6277f8123422e3a44ea185 | |
| parent | e297b36df55b39a819d1c818ce1b74e8c9323772 (diff) | |
only keep newest packages
| -rw-r--r-- | wit.go | 44 |
1 files changed, 43 insertions, 1 deletions
@@ -4,6 +4,9 @@ import ( "bufio" "os" "strings" + + "go.wit.com/lib/fhelp" + "go.wit.com/log" ) func (m *Machine) IsInstalled(name string) bool { @@ -52,6 +55,22 @@ func (m *Machine) FindVersion(name string) string { return "" } +func (m *Machine) FindInstalledPackage(check *Package) *Package { + /* + for p := range m.Packages.IterByName() { + if (check.Name == p.Name) && (check.Version == p.Version) { + return p + } + } + */ + for p := range m.Wit.IterByName() { + if (check.Name == p.Name) && (check.Version == p.Version) { + return p + } + } + return nil +} + // looks to see if any package matches a name and version // if version == "", return the first name found func (m *Machine) FindByVersion(name string, version string) *Package { @@ -93,6 +112,29 @@ func (m *Machine) InitWitMirrors() error { return err } +// adds the package if the name isn't there +// if it's newer, remove the old package and use the new one +func (all *Packages) AddIfNewer(p *Package) { + check := all.FindByName(p.Name) + if check == nil { + all.Append(p) + return + } + v1, _ := fhelp.NewDebVersion(check.Version) + v2, _ := fhelp.NewDebVersion(p.Version) + if v1.Equal(v2) { + // log.Info("do nothing", v1, v2) + return + } + if v1.LessThan(v2) { + log.Info("removing", v1, "using", v2) + all.Delete(check) + all.Append(p) + } else { + log.Info("keeping", v1, "got:", v2) + } +} + // breaks up the apt list file into sections // then sends each section to be processed // and added to zoopb.Machine.Wit @@ -108,7 +150,7 @@ func (m *Machine) scanPackageListFile(filename string) error { line := scanner.Text() if line == "" { p := parsePackageInfo(debInfo) - m.Wit.Append(p) + m.Wit.AddIfNewer(p) debInfo = "" } debInfo += line + "\n" |
