mirror of
https://github.com/safing/portmaster
synced 2025-09-01 18:19:12 +00:00
Upgrade pmctl to only do a self upgrade when the update is already available
This commit is contained in:
parent
a316542f82
commit
7043f05144
3 changed files with 30 additions and 5 deletions
|
@ -13,7 +13,7 @@ import (
|
|||
|
||||
func checkForUpgrade() (update *updates.File) {
|
||||
info := info.GetInfo()
|
||||
file, err := getFile("pmctl/pmctl")
|
||||
file, err := updates.GetLocalPlatformFile("pmctl/pmctl")
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ import (
|
|||
|
||||
var (
|
||||
ErrNotFound = errors.New("the requested file could not be found")
|
||||
ErrNotAvailableLocally = errors.New("the requested file is not available locally")
|
||||
)
|
||||
|
||||
// GetPlatformFile returns the latest platform specific file identified by the given identifier.
|
||||
|
@ -21,13 +22,28 @@ func GetPlatformFile(identifier string) (*File, error) {
|
|||
// From https://golang.org/pkg/runtime/#GOARCH
|
||||
// GOOS is the running program's operating system target: one of darwin, freebsd, linux, and so on.
|
||||
// GOARCH is the running program's architecture target: one of 386, amd64, arm, s390x, and so on.
|
||||
return loadOrFetchFile(identifier)
|
||||
return loadOrFetchFile(identifier, true)
|
||||
}
|
||||
|
||||
// GetLocalPlatformFile returns the latest platform specific file identified by the given identifier, that is available locally.
|
||||
func GetLocalPlatformFile(identifier string) (*File, error) {
|
||||
identifier = path.Join(fmt.Sprintf("%s_%s", runtime.GOOS, runtime.GOARCH), identifier)
|
||||
// From https://golang.org/pkg/runtime/#GOARCH
|
||||
// GOOS is the running program's operating system target: one of darwin, freebsd, linux, and so on.
|
||||
// GOARCH is the running program's architecture target: one of 386, amd64, arm, s390x, and so on.
|
||||
return loadOrFetchFile(identifier, false)
|
||||
}
|
||||
|
||||
// GetFile returns the latest generic file identified by the given identifier.
|
||||
func GetFile(identifier string) (*File, error) {
|
||||
identifier = path.Join("all", identifier)
|
||||
return loadOrFetchFile(identifier)
|
||||
return loadOrFetchFile(identifier, true)
|
||||
}
|
||||
|
||||
// GetLocalFile returns the latest generic file identified by the given identifier, that is available locally.
|
||||
func GetLocalFile(identifier string) (*File, error) {
|
||||
identifier = path.Join("all", identifier)
|
||||
return loadOrFetchFile(identifier, false)
|
||||
}
|
||||
|
||||
func getLatestFilePath(identifier string) (versionedFilePath, version string, stable bool, ok bool) {
|
||||
|
@ -49,7 +65,7 @@ func getLatestFilePath(identifier string) (versionedFilePath, version string, st
|
|||
return GetVersionedPath(identifier, version), version, false, true
|
||||
}
|
||||
|
||||
func loadOrFetchFile(identifier string) (*File, error) {
|
||||
func loadOrFetchFile(identifier string, fetch bool) (*File, error) {
|
||||
versionedFilePath, version, stable, ok := getLatestFilePath(identifier)
|
||||
if !ok {
|
||||
// TODO: if in development mode, search updates dir for sideloaded apps
|
||||
|
@ -70,6 +86,10 @@ func loadOrFetchFile(identifier string) (*File, error) {
|
|||
return nil, fmt.Errorf("could not prepare tmp directory for download: %s", err)
|
||||
}
|
||||
|
||||
if (!fetch) {
|
||||
return nil, ErrNotAvailableLocally
|
||||
}
|
||||
|
||||
// download file
|
||||
log.Tracef("updates: starting download of %s", versionedFilePath)
|
||||
for tries := 0; tries < 5; tries++ {
|
||||
|
|
|
@ -23,9 +23,14 @@ func updater() {
|
|||
|
||||
func CheckForUpdates() error {
|
||||
|
||||
// be sure that pmctl is part of the "used" updates
|
||||
_, err := GetLocalFile("pmctl/pmctl")
|
||||
if err != nil {
|
||||
log.Errorf("updates: failed to mark pmctl/pmctl as used to ensure updates: %s", err)
|
||||
}
|
||||
|
||||
// download new index
|
||||
var data []byte
|
||||
var err error
|
||||
for tries := 0; tries < 3; tries++ {
|
||||
data, err = fetchData("stable.json", tries)
|
||||
if err == nil {
|
||||
|
|
Loading…
Add table
Reference in a new issue