From bb620b3d9b5d28363d932db438a6c36369f3bdc5 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Fri, 22 Nov 2024 19:11:36 -0600 Subject: [PATCH] to build or not to build is the question --- wit.go | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/wit.go b/wit.go index 0f68aae..6a19efa 100644 --- a/wit.go +++ b/wit.go @@ -24,6 +24,57 @@ func (m *Machine) IsInstalled(name string) bool { return false } +func (m *Machine) FindInstalledByName(name string) *Package { + loop := m.Packages.SortByName() + for loop.Scan() { + p := loop.Package() + if name == p.Name { + // log.Info("package installed:", p.Name, p.Version, p.PkgName) + return p + } + } + + // log.Info("package not-installed:", name) + return nil +} + +// looks to see if any package matches a name and version +// if version == "", return the first name found +func (m *Machine) FindVersion(name string, version string) *Package { + // first check all installed versions + loop := m.Packages.SortByName() + for loop.Scan() { + p := loop.Package() + if name == p.Name { + if version == "" { + return p + } else { + if version == p.Version { + return p + } + } + } + } + + // check all wit packages + loop = m.Wit.SortByName() + for loop.Scan() { + p := loop.Package() + if name == p.Name { + if version == "" { + return p + } else { + if version == p.Version { + return p + } + } + } + } + + // log.Info("package not-installed:", name) + return nil +} + // read the package list file from mirrors.wit.com func (m *Machine) InitWit() error { if m.Wit == nil {