all: Mac OS X is now called macOS

GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/4694
LGTM: imsodin
This commit is contained in:
Jakob Borg 2018-01-27 09:07:19 +00:00
parent e0931e201e
commit 050f9f8091
7 changed files with 65 additions and 16 deletions

View File

@ -87,8 +87,8 @@ D26E6ED000654A3E, available from https://syncthing.net/security.html and
most key servers. most key servers.
There is also a built in automatic upgrade mechanism (disabled in some There is also a built in automatic upgrade mechanism (disabled in some
distribution channels) which uses a compiled in ECDSA signature. Mac OS distribution channels) which uses a compiled in ECDSA signature. macOS
X binaries are also properly code signed. binaries are also properly code signed.
## Documentation ## Documentation

View File

@ -1,5 +1,5 @@
This directory contains an example for running Syncthing in the This directory contains an example for running Syncthing in the
background under Mac OS X. background under macOS.
1. Install the `syncthing` binary in a directory called `bin` in your 1. Install the `syncthing` binary in a directory called `bin` in your
home directory. home directory.

View File

@ -2151,7 +2151,7 @@ angular.module('syncthing.core')
} }
var os = { var os = {
'darwin': 'Mac OS X', 'darwin': 'macOS',
'dragonfly': 'DragonFly BSD', 'dragonfly': 'DragonFly BSD',
'freebsd': 'FreeBSD', 'freebsd': 'FreeBSD',
'openbsd': 'OpenBSD', 'openbsd': 'OpenBSD',

View File

@ -225,15 +225,20 @@ func versionParts(v string) ([]int, []interface{}) {
return release, prerelease return release, prerelease
} }
func releaseName(tag string) string { func releaseNames(tag string) []string {
// We must ensure that the release asset matches the expected naming // We must ensure that the release asset matches the expected naming
// standard, containing both the architecture/OS and the tag name we // standard, containing both the architecture/OS and the tag name we
// expect. This protects against malformed release data potentially // expect. This protects against malformed release data potentially
// tricking us into doing a downgrade. // tricking us into doing a downgrade.
switch runtime.GOOS { switch runtime.GOOS {
case "darwin": case "darwin":
return fmt.Sprintf("syncthing-macosx-%s-%s.", runtime.GOARCH, tag) return []string{
fmt.Sprintf("syncthing-macos-%s-%s.", runtime.GOARCH, tag),
fmt.Sprintf("syncthing-macosx-%s-%s.", runtime.GOARCH, tag),
}
default: default:
return fmt.Sprintf("syncthing-%s-%s-%s.", runtime.GOOS, runtime.GOARCH, tag) return []string{
fmt.Sprintf("syncthing-%s-%s-%s.", runtime.GOOS, runtime.GOARCH, tag),
}
} }
} }

View File

@ -147,13 +147,18 @@ func SelectLatestRelease(rels []Release, current string, upgradeToPreReleases bo
l.Debugln("skipping pre-release", rel.Tag) l.Debugln("skipping pre-release", rel.Tag)
continue continue
} }
expectedReleases := releaseNames(rel.Tag)
nextAsset:
for _, asset := range rel.Assets { for _, asset := range rel.Assets {
assetName := path.Base(asset.Name) assetName := path.Base(asset.Name)
// Check for the architecture // Check for the architecture
expectedRelease := releaseName(rel.Tag) for _, expRel := range expectedReleases {
if strings.HasPrefix(assetName, expectedRelease) { if strings.HasPrefix(assetName, expRel) {
l.Debugln("selected", rel.Tag) l.Debugln("selected", rel.Tag)
selected = rel selected = rel
break nextAsset
}
} }
} }
} }
@ -167,16 +172,17 @@ func SelectLatestRelease(rels []Release, current string, upgradeToPreReleases bo
// Upgrade to the given release, saving the previous binary with a ".old" extension. // Upgrade to the given release, saving the previous binary with a ".old" extension.
func upgradeTo(binary string, rel Release) error { func upgradeTo(binary string, rel Release) error {
expectedRelease := releaseName(rel.Tag) expectedReleases := releaseNames(rel.Tag)
l.Debugf("expected release asset %q", expectedRelease)
for _, asset := range rel.Assets { for _, asset := range rel.Assets {
assetName := path.Base(asset.Name) assetName := path.Base(asset.Name)
l.Debugln("considering release", assetName) l.Debugln("considering release", assetName)
if strings.HasPrefix(assetName, expectedRelease) { for _, expRel := range expectedReleases {
if strings.HasPrefix(assetName, expRel) {
return upgradeToURL(assetName, binary, asset.URL) return upgradeToURL(assetName, binary, asset.URL)
} }
} }
}
return ErrNoReleaseDownload return ErrNoReleaseDownload
} }

View File

@ -9,6 +9,7 @@
package upgrade package upgrade
import ( import (
"runtime"
"strings" "strings"
"testing" "testing"
) )
@ -100,7 +101,7 @@ func TestSelectedRelease(t *testing.T) {
Prerelease: strings.Contains(c, "-"), Prerelease: strings.Contains(c, "-"),
Assets: []Asset{ Assets: []Asset{
// There must be a matching asset or it will not get selected // There must be a matching asset or it will not get selected
{Name: releaseName(c)}, {Name: releaseNames(c)[0]},
}, },
}) })
} }
@ -115,3 +116,40 @@ func TestSelectedRelease(t *testing.T) {
} }
} }
} }
func TestSelectedReleaseMacOS(t *testing.T) {
if runtime.GOOS != "darwin" {
t.Skip("macOS only")
}
// The alterantives that we expect should work
assetNames := []string{
"syncthing-macos-amd64-v0.14.47.tar.gz",
"syncthing-macosx-amd64-v0.14.47.tar.gz",
}
for _, assetName := range assetNames {
// Provide one release with the given asset name
rels := []Release{
{
Tag: "v0.14.47",
Prerelease: false,
Assets: []Asset{
{Name: assetName},
},
},
}
// Check that it is selected and the asset is as epected
sel, err := SelectLatestRelease(rels, "v0.14.46", false)
if err != nil {
t.Fatal("Unexpected error:", err)
}
if sel.Tag != "v0.14.47" {
t.Error("wrong tag selected:", sel.Tag)
}
if sel.Assets[0].Name != assetName {
t.Error("wrong asset selected:", sel.Assets[0].Name)
}
}
}