From 050f9f809181f39d258eb1e665e00d3090a9a96b Mon Sep 17 00:00:00 2001 From: Jakob Borg Date: Sat, 27 Jan 2018 09:07:19 +0000 Subject: [PATCH] all: Mac OS X is now called macOS GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/4694 LGTM: imsodin --- README.md | 4 +- .../README.md | 2 +- .../syncthing.plist | 0 .../syncthing/core/syncthingController.js | 2 +- lib/upgrade/upgrade_common.go | 11 +++-- lib/upgrade/upgrade_supported.go | 22 ++++++---- lib/upgrade/upgrade_test.go | 40 ++++++++++++++++++- 7 files changed, 65 insertions(+), 16 deletions(-) rename etc/{macosx-launchd => macos-launchd}/README.md (96%) rename etc/{macosx-launchd => macos-launchd}/syncthing.plist (100%) diff --git a/README.md b/README.md index 1ab81a2c9..735d407a3 100644 --- a/README.md +++ b/README.md @@ -87,8 +87,8 @@ D26E6ED000654A3E, available from https://syncthing.net/security.html and most key servers. There is also a built in automatic upgrade mechanism (disabled in some -distribution channels) which uses a compiled in ECDSA signature. Mac OS -X binaries are also properly code signed. +distribution channels) which uses a compiled in ECDSA signature. macOS +binaries are also properly code signed. ## Documentation diff --git a/etc/macosx-launchd/README.md b/etc/macos-launchd/README.md similarity index 96% rename from etc/macosx-launchd/README.md rename to etc/macos-launchd/README.md index b5249c2ae..f5656deed 100644 --- a/etc/macosx-launchd/README.md +++ b/etc/macos-launchd/README.md @@ -1,5 +1,5 @@ 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 home directory. diff --git a/etc/macosx-launchd/syncthing.plist b/etc/macos-launchd/syncthing.plist similarity index 100% rename from etc/macosx-launchd/syncthing.plist rename to etc/macos-launchd/syncthing.plist diff --git a/gui/default/syncthing/core/syncthingController.js b/gui/default/syncthing/core/syncthingController.js index b4c06e1d6..f2e83de2f 100755 --- a/gui/default/syncthing/core/syncthingController.js +++ b/gui/default/syncthing/core/syncthingController.js @@ -2151,7 +2151,7 @@ angular.module('syncthing.core') } var os = { - 'darwin': 'Mac OS X', + 'darwin': 'macOS', 'dragonfly': 'DragonFly BSD', 'freebsd': 'FreeBSD', 'openbsd': 'OpenBSD', diff --git a/lib/upgrade/upgrade_common.go b/lib/upgrade/upgrade_common.go index 6e8f3581b..76a195382 100644 --- a/lib/upgrade/upgrade_common.go +++ b/lib/upgrade/upgrade_common.go @@ -225,15 +225,20 @@ func versionParts(v string) ([]int, []interface{}) { return release, prerelease } -func releaseName(tag string) string { +func releaseNames(tag string) []string { // We must ensure that the release asset matches the expected naming // standard, containing both the architecture/OS and the tag name we // expect. This protects against malformed release data potentially // tricking us into doing a downgrade. switch runtime.GOOS { 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: - 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), + } } } diff --git a/lib/upgrade/upgrade_supported.go b/lib/upgrade/upgrade_supported.go index d9b19a351..163b9a336 100644 --- a/lib/upgrade/upgrade_supported.go +++ b/lib/upgrade/upgrade_supported.go @@ -147,13 +147,18 @@ func SelectLatestRelease(rels []Release, current string, upgradeToPreReleases bo l.Debugln("skipping pre-release", rel.Tag) continue } + + expectedReleases := releaseNames(rel.Tag) + nextAsset: for _, asset := range rel.Assets { assetName := path.Base(asset.Name) // Check for the architecture - expectedRelease := releaseName(rel.Tag) - if strings.HasPrefix(assetName, expectedRelease) { - l.Debugln("selected", rel.Tag) - selected = rel + for _, expRel := range expectedReleases { + if strings.HasPrefix(assetName, expRel) { + l.Debugln("selected", rel.Tag) + selected = rel + break nextAsset + } } } } @@ -167,14 +172,15 @@ func SelectLatestRelease(rels []Release, current string, upgradeToPreReleases bo // Upgrade to the given release, saving the previous binary with a ".old" extension. func upgradeTo(binary string, rel Release) error { - expectedRelease := releaseName(rel.Tag) - l.Debugf("expected release asset %q", expectedRelease) + expectedReleases := releaseNames(rel.Tag) for _, asset := range rel.Assets { assetName := path.Base(asset.Name) l.Debugln("considering release", assetName) - if strings.HasPrefix(assetName, expectedRelease) { - return upgradeToURL(assetName, binary, asset.URL) + for _, expRel := range expectedReleases { + if strings.HasPrefix(assetName, expRel) { + return upgradeToURL(assetName, binary, asset.URL) + } } } diff --git a/lib/upgrade/upgrade_test.go b/lib/upgrade/upgrade_test.go index 5f688de0d..7ece02b3e 100644 --- a/lib/upgrade/upgrade_test.go +++ b/lib/upgrade/upgrade_test.go @@ -9,6 +9,7 @@ package upgrade import ( + "runtime" "strings" "testing" ) @@ -100,7 +101,7 @@ func TestSelectedRelease(t *testing.T) { Prerelease: strings.Contains(c, "-"), Assets: []Asset{ // 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) + } + } +}