Merge pull request #305 from safing/fix/update-notification

Allow manual updates even if automatic ones are disabled
This commit is contained in:
Daniel
2021-05-17 16:07:50 +02:00
committed by GitHub
3 changed files with 10 additions and 5 deletions

View File

@@ -14,7 +14,8 @@ func registerAPIEndpoints() error {
Write: api.PermitUser, Write: api.PermitUser,
BelongsTo: module, BelongsTo: module,
ActionFunc: func(_ *api.Request) (msg string, err error) { ActionFunc: func(_ *api.Request) (msg string, err error) {
if err := TriggerUpdate(true); err != nil { forceUpdate.Set()
if err := TriggerUpdate(); err != nil {
return "", err return "", err
} }
return "triggered update check", nil return "triggered update check", nil

View File

@@ -4,6 +4,7 @@ import (
"context" "context"
"github.com/safing/portbase/notifications" "github.com/safing/portbase/notifications"
"github.com/tevino/abool"
"github.com/safing/portbase/config" "github.com/safing/portbase/config"
"github.com/safing/portbase/log" "github.com/safing/portbase/log"
@@ -22,6 +23,7 @@ var (
previousReleaseChannel string previousReleaseChannel string
updatesCurrentlyEnabled bool updatesCurrentlyEnabled bool
previousDevMode bool previousDevMode bool
forceUpdate = abool.New()
) )
func registerConfig() error { func registerConfig() error {
@@ -127,7 +129,7 @@ func updateRegistryConfig(_ context.Context, _ interface{}) error {
if updatesCurrentlyEnabled { if updatesCurrentlyEnabled {
module.Resolve("") module.Resolve("")
if err := TriggerUpdate(false); err != nil { if err := TriggerUpdate(); err != nil {
log.Warningf("updates: failed to trigger update: %s", err) log.Warningf("updates: failed to trigger update: %s", err)
} }
log.Infof("updates: automatic updates are now enabled") log.Infof("updates: automatic updates are now enabled")

View File

@@ -232,7 +232,7 @@ func start() error {
} }
// TriggerUpdate queues the update task to execute ASAP. // TriggerUpdate queues the update task to execute ASAP.
func TriggerUpdate(force bool) error { func TriggerUpdate() error {
switch { switch {
case !module.OnlineSoon(): case !module.OnlineSoon():
return fmt.Errorf("updates module is disabled") return fmt.Errorf("updates module is disabled")
@@ -240,7 +240,7 @@ func TriggerUpdate(force bool) error {
case !module.Online(): case !module.Online():
updateASAP = true updateASAP = true
case !force && !enableUpdates(): case forceUpdate.IsNotSet() && !enableUpdates():
return fmt.Errorf("automatic updating is disabled") return fmt.Errorf("automatic updating is disabled")
default: default:
@@ -265,10 +265,12 @@ func DisableUpdateSchedule() error {
} }
func checkForUpdates(ctx context.Context) (err error) { func checkForUpdates(ctx context.Context) (err error) {
if !updatesCurrentlyEnabled { if !updatesCurrentlyEnabled && !forceUpdate.IsSet() {
log.Debugf("updates: automatic updates are disabled") log.Debugf("updates: automatic updates are disabled")
return nil return nil
} }
forceUpdate.UnSet()
defer log.Debugf("updates: finished checking for updates") defer log.Debugf("updates: finished checking for updates")
defer func() { defer func() {