Fix paths and identifiers

This commit is contained in:
Daniel 2019-07-30 13:07:33 +02:00
parent ae79877a3f
commit c6332dda7d
4 changed files with 14 additions and 8 deletions

View file

@ -83,7 +83,7 @@ func loadOrFetchFile(identifier string, fetch bool) (*File, error) {
} }
// check download dir // check download dir
err := utils.EnsureDirectory(downloadTmpPath, 0755) err := utils.EnsureDirectory(downloadTmpPath, 0700)
if err != nil { if err != nil {
return nil, fmt.Errorf("could not prepare tmp directory for download: %s", err) return nil, fmt.Errorf("could not prepare tmp directory for download: %s", err)
} }

View file

@ -4,6 +4,7 @@ import (
"errors" "errors"
"os" "os"
"path/filepath" "path/filepath"
"runtime"
"github.com/safing/portbase/database" "github.com/safing/portbase/database"
"github.com/safing/portbase/info" "github.com/safing/portbase/info"
@ -15,6 +16,7 @@ import (
var ( var (
updateStoragePath string updateStoragePath string
downloadTmpPath string downloadTmpPath string
isWindows = runtime.GOOS == "windows"
) )
// SetDatabaseRoot tells the updates module where the database is - and where to put its stuff. // SetDatabaseRoot tells the updates module where the database is - and where to put its stuff.
@ -66,7 +68,7 @@ func start() error {
err = UpdateIndexes() err = UpdateIndexes()
if err != nil { if err != nil {
return err log.Errorf("updates: failed to download update index: %s", err)
} }
} else { } else {
return err return err

View file

@ -12,21 +12,25 @@ const coreIdentifier = "core/portmaster-core"
var lastNotified time.Time var lastNotified time.Time
func updateNotifier() { func updateNotifier() {
time.Sleep(30 * time.Second) time.Sleep(5 * time.Minute)
for { for {
ident := coreIdentifier
if isWindows {
ident += ".exe"
}
_, version, _, ok := getLatestFilePath(coreIdentifier) file, err := GetLocalPlatformFile(ident)
if ok { if err == nil {
status.Lock() status.Lock()
liveVersion := status.Core.Version liveVersion := status.Core.Version
status.Unlock() status.Unlock()
if version != liveVersion { if file.Version() != liveVersion {
// create notification // create notification
(&notifications.Notification{ (&notifications.Notification{
ID: "updates-core-update-available", ID: "updates-core-update-available",
Message: fmt.Sprintf("There is an update available for the Portmaster core (v%s), please restart the Portmaster to apply the update.", version), Message: fmt.Sprintf("There is an update available for the Portmaster core (v%s), please restart the Portmaster to apply the update.", file.Version()),
Type: notifications.Info, Type: notifications.Info,
Expires: time.Now().Add(1 * time.Minute).Unix(), Expires: time.Now().Add(1 * time.Minute).Unix(),
}).Init().Save() }).Init().Save()

View file

@ -153,7 +153,7 @@ func DownloadUpdates() (err error) {
log.Tracef("updates: finished updating existing files") log.Tracef("updates: finished updating existing files")
// remove tmp folder after we are finished // remove tmp folder after we are finished
err = os.RemoveAll(updateStoragePath) err = os.RemoveAll(downloadTmpPath)
if err != nil { if err != nil {
log.Tracef("updates: failed to remove tmp dir %s after downloading updates: %s", updateStoragePath, err) log.Tracef("updates: failed to remove tmp dir %s after downloading updates: %s", updateStoragePath, err)
} }