Allow a single upgrade at a time
This commit is contained in:
@@ -9,6 +9,8 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"bitbucket.org/kardianos/osext"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Release struct {
|
type Release struct {
|
||||||
@@ -26,8 +28,34 @@ var (
|
|||||||
ErrVersionUpToDate = errors.New("current version is up to date")
|
ErrVersionUpToDate = errors.New("current version is up to date")
|
||||||
ErrVersionUnknown = errors.New("couldn't fetch release information")
|
ErrVersionUnknown = errors.New("couldn't fetch release information")
|
||||||
ErrUpgradeUnsupported = errors.New("upgrade unsupported")
|
ErrUpgradeUnsupported = errors.New("upgrade unsupported")
|
||||||
|
ErrUpgradeInProgress = errors.New("upgrade already in progress")
|
||||||
|
upgradeUnlocked = make(chan bool, 1)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
upgradeUnlocked <- true
|
||||||
|
}
|
||||||
|
|
||||||
|
// A wrapper around actual implementations
|
||||||
|
func UpgradeTo(rel Release, archExtra string) error {
|
||||||
|
select {
|
||||||
|
case <-upgradeUnlocked:
|
||||||
|
path, err := osext.Executable()
|
||||||
|
if err != nil {
|
||||||
|
upgradeUnlocked <- true
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = upgradeTo(path, rel, archExtra)
|
||||||
|
// If we've failed to upgrade, unlock so that another attempt could be made
|
||||||
|
if err != nil {
|
||||||
|
upgradeUnlocked <- true
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
default:
|
||||||
|
return ErrUpgradeInProgress
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Returns 1 if a>b, -1 if a<b and 0 if they are equal
|
// Returns 1 if a>b, -1 if a<b and 0 if they are equal
|
||||||
func CompareVersions(a, b string) int {
|
func CompareVersions(a, b string) int {
|
||||||
arel, apre := versionParts(a)
|
arel, apre := versionParts(a)
|
||||||
|
|||||||
@@ -19,17 +19,10 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"bitbucket.org/kardianos/osext"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// 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(rel Release, archExtra string) error {
|
func upgradeTo(path string, rel Release, archExtra string) error {
|
||||||
path, err := osext.Executable()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
osName := runtime.GOOS
|
osName := runtime.GOOS
|
||||||
if osName == "darwin" {
|
if osName == "darwin" {
|
||||||
// We call the darwin release bundles macosx because that makes more
|
// We call the darwin release bundles macosx because that makes more
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
package upgrade
|
package upgrade
|
||||||
|
|
||||||
func UpgradeTo(rel Release, extra string) error {
|
func upgradeTo(path string, rel Release, extra string) error {
|
||||||
return ErrUpgradeUnsupported
|
return ErrUpgradeUnsupported
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,17 +19,10 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"bitbucket.org/kardianos/osext"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// 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(rel Release, archExtra string) error {
|
func upgradeTo(path string, rel Release, archExtra string) error {
|
||||||
path, err := osext.Executable()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
expectedRelease := fmt.Sprintf("syncthing-%s-%s%s-%s.", runtime.GOOS, runtime.GOARCH, archExtra, rel.Tag)
|
expectedRelease := fmt.Sprintf("syncthing-%s-%s%s-%s.", runtime.GOOS, runtime.GOARCH, archExtra, rel.Tag)
|
||||||
if debug {
|
if debug {
|
||||||
l.Debugf("expected release asset %q", expectedRelease)
|
l.Debugf("expected release asset %q", expectedRelease)
|
||||||
|
|||||||
Reference in New Issue
Block a user