Merge pull request #305 from safing/fix/update-notification
Allow manual updates even if automatic ones are disabled
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user