mirror of
https://github.com/safing/portbase
synced 2025-09-01 18:19:57 +00:00
Merge pull request #42 from safing/feature/updater-improvements
improvement updater
This commit is contained in:
commit
43a91f07ed
3 changed files with 19 additions and 9 deletions
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue