From 98589f80087b81bfae974d4a3bc9ddfcb08ecd98 Mon Sep 17 00:00:00 2001 From: Daniel Date: Fri, 8 May 2020 10:56:16 +0200 Subject: [PATCH 1/3] Reset and recreate the updates tmp dir on startup --- updater/registry.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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 } From 74fc1dc888c9768d9bd42220e9398951f6fb4f8a Mon Sep 17 00:00:00 2001 From: Daniel Date: Fri, 8 May 2020 10:57:06 +0200 Subject: [PATCH 2/3] Do not remove tmp dir anymore, as it's used by others too --- updater/updating.go | 6 ------ 1 file changed, 6 deletions(-) diff --git a/updater/updating.go b/updater/updating.go index 7ead3ab..3788eac 100644 --- a/updater/updating.go +++ b/updater/updating.go @@ -121,11 +121,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 } From 441f9c45acd6f7440ae53d62a5662eb37d4b87c1 Mon Sep 17 00:00:00 2001 From: Daniel Date: Fri, 8 May 2020 10:57:14 +0200 Subject: [PATCH 3/3] Improve logging --- updater/storage.go | 4 +++- updater/updating.go | 6 ++++-- 2 files changed, 7 insertions(+), 3 deletions(-) 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 3788eac..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)