Allow a single upgrade at a time
This commit is contained in:
parent
56d0ecc253
commit
59ffec4e39
|
@ -9,6 +9,8 @@ import (
|
|||
"errors"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"bitbucket.org/kardianos/osext"
|
||||
)
|
||||
|
||||
type Release struct {
|
||||
|
@ -26,8 +28,34 @@ var (
|
|||
ErrVersionUpToDate = errors.New("current version is up to date")
|
||||
ErrVersionUnknown = errors.New("couldn't fetch release information")
|
||||
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
|
||||
func CompareVersions(a, b string) int {
|
||||
arel, apre := versionParts(a)
|
||||
|
|
|
@ -19,17 +19,10 @@ import (
|
|||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
|
||||
"bitbucket.org/kardianos/osext"
|
||||
)
|
||||
|
||||
// Upgrade to the given release, saving the previous binary with a ".old" extension.
|
||||
func UpgradeTo(rel Release, archExtra string) error {
|
||||
path, err := osext.Executable()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
func upgradeTo(path string, rel Release, archExtra string) error {
|
||||
osName := runtime.GOOS
|
||||
if osName == "darwin" {
|
||||
// We call the darwin release bundles macosx because that makes more
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
package upgrade
|
||||
|
||||
func UpgradeTo(rel Release, extra string) error {
|
||||
func upgradeTo(path string, rel Release, extra string) error {
|
||||
return ErrUpgradeUnsupported
|
||||
}
|
||||
|
||||
|
|
|
@ -19,17 +19,10 @@ import (
|
|||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
|
||||
"bitbucket.org/kardianos/osext"
|
||||
)
|
||||
|
||||
// Upgrade to the given release, saving the previous binary with a ".old" extension.
|
||||
func UpgradeTo(rel Release, archExtra string) error {
|
||||
path, err := osext.Executable()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
func upgradeTo(path string, rel Release, archExtra string) error {
|
||||
expectedRelease := fmt.Sprintf("syncthing-%s-%s%s-%s.", runtime.GOOS, runtime.GOARCH, archExtra, rel.Tag)
|
||||
if debug {
|
||||
l.Debugf("expected release asset %q", expectedRelease)
|
||||
|
|
Loading…
Reference in New Issue