mirror of
https://github.com/ProtonMail/proton-bridge.git
synced 2025-12-10 12:46:46 +00:00
GODT-1978: Don't install the same update twice
This commit is contained in:
@ -72,9 +72,14 @@ type Bridge struct {
|
|||||||
smtpListener net.Listener
|
smtpListener net.Listener
|
||||||
|
|
||||||
// updater is the bridge's updater.
|
// updater is the bridge's updater.
|
||||||
updater Updater
|
updater Updater
|
||||||
curVersion *semver.Version
|
installCh chan installJob
|
||||||
installCh chan installJob
|
|
||||||
|
// curVersion is the current version of the bridge,
|
||||||
|
// newVersion is the version that was installed by the updater.
|
||||||
|
curVersion *semver.Version
|
||||||
|
newVersion *semver.Version
|
||||||
|
newVersionLock safe.RWMutex
|
||||||
|
|
||||||
// focusService is used to raise the bridge window when needed.
|
// focusService is used to raise the bridge window when needed.
|
||||||
focusService *focus.Service
|
focusService *focus.Service
|
||||||
@ -240,9 +245,12 @@ func newBridge(
|
|||||||
imapServer: imapServer,
|
imapServer: imapServer,
|
||||||
imapEventCh: imapEventCh,
|
imapEventCh: imapEventCh,
|
||||||
|
|
||||||
updater: updater,
|
updater: updater,
|
||||||
curVersion: curVersion,
|
installCh: make(chan installJob),
|
||||||
installCh: make(chan installJob, 1),
|
|
||||||
|
curVersion: curVersion,
|
||||||
|
newVersion: curVersion,
|
||||||
|
newVersionLock: safe.NewRWMutex(),
|
||||||
|
|
||||||
focusService: focusService,
|
focusService: focusService,
|
||||||
autostarter: autostarter,
|
autostarter: autostarter,
|
||||||
|
|||||||
@ -21,6 +21,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
|
|
||||||
"github.com/ProtonMail/proton-bridge/v2/internal/events"
|
"github.com/ProtonMail/proton-bridge/v2/internal/events"
|
||||||
|
"github.com/ProtonMail/proton-bridge/v2/internal/safe"
|
||||||
"github.com/ProtonMail/proton-bridge/v2/internal/updater"
|
"github.com/ProtonMail/proton-bridge/v2/internal/updater"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
@ -86,21 +87,19 @@ func (bridge *Bridge) handleUpdate(version updater.VersionInfo) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
default:
|
default:
|
||||||
log.Info("An update is available")
|
safe.RLock(func() {
|
||||||
|
if version.Version.GreaterThan(bridge.newVersion) {
|
||||||
|
log.Info("An update is available")
|
||||||
|
|
||||||
bridge.publish(events.UpdateAvailable{
|
select {
|
||||||
Version: version,
|
case bridge.installCh <- installJob{version: version, silent: true}:
|
||||||
Compatible: true,
|
log.Info("The update will be installed silently")
|
||||||
Silent: true,
|
|
||||||
})
|
|
||||||
|
|
||||||
select {
|
default:
|
||||||
case bridge.installCh <- installJob{version: version, silent: true}:
|
log.Info("An update is already being installed")
|
||||||
log.Info("The update will be installed silently")
|
}
|
||||||
|
}
|
||||||
default:
|
}, bridge.newVersionLock)
|
||||||
log.Info("An update is already being installed")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -110,31 +109,41 @@ type installJob struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (bridge *Bridge) installUpdate(ctx context.Context, job installJob) {
|
func (bridge *Bridge) installUpdate(ctx context.Context, job installJob) {
|
||||||
log := logrus.WithFields(logrus.Fields{
|
safe.Lock(func() {
|
||||||
"version": job.version.Version,
|
log := logrus.WithFields(logrus.Fields{
|
||||||
"current": bridge.curVersion,
|
"version": job.version.Version,
|
||||||
"channel": bridge.vault.GetUpdateChannel(),
|
"current": bridge.curVersion,
|
||||||
})
|
"channel": bridge.vault.GetUpdateChannel(),
|
||||||
|
|
||||||
bridge.publish(events.UpdateInstalling{
|
|
||||||
Version: job.version,
|
|
||||||
Silent: job.silent,
|
|
||||||
})
|
|
||||||
|
|
||||||
if err := bridge.updater.InstallUpdate(ctx, bridge.api, job.version); err != nil {
|
|
||||||
log.Error("The update could not be installed")
|
|
||||||
|
|
||||||
bridge.publish(events.UpdateFailed{
|
|
||||||
Version: job.version,
|
|
||||||
Silent: job.silent,
|
|
||||||
Error: err,
|
|
||||||
})
|
})
|
||||||
} else {
|
|
||||||
log.Info("The update was installed successfully")
|
|
||||||
|
|
||||||
bridge.publish(events.UpdateInstalled{
|
bridge.publish(events.UpdateAvailable{
|
||||||
|
Version: job.version,
|
||||||
|
Compatible: true,
|
||||||
|
Silent: job.silent,
|
||||||
|
})
|
||||||
|
|
||||||
|
bridge.publish(events.UpdateInstalling{
|
||||||
Version: job.version,
|
Version: job.version,
|
||||||
Silent: job.silent,
|
Silent: job.silent,
|
||||||
})
|
})
|
||||||
}
|
|
||||||
|
if err := bridge.updater.InstallUpdate(ctx, bridge.api, job.version); err != nil {
|
||||||
|
log.Error("The update could not be installed")
|
||||||
|
|
||||||
|
bridge.publish(events.UpdateFailed{
|
||||||
|
Version: job.version,
|
||||||
|
Silent: job.silent,
|
||||||
|
Error: err,
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
log.Info("The update was installed successfully")
|
||||||
|
|
||||||
|
bridge.publish(events.UpdateInstalled{
|
||||||
|
Version: job.version,
|
||||||
|
Silent: job.silent,
|
||||||
|
})
|
||||||
|
|
||||||
|
bridge.newVersion = job.version.Version
|
||||||
|
}
|
||||||
|
}, bridge.newVersionLock)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -109,5 +109,5 @@ type UpdateForced struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (event UpdateForced) String() string {
|
func (event UpdateForced) String() string {
|
||||||
return fmt.Sprintf("UpdateForced")
|
return "UpdateForced"
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user