mirror of
https://github.com/safing/portmaster
synced 2025-04-14 07:59:11 +00:00
Merge pull request #1849 from safing/fix/updater-fix-2
Fix/updater fix 2
This commit is contained in:
commit
58167bd259
7 changed files with 37 additions and 9 deletions
cmds/updatemgr
service
|
@ -4,13 +4,14 @@ import (
|
|||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"github.com/safing/portmaster/service/configure"
|
||||
"github.com/safing/portmaster/service/updates"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var (
|
||||
scanConfig = updates.IndexScanConfig{
|
||||
Name: "Portmaster Binaries",
|
||||
Name: configure.DefaultBinaryIndexName,
|
||||
PrimaryArtifact: "linux_amd64/portmaster-core",
|
||||
BaseURL: "https://updates.safing.io/",
|
||||
IgnoreFiles: []string{
|
||||
|
|
|
@ -115,7 +115,7 @@ func MakeUpdateConfigs(svcCfg *ServiceConfig) (binaryUpdateConfig, intelUpdateCo
|
|||
switch runtime.GOOS {
|
||||
case "windows":
|
||||
binaryUpdateConfig = &updates.Config{
|
||||
Name: "binaries",
|
||||
Name: configure.DefaultBinaryIndexName,
|
||||
Directory: svcCfg.BinDir,
|
||||
DownloadDirectory: filepath.Join(svcCfg.DataDir, "download_binaries"),
|
||||
PurgeDirectory: filepath.Join(svcCfg.BinDir, "upgrade_obsolete_binaries"),
|
||||
|
@ -130,7 +130,7 @@ func MakeUpdateConfigs(svcCfg *ServiceConfig) (binaryUpdateConfig, intelUpdateCo
|
|||
Notify: true,
|
||||
}
|
||||
intelUpdateConfig = &updates.Config{
|
||||
Name: "intel",
|
||||
Name: configure.DefaultIntelIndexName,
|
||||
Directory: filepath.Join(svcCfg.DataDir, "intel"),
|
||||
DownloadDirectory: filepath.Join(svcCfg.DataDir, "download_intel"),
|
||||
PurgeDirectory: filepath.Join(svcCfg.DataDir, "upgrade_obsolete_intel"),
|
||||
|
@ -146,7 +146,7 @@ func MakeUpdateConfigs(svcCfg *ServiceConfig) (binaryUpdateConfig, intelUpdateCo
|
|||
|
||||
case "linux":
|
||||
binaryUpdateConfig = &updates.Config{
|
||||
Name: "binaries",
|
||||
Name: configure.DefaultBinaryIndexName,
|
||||
Directory: svcCfg.BinDir,
|
||||
DownloadDirectory: filepath.Join(svcCfg.DataDir, "download_binaries"),
|
||||
PurgeDirectory: filepath.Join(svcCfg.DataDir, "upgrade_obsolete_binaries"),
|
||||
|
@ -161,7 +161,7 @@ func MakeUpdateConfigs(svcCfg *ServiceConfig) (binaryUpdateConfig, intelUpdateCo
|
|||
Notify: true,
|
||||
}
|
||||
intelUpdateConfig = &updates.Config{
|
||||
Name: "intel",
|
||||
Name: configure.DefaultIntelIndexName,
|
||||
Directory: filepath.Join(svcCfg.DataDir, "intel"),
|
||||
DownloadDirectory: filepath.Join(svcCfg.DataDir, "download_intel"),
|
||||
PurgeDirectory: filepath.Join(svcCfg.DataDir, "upgrade_obsolete_intel"),
|
||||
|
|
|
@ -5,6 +5,9 @@ import (
|
|||
)
|
||||
|
||||
var (
|
||||
DefaultBinaryIndexName = "Portmaster Binaries"
|
||||
DefaultIntelIndexName = "intel"
|
||||
|
||||
DefaultStableBinaryIndexURLs = []string{
|
||||
"https://updates.safing.io/stable.v3.json",
|
||||
}
|
||||
|
|
|
@ -118,6 +118,14 @@ type Index struct {
|
|||
Artifacts []*Artifact `json:"Artifacts"`
|
||||
|
||||
versionNum *semver.Version
|
||||
|
||||
// isLocallyGenerated indicates whether the index was generated from a local directory.
|
||||
//
|
||||
// When true:
|
||||
// - The `Published` field represents the generation time, not a formal release date.
|
||||
// This timestamp should be ignored when checking for online updates.
|
||||
// - Downgrades from this locally generated version to an online index should be prevented.
|
||||
isLocallyGenerated bool
|
||||
}
|
||||
|
||||
// LoadIndex loads and parses an index from the given filename.
|
||||
|
@ -235,6 +243,15 @@ func (index *Index) ShouldUpgradeTo(newIndex *Index) error {
|
|||
case index.Name != newIndex.Name:
|
||||
return errors.New("new index name does not match")
|
||||
|
||||
case index.isLocallyGenerated:
|
||||
if newIndex.versionNum.GreaterThan(index.versionNum) {
|
||||
// Upgrade! (from a locally generated index to an online index)
|
||||
return nil
|
||||
} else {
|
||||
// "Do nothing".
|
||||
return ErrSameIndex
|
||||
}
|
||||
|
||||
case index.Published.After(newIndex.Published):
|
||||
return errors.New("new index is older (time)")
|
||||
|
||||
|
|
|
@ -234,10 +234,11 @@ func GenerateIndexFromDir(sourceDir string, cfg IndexScanConfig) (*Index, error)
|
|||
|
||||
// Create base index.
|
||||
index := &Index{
|
||||
Name: cfg.Name,
|
||||
Version: cfg.Version,
|
||||
Published: time.Now(),
|
||||
versionNum: indexVersion,
|
||||
Name: cfg.Name,
|
||||
Version: cfg.Version,
|
||||
Published: time.Now(),
|
||||
versionNum: indexVersion,
|
||||
isLocallyGenerated: true,
|
||||
}
|
||||
if index.Version == "" && cfg.PrimaryArtifact != "" {
|
||||
pv, ok := artifacts[cfg.PrimaryArtifact]
|
||||
|
|
|
@ -18,6 +18,7 @@ import (
|
|||
"github.com/safing/portmaster/base/log"
|
||||
"github.com/safing/portmaster/base/notifications"
|
||||
"github.com/safing/portmaster/base/utils"
|
||||
"github.com/safing/portmaster/service/configure"
|
||||
"github.com/safing/portmaster/service/mgr"
|
||||
)
|
||||
|
||||
|
@ -201,6 +202,7 @@ func New(instance instance, name string, cfg Config) (*Updater, error) {
|
|||
module.corruptedInstallation = fmt.Errorf("invalid index: %w", err)
|
||||
}
|
||||
index, err = GenerateIndexFromDir(cfg.Directory, IndexScanConfig{
|
||||
Name: configure.DefaultBinaryIndexName,
|
||||
Version: info.VersionNumber(),
|
||||
})
|
||||
if err == nil && index.init(currentPlatform) == nil {
|
||||
|
|
|
@ -73,6 +73,10 @@ func (u *Updater) upgradeMoveFiles(downloader *Downloader) error {
|
|||
if slices.Contains(u.cfg.Ignore, file.Name()) {
|
||||
continue
|
||||
}
|
||||
// ignore PurgeDirectory itself
|
||||
if strings.EqualFold(u.cfg.PurgeDirectory, filepath.Join(u.cfg.Directory, file.Name())) {
|
||||
continue
|
||||
}
|
||||
|
||||
// Otherwise, move file to purge dir.
|
||||
src := filepath.Join(u.cfg.Directory, file.Name())
|
||||
|
|
Loading…
Add table
Reference in a new issue