Skip to content

Commit

Permalink
Split dpkg-query fields with a tab
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rifelpet committed Feb 20, 2025
1 parent 12931dd commit 24fb33d
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions upup/pkg/fi/nodeup/nodetasks/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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":
Expand Down

0 comments on commit 24fb33d

Please sign in to comment.