aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob Borg <jakob@kastelo.net>2023-07-12 09:27:34 +0200
committerJakob Borg <jakob@kastelo.net>2023-07-12 09:27:34 +0200
commit48c95eb41d7e393b585e488ec2b9cc82c6b8f467 (patch)
treeae1bb38963c277c00fbbc79868eb2d807e536801
parent937895be69fd79c17179afe22d681d27820c037d (diff)
downloadsyncthing-48c95eb41d7e393b585e488ec2b9cc82c6b8f467.tar.gz
syncthing-48c95eb41d7e393b585e488ec2b9cc82c6b8f467.zip
cmd/stcrashreceiver: Correct parsing of current version string
-rw-r--r--cmd/stcrashreceiver/sentry.go23
-rw-r--r--cmd/stcrashreceiver/sentry_test.go14
2 files changed, 34 insertions, 3 deletions
diff --git a/cmd/stcrashreceiver/sentry.go b/cmd/stcrashreceiver/sentry.go
index de8d91e57..73bfdc969 100644
--- a/cmd/stcrashreceiver/sentry.go
+++ b/cmd/stcrashreceiver/sentry.go
@@ -215,7 +215,13 @@ func crashReportFingerprint(message string) []string {
}
// syncthing v1.1.4-rc.1+30-g6aaae618-dirty-crashrep "Erbium Earthworm" (go1.12.5 darwin-amd64) jb@kvin.kastelo.net 2019-05-23 16:08:14 UTC [foo, bar]
-var longVersionRE = regexp.MustCompile(`syncthing\s+(v[^\s]+)\s+"([^"]+)"\s\(([^\s]+)\s+([^-]+)-([^)]+)\)\s+([^\s]+)[^\[]*(?:\[(.+)\])?$`)
+// or, somewhere along the way the "+" in the version tag disappeared:
+// syncthing v1.23.7-dev.26.gdf7b56ae.dirty-stversionextra "Fermium Flea" (go1.20.5 darwin-arm64) jb@ok.kastelo.net 2023-07-12 06:55:26 UTC [Some Wrapper, purego, stnoupgrade]
+var (
+ longVersionRE = regexp.MustCompile(`syncthing\s+(v[^\s]+)\s+"([^"]+)"\s\(([^\s]+)\s+([^-]+)-([^)]+)\)\s+([^\s]+)[^\[]*(?:\[(.+)\])?$`)
+ gitExtraRE = regexp.MustCompile(`\.\d+\.g[0-9a-f]+`) // ".1.g6aaae618"
+ gitExtraSepRE = regexp.MustCompile(`[.-]`) // dot or dash
+)
type version struct {
version string // "v1.1.4-rc.1+30-g6aaae618-dirty-crashrep"
@@ -257,10 +263,21 @@ func parseVersion(line string) (version, error) {
builder: m[6],
}
- parts := strings.Split(v.version, "+")
+ // Split the version tag into tag and commit. This is old style
+ // v1.2.3-something.4+11-g12345678 or newer with just dots
+ // v1.2.3-something.4.11.g12345678 or v1.2.3-dev.11.g12345678.
+ parts := []string{v.version}
+ if strings.Contains(v.version, "+") {
+ parts = strings.Split(v.version, "+")
+ } else {
+ idxs := gitExtraRE.FindStringIndex(v.version)
+ if len(idxs) > 0 {
+ parts = []string{v.version[:idxs[0]], v.version[idxs[0]+1:]}
+ }
+ }
v.tag = parts[0]
if len(parts) > 1 {
- fields := strings.Split(parts[1], "-")
+ fields := gitExtraSepRE.Split(parts[1], -1)
if len(fields) >= 2 && strings.HasPrefix(fields[1], "g") {
v.commit = fields[1][1:]
}
diff --git a/cmd/stcrashreceiver/sentry_test.go b/cmd/stcrashreceiver/sentry_test.go
index e052197c9..9fa30f262 100644
--- a/cmd/stcrashreceiver/sentry_test.go
+++ b/cmd/stcrashreceiver/sentry_test.go
@@ -44,6 +44,20 @@ func TestParseVersion(t *testing.T) {
extra: []string{"foo", "bar"},
},
},
+ {
+ longVersion: `syncthing v1.23.7-dev.26.gdf7b56ae-stversionextra "Fermium Flea" (go1.20.5 darwin-arm64) jb@ok.kastelo.net 2023-07-12 06:55:26 UTC [Some Wrapper, purego, stnoupgrade]`,
+ parsed: version{
+ version: "v1.23.7-dev.26.gdf7b56ae-stversionextra",
+ tag: "v1.23.7-dev",
+ commit: "df7b56ae",
+ codename: "Fermium Flea",
+ runtime: "go1.20.5",
+ goos: "darwin",
+ goarch: "arm64",
+ builder: "jb@ok.kastelo.net",
+ extra: []string{"Some Wrapper", "purego", "stnoupgrade"},
+ },
+ },
}
for _, tc := range cases {