diff --git a/updates/main.go b/updates/main.go index a4092277..38f7ad9d 100644 --- a/updates/main.go +++ b/updates/main.go @@ -6,10 +6,10 @@ import ( "runtime" "time" + "github.com/safing/portbase/dataroot" "github.com/safing/portbase/log" "github.com/safing/portbase/modules" "github.com/safing/portbase/updater" - "github.com/safing/portmaster/core/structure" ) const ( @@ -67,7 +67,7 @@ func start() error { Online: true, } // initialize - err := registry.Initialize(structure.Root().ChildDir("updates", 0755)) + err := registry.Initialize(dataroot.Root().ChildDir("updates", 0755)) if err != nil { return err } @@ -91,12 +91,13 @@ func start() error { } // start updater task - module.NewTask("updater", func(ctx context.Context, task *modules.Task) { + module.NewTask("updater", func(ctx context.Context, task *modules.Task) error { err := registry.DownloadUpdates(ctx) if err != nil { - log.Warningf("updates: failed to update: %s", err) + return fmt.Errorf("updates: failed to update: %s", err) } module.TriggerEvent(eventResourceUpdate, nil) + return nil }).Repeat(24 * time.Hour).MaxDelay(1 * time.Hour).Schedule(time.Now().Add(10 * time.Second)) // react to upgrades diff --git a/updates/testing.go b/updates/testing.go deleted file mode 100644 index c2c8472a..00000000 --- a/updates/testing.go +++ /dev/null @@ -1,53 +0,0 @@ -package updates - -import ( - "os" - "path/filepath" - - "github.com/safing/portbase/log" - "github.com/safing/portbase/updater" - "github.com/safing/portbase/utils" -) - -// InitForTesting initializes the update module directly. This is intended to be only used by unit tests that require the updates module. -func InitForTesting() error { - // create registry - registry = &updater.ResourceRegistry{ - Name: "testing-updates", - UpdateURLs: []string{ - "https://updates.safing.io", - }, - Beta: false, - DevMode: false, - Online: true, - } - - // set data dir - root := utils.NewDirStructure( - filepath.Join(os.TempDir(), "pm-testing"), - 0755, - ) - err := root.Ensure() - if err != nil { - return err - } - - // initialize - err = registry.Initialize(root.ChildDir("updates", 0755)) - if err != nil { - return err - } - - err = registry.LoadIndexes() - if err != nil { - return err - } - - err = registry.ScanStorage("") - if err != nil { - log.Warningf("updates: error during storage scan: %s", err) - } - - registry.SelectVersions() - return nil -}