Split dpkg-query fields with a tab

We were previously splitting on a space which depended on Status-Abbrev only using 1 or 2 of its 3 character width.
When Status-Abbrev has 3 non-whitespace characters the parsing fails. Now we use tab delimiters and trim off any whitespace after splitting.
This commit is contained in:
Peter Rifel 2025-02-19 20:36:32 -06:00
parent 12931dd99d
commit 24fb33dad3
No known key found for this signature in database
1 changed files with 4 additions and 4 deletions

View File

@ -145,7 +145,7 @@ func (e *Package) Find(c *fi.NodeupContext) (*Package, error) {
}
func (e *Package) findDpkg(c *fi.NodeupContext) (*Package, error) {
args := []string{"dpkg-query", "-f", "${db:Status-Abbrev}${Version}\\n", "-W", e.Name}
args := []string{"dpkg-query", "-f", "${db:Status-Abbrev}\\t${Version}\\n", "-W", e.Name}
human := strings.Join(args, " ")
klog.V(2).Infof("Listing installed packages: %s", human)
@ -166,12 +166,12 @@ func (e *Package) findDpkg(c *fi.NodeupContext) (*Package, error) {
continue
}
tokens := strings.Split(line, " ")
tokens := strings.Split(line, "\t")
if len(tokens) != 2 {
return nil, fmt.Errorf("error parsing dpkg-query line %q", line)
}
state := tokens[0]
version := tokens[1]
state := strings.TrimSpace(tokens[0])
version := strings.TrimSpace(tokens[1])
switch state {
case "ii":