From befe7a1cd7c8b81c88622a6e85a5a84200ad5b0d Mon Sep 17 00:00:00 2001 From: Patrick Pacher Date: Mon, 17 May 2021 16:04:03 +0200 Subject: [PATCH] Allow manual updates even if automatic ones are disabled --- updates/api.go | 3 ++- updates/config.go | 4 +++- updates/main.go | 8 +++++--- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/updates/api.go b/updates/api.go index 59edc460..44ffed6f 100644 --- a/updates/api.go +++ b/updates/api.go @@ -14,7 +14,8 @@ func registerAPIEndpoints() error { Write: api.PermitUser, BelongsTo: module, ActionFunc: func(_ *api.Request) (msg string, err error) { - if err := TriggerUpdate(true); err != nil { + forceUpdate.Set() + if err := TriggerUpdate(); err != nil { return "", err } return "triggered update check", nil diff --git a/updates/config.go b/updates/config.go index f282a5d3..2889029c 100644 --- a/updates/config.go +++ b/updates/config.go @@ -4,6 +4,7 @@ import ( "context" "github.com/safing/portbase/notifications" + "github.com/tevino/abool" "github.com/safing/portbase/config" "github.com/safing/portbase/log" @@ -22,6 +23,7 @@ var ( previousReleaseChannel string updatesCurrentlyEnabled bool previousDevMode bool + forceUpdate = abool.New() ) func registerConfig() error { @@ -127,7 +129,7 @@ func updateRegistryConfig(_ context.Context, _ interface{}) error { if updatesCurrentlyEnabled { module.Resolve("") - if err := TriggerUpdate(false); err != nil { + if err := TriggerUpdate(); err != nil { log.Warningf("updates: failed to trigger update: %s", err) } log.Infof("updates: automatic updates are now enabled") diff --git a/updates/main.go b/updates/main.go index 86ad65b6..5f2000c6 100644 --- a/updates/main.go +++ b/updates/main.go @@ -232,7 +232,7 @@ func start() error { } // TriggerUpdate queues the update task to execute ASAP. -func TriggerUpdate(force bool) error { +func TriggerUpdate() error { switch { case !module.OnlineSoon(): return fmt.Errorf("updates module is disabled") @@ -240,7 +240,7 @@ func TriggerUpdate(force bool) error { case !module.Online(): updateASAP = true - case !force && !enableUpdates(): + case forceUpdate.IsNotSet() && !enableUpdates(): return fmt.Errorf("automatic updating is disabled") default: @@ -265,10 +265,12 @@ func DisableUpdateSchedule() error { } func checkForUpdates(ctx context.Context) (err error) { - if !updatesCurrentlyEnabled { + if !updatesCurrentlyEnabled && !forceUpdate.IsSet() { log.Debugf("updates: automatic updates are disabled") return nil } + forceUpdate.UnSet() + defer log.Debugf("updates: finished checking for updates") defer func() {