mirror of
https://github.com/octoleo/syncthing.git
synced 2024-11-12 16:26:37 +00:00
Connecting to a newer node triggers autoupgrade check (fixes #1177)
This commit is contained in:
parent
5d173168cc
commit
5034a41c08
@ -1259,28 +1259,35 @@ func standbyMonitor() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func autoUpgrade() {
|
func autoUpgrade() {
|
||||||
var skipped bool
|
timer := time.NewTimer(0)
|
||||||
interval := time.Duration(cfg.Options().AutoUpgradeIntervalH) * time.Hour
|
sub := events.Default.Subscribe(events.DeviceConnected)
|
||||||
for {
|
for {
|
||||||
if skipped {
|
select {
|
||||||
time.Sleep(interval)
|
case event := <-sub.C():
|
||||||
} else {
|
data, ok := event.Data.(map[string]string)
|
||||||
skipped = true
|
if !ok || data["clientName"] != "syncthing" || upgrade.CompareVersions(data["clientVersion"], Version) != upgrade.Newer {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
l.Infof("Connected to device %s with a newer version (current %q < remote %q). Checking for upgrades.", data["id"], Version, data["clientVersion"])
|
||||||
|
case <-timer.C:
|
||||||
}
|
}
|
||||||
|
|
||||||
rel, err := upgrade.LatestRelease(IsBeta)
|
rel, err := upgrade.LatestRelease(IsBeta)
|
||||||
if err == upgrade.ErrUpgradeUnsupported {
|
if err == upgrade.ErrUpgradeUnsupported {
|
||||||
|
events.Default.Unsubscribe(sub)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Don't complain too loudly here; we might simply not have
|
// Don't complain too loudly here; we might simply not have
|
||||||
// internet connectivity, or the upgrade server might be down.
|
// internet connectivity, or the upgrade server might be down.
|
||||||
l.Infoln("Automatic upgrade:", err)
|
l.Infoln("Automatic upgrade:", err)
|
||||||
|
timer.Reset(time.Duration(cfg.Options().AutoUpgradeIntervalH) * time.Hour)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if upgrade.CompareVersions(rel.Tag, Version) != upgrade.Newer {
|
if upgrade.CompareVersions(rel.Tag, Version) != upgrade.Newer {
|
||||||
// Skip equal, older or majorly newer (incompatible) versions
|
// Skip equal, older or majorly newer (incompatible) versions
|
||||||
|
timer.Reset(time.Duration(cfg.Options().AutoUpgradeIntervalH) * time.Hour)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1288,8 +1295,10 @@ func autoUpgrade() {
|
|||||||
err = upgrade.To(rel)
|
err = upgrade.To(rel)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
l.Warnln("Automatic upgrade:", err)
|
l.Warnln("Automatic upgrade:", err)
|
||||||
|
timer.Reset(time.Duration(cfg.Options().AutoUpgradeIntervalH) * time.Hour)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
events.Default.Unsubscribe(sub)
|
||||||
l.Warnf("Automatically upgraded to version %q. Restarting in 1 minute.", rel.Tag)
|
l.Warnf("Automatically upgraded to version %q. Restarting in 1 minute.", rel.Tag)
|
||||||
time.Sleep(time.Minute)
|
time.Sleep(time.Minute)
|
||||||
stop <- exitUpgrading
|
stop <- exitUpgrading
|
||||||
|
@ -187,6 +187,10 @@ func (s *Subscription) Poll(timeout time.Duration) (Event, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Subscription) C() <-chan Event {
|
||||||
|
return s.events
|
||||||
|
}
|
||||||
|
|
||||||
type BufferedSubscription struct {
|
type BufferedSubscription struct {
|
||||||
sub *Subscription
|
sub *Subscription
|
||||||
buf []Event
|
buf []Event
|
||||||
|
@ -577,8 +577,21 @@ func (m *Model) ClusterConfig(deviceID protocol.DeviceID, cm protocol.ClusterCon
|
|||||||
} else {
|
} else {
|
||||||
m.deviceVer[deviceID] = cm.ClientName + " " + cm.ClientVersion
|
m.deviceVer[deviceID] = cm.ClientName + " " + cm.ClientVersion
|
||||||
}
|
}
|
||||||
|
|
||||||
|
event := map[string]string{
|
||||||
|
"id": deviceID.String(),
|
||||||
|
"clientName": cm.ClientName,
|
||||||
|
"clientVersion": cm.ClientVersion,
|
||||||
|
}
|
||||||
|
|
||||||
|
if conn, ok := m.rawConn[deviceID].(*tls.Conn); ok {
|
||||||
|
event["addr"] = conn.RemoteAddr().String()
|
||||||
|
}
|
||||||
|
|
||||||
m.pmut.Unlock()
|
m.pmut.Unlock()
|
||||||
|
|
||||||
|
events.Default.Log(events.DeviceConnected, event)
|
||||||
|
|
||||||
l.Infof(`Device %s client is "%s %s"`, deviceID, cm.ClientName, cm.ClientVersion)
|
l.Infof(`Device %s client is "%s %s"`, deviceID, cm.ClientName, cm.ClientVersion)
|
||||||
|
|
||||||
var changed bool
|
var changed bool
|
||||||
|
Loading…
Reference in New Issue
Block a user