diff --git a/updater/registry.go b/updater/registry.go index fa7fe96..1f031c1 100644 --- a/updater/registry.go +++ b/updater/registry.go @@ -57,6 +57,18 @@ func (reg *ResourceRegistry) Initialize(storageDir *utils.DirStructure) error { reg.tmpDir = storageDir.ChildDir("tmp", 0700) reg.resources = make(map[string]*Resource) + // remove tmp dir to delete old entries + err = reg.Cleanup() + if err != nil { + log.Warningf("%s: failed to remove tmp dir: %s", reg.Name, err) + } + + // (re-)create tmp dir + reg.tmpDir.Ensure() + if err != nil { + log.Warningf("%s: failed to create tmp dir: %s", reg.Name, err) + } + return nil } diff --git a/updater/storage.go b/updater/storage.go index 5e6de27..f444d04 100644 --- a/updater/storage.go +++ b/updater/storage.go @@ -82,7 +82,9 @@ func (reg *ResourceRegistry) LoadIndexes() error { var firstErr error for _, idx := range reg.getIndexes() { err := reg.loadIndexFile(idx) - if err != nil && reg.Online { + if err == nil { + log.Debugf("%s: loaded index %s", reg.Name, idx.Path) + } else if reg.Online { // try to download the index file if a local disk version // does not exist or we don't have permission to read it. if os.IsNotExist(err) || os.IsPermission(err) { diff --git a/updater/updating.go b/updater/updating.go index 7ead3ab..8e1a4cc 100644 --- a/updater/updating.go +++ b/updater/updating.go @@ -5,7 +5,6 @@ import ( "encoding/json" "fmt" "io/ioutil" - "os" "path/filepath" "github.com/safing/portbase/utils" @@ -56,7 +55,10 @@ func (reg *ResourceRegistry) downloadIndex(idx Index) error { } // add resources to registry - _ = reg.AddResources(new, false, idx.Stable, idx.Beta) + err = reg.AddResources(new, false, idx.Stable, idx.Beta) + if err != nil { + log.Warningf("%s: failed to add resources: %s", reg.Name, err) + } // save index err = ioutil.WriteFile(filepath.Join(reg.storageDir.Path, idx.Path), data, 0644) @@ -121,11 +123,5 @@ func (reg *ResourceRegistry) DownloadUpdates(ctx context.Context) error { } log.Infof("%s: finished downloading updates", reg.Name) - // remove tmp folder after we are finished - err = os.RemoveAll(reg.tmpDir.Path) - if err != nil { - log.Tracef("%s: failed to remove tmp dir %s after downloading updates: %s", reg.Name, reg.tmpDir.Path, err) - } - return nil }