Adapt updates package to new structure

This commit is contained in:
Daniel
2020-03-20 23:03:54 +01:00
parent f1a2a4d3e8
commit d4d7938f0e
2 changed files with 5 additions and 57 deletions

View File

@@ -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

View File

@@ -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
}