Skip to content
This repository has been archived by the owner on Jan 6, 2023. It is now read-only.

Commit

Permalink
Fix handling of "swupd update" output
Browse files Browse the repository at this point in the history
"swupd update" changed its output, both directing messages to stdout
and changing the format of the "-s" output by adding an additional
line.
  • Loading branch information
bryteise committed Jun 14, 2019
1 parent 6c405aa commit d44cb76
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions cublib/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func GetFormat() (string, error) {
func GetVersion(uri string, statedir string) (string, error) {
cmd := exec.Command("swupd", "update", "-S", statedir, "-s", "-u", uri)
var out bytes.Buffer
cmd.Stderr = &out
cmd.Stdout = &out
err := cmd.Start()
if err != nil {
return "", err
Expand All @@ -62,6 +62,8 @@ func GetVersion(uri string, statedir string) (string, error) {
// Output is of the form:
// Current OS version: XXX
// Latest server version: YYY
// ZZZZZZZZZZZ
//
// Grab YYY
// TODO make a swupd-client check-update command to just give us this value.
if _, err = out.ReadBytes(':'); err != nil {
Expand All @@ -73,7 +75,11 @@ func GetVersion(uri string, statedir string) (string, error) {
if _, err = out.ReadByte(); err != nil {
return "", err
}
return strings.TrimSpace(out.String()), nil
var version []byte
if version, err = out.ReadBytes('\n'); err != nil {
return "", err
}
return strings.TrimSpace(string(version)), nil
}

// Take lock for a given statedir, causes program to exit if it would fail to get the lock.
Expand Down

0 comments on commit d44cb76

Please sign in to comment.