Skip to content

Commit

Permalink
update regex to handle missing patch
Browse files Browse the repository at this point in the history
  • Loading branch information
rajkumarGosavi committed Oct 7, 2023
1 parent 6c01c6d commit 80ae074
Showing 1 changed file with 10 additions and 19 deletions.
29 changes: 10 additions & 19 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ func serverInfo(paClient *pulseaudio.Client) (audioserverinfo, error) {
var servername string
var servertype uint
var major, minor, patch int
var versionRegex, fallbackVersionRegex *regexp.Regexp
var versionRegex *regexp.Regexp
var versionString string

var outdatedPipeWire bool
Expand All @@ -254,32 +254,16 @@ func serverInfo(paClient *pulseaudio.Client) (audioserverinfo, error) {
} else {
servername = "PulseAudio"
servertype = servertype_pulse
versionRegex = regexp.MustCompile(`.*?(\d+)\.(\d+)\.(\d+).*?`)
fallbackVersionRegex = regexp.MustCompile(`.*?(\d+)\.(\d+).*?`)
versionRegex = regexp.MustCompile(`.*?(\d+)\.(\d+)\.?(\d+)?.*?`)
versionString = info.PackageVersion
log.Printf("Detected PulseAudio\n")
}

res := versionRegex.FindStringSubmatch(versionString)
if len(res) != 4 {
if fallbackVersionRegex == nil {
log.Printf("couldn't parse server version, regexp didn't match version: %s\n", versionString)
return audioserverinfo{servertype: servertype}, nil
}
}

// the server version did not match the standard `major.minor.patch` regex
// now trying with fallback regex of style `major.minor`

res = fallbackVersionRegex.FindStringSubmatch(versionString)
if len(res) != 3 {
log.Printf("couldn't parse server version, fallback regexp didn't match version: %s\n", versionString)
log.Printf("couldn't parse server version, regexp didn't match version: %s\n", versionString)
return audioserverinfo{servertype: servertype}, nil
} else {
// set patch number as `0` by default if patch is not provided by the server version
res = append(res, "0")
}

major, err = strconv.Atoi(res[1])
if err != nil {
return audioserverinfo{servertype: servertype}, err
Expand All @@ -288,6 +272,13 @@ func serverInfo(paClient *pulseaudio.Client) (audioserverinfo, error) {
if err != nil {
return audioserverinfo{servertype: servertype}, err
}

// the server version did not match the standard `major.minor.patch` pattern
// setting the patch version to default 0
if res[3] == "" {
res[3] = "0"
}

patch, err = strconv.Atoi(res[3])
if err != nil {
return audioserverinfo{servertype: servertype}, err
Expand Down

0 comments on commit 80ae074

Please sign in to comment.