mirror of
https://github.com/octoleo/syncthing.git
synced 2025-01-03 15:17:25 +00:00
Guessing version from directory name is not viable in Go (ref #1449)
This commit is contained in:
parent
d2d894d808
commit
3532a560d8
26
build.go
26
build.go
@ -23,7 +23,6 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"compress/gzip"
|
"compress/gzip"
|
||||||
"crypto/md5"
|
"crypto/md5"
|
||||||
"errors"
|
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
@ -377,38 +376,15 @@ func getGitVersion() (string, error) {
|
|||||||
return string(v), nil
|
return string(v), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getDirectoryVersion() (string, error) {
|
|
||||||
wd, err := os.Getwd()
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
base := filepath.Base(filepath.Clean(wd))
|
|
||||||
|
|
||||||
re := regexp.MustCompile(`syncthing-(v?\d+\.\d+\.\d+)`)
|
|
||||||
parts := re.FindStringSubmatch(base)
|
|
||||||
|
|
||||||
if len(parts) != 2 {
|
|
||||||
return "", errors.New("not a release directory")
|
|
||||||
}
|
|
||||||
if strings.HasPrefix(parts[1], "v") {
|
|
||||||
return parts[1], nil
|
|
||||||
}
|
|
||||||
return "v" + parts[1], nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func getVersion() string {
|
func getVersion() string {
|
||||||
// First try for a RELEASE file,
|
// First try for a RELEASE file,
|
||||||
if ver, err := getReleaseVersion(); err == nil {
|
if ver, err := getReleaseVersion(); err == nil {
|
||||||
return ver
|
return ver
|
||||||
}
|
}
|
||||||
// ... then see if we have a Git tag,
|
// ... then see if we have a Git tag.
|
||||||
if ver, err := getGitVersion(); err == nil {
|
if ver, err := getGitVersion(); err == nil {
|
||||||
return ver
|
return ver
|
||||||
}
|
}
|
||||||
// ... otherwise try to guess from the directory name.
|
|
||||||
if ver, err := getDirectoryVersion(); err == nil {
|
|
||||||
return ver
|
|
||||||
}
|
|
||||||
// This seems to be a dev build.
|
// This seems to be a dev build.
|
||||||
return "unknown-dev"
|
return "unknown-dev"
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user