mirror of
https://github.com/safing/portmaster
synced 2025-04-23 04:19:10 +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"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/safing/portmaster/service/configure"
|
||||||
"github.com/safing/portmaster/service/updates"
|
"github.com/safing/portmaster/service/updates"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
scanConfig = updates.IndexScanConfig{
|
scanConfig = updates.IndexScanConfig{
|
||||||
Name: "Portmaster Binaries",
|
Name: configure.DefaultBinaryIndexName,
|
||||||
PrimaryArtifact: "linux_amd64/portmaster-core",
|
PrimaryArtifact: "linux_amd64/portmaster-core",
|
||||||
BaseURL: "https://updates.safing.io/",
|
BaseURL: "https://updates.safing.io/",
|
||||||
IgnoreFiles: []string{
|
IgnoreFiles: []string{
|
||||||
|
|
|
@ -115,7 +115,7 @@ func MakeUpdateConfigs(svcCfg *ServiceConfig) (binaryUpdateConfig, intelUpdateCo
|
||||||
switch runtime.GOOS {
|
switch runtime.GOOS {
|
||||||
case "windows":
|
case "windows":
|
||||||
binaryUpdateConfig = &updates.Config{
|
binaryUpdateConfig = &updates.Config{
|
||||||
Name: "binaries",
|
Name: configure.DefaultBinaryIndexName,
|
||||||
Directory: svcCfg.BinDir,
|
Directory: svcCfg.BinDir,
|
||||||
DownloadDirectory: filepath.Join(svcCfg.DataDir, "download_binaries"),
|
DownloadDirectory: filepath.Join(svcCfg.DataDir, "download_binaries"),
|
||||||
PurgeDirectory: filepath.Join(svcCfg.BinDir, "upgrade_obsolete_binaries"),
|
PurgeDirectory: filepath.Join(svcCfg.BinDir, "upgrade_obsolete_binaries"),
|
||||||
|
@ -130,7 +130,7 @@ func MakeUpdateConfigs(svcCfg *ServiceConfig) (binaryUpdateConfig, intelUpdateCo
|
||||||
Notify: true,
|
Notify: true,
|
||||||
}
|
}
|
||||||
intelUpdateConfig = &updates.Config{
|
intelUpdateConfig = &updates.Config{
|
||||||
Name: "intel",
|
Name: configure.DefaultIntelIndexName,
|
||||||
Directory: filepath.Join(svcCfg.DataDir, "intel"),
|
Directory: filepath.Join(svcCfg.DataDir, "intel"),
|
||||||
DownloadDirectory: filepath.Join(svcCfg.DataDir, "download_intel"),
|
DownloadDirectory: filepath.Join(svcCfg.DataDir, "download_intel"),
|
||||||
PurgeDirectory: filepath.Join(svcCfg.DataDir, "upgrade_obsolete_intel"),
|
PurgeDirectory: filepath.Join(svcCfg.DataDir, "upgrade_obsolete_intel"),
|
||||||
|
@ -146,7 +146,7 @@ func MakeUpdateConfigs(svcCfg *ServiceConfig) (binaryUpdateConfig, intelUpdateCo
|
||||||
|
|
||||||
case "linux":
|
case "linux":
|
||||||
binaryUpdateConfig = &updates.Config{
|
binaryUpdateConfig = &updates.Config{
|
||||||
Name: "binaries",
|
Name: configure.DefaultBinaryIndexName,
|
||||||
Directory: svcCfg.BinDir,
|
Directory: svcCfg.BinDir,
|
||||||
DownloadDirectory: filepath.Join(svcCfg.DataDir, "download_binaries"),
|
DownloadDirectory: filepath.Join(svcCfg.DataDir, "download_binaries"),
|
||||||
PurgeDirectory: filepath.Join(svcCfg.DataDir, "upgrade_obsolete_binaries"),
|
PurgeDirectory: filepath.Join(svcCfg.DataDir, "upgrade_obsolete_binaries"),
|
||||||
|
@ -161,7 +161,7 @@ func MakeUpdateConfigs(svcCfg *ServiceConfig) (binaryUpdateConfig, intelUpdateCo
|
||||||
Notify: true,
|
Notify: true,
|
||||||
}
|
}
|
||||||
intelUpdateConfig = &updates.Config{
|
intelUpdateConfig = &updates.Config{
|
||||||
Name: "intel",
|
Name: configure.DefaultIntelIndexName,
|
||||||
Directory: filepath.Join(svcCfg.DataDir, "intel"),
|
Directory: filepath.Join(svcCfg.DataDir, "intel"),
|
||||||
DownloadDirectory: filepath.Join(svcCfg.DataDir, "download_intel"),
|
DownloadDirectory: filepath.Join(svcCfg.DataDir, "download_intel"),
|
||||||
PurgeDirectory: filepath.Join(svcCfg.DataDir, "upgrade_obsolete_intel"),
|
PurgeDirectory: filepath.Join(svcCfg.DataDir, "upgrade_obsolete_intel"),
|
||||||
|
|
|
@ -5,6 +5,9 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
DefaultBinaryIndexName = "Portmaster Binaries"
|
||||||
|
DefaultIntelIndexName = "intel"
|
||||||
|
|
||||||
DefaultStableBinaryIndexURLs = []string{
|
DefaultStableBinaryIndexURLs = []string{
|
||||||
"https://updates.safing.io/stable.v3.json",
|
"https://updates.safing.io/stable.v3.json",
|
||||||
}
|
}
|
||||||
|
|
|
@ -118,6 +118,14 @@ type Index struct {
|
||||||
Artifacts []*Artifact `json:"Artifacts"`
|
Artifacts []*Artifact `json:"Artifacts"`
|
||||||
|
|
||||||
versionNum *semver.Version
|
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.
|
// 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:
|
case index.Name != newIndex.Name:
|
||||||
return errors.New("new index name does not match")
|
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):
|
case index.Published.After(newIndex.Published):
|
||||||
return errors.New("new index is older (time)")
|
return errors.New("new index is older (time)")
|
||||||
|
|
||||||
|
|
|
@ -234,10 +234,11 @@ func GenerateIndexFromDir(sourceDir string, cfg IndexScanConfig) (*Index, error)
|
||||||
|
|
||||||
// Create base index.
|
// Create base index.
|
||||||
index := &Index{
|
index := &Index{
|
||||||
Name: cfg.Name,
|
Name: cfg.Name,
|
||||||
Version: cfg.Version,
|
Version: cfg.Version,
|
||||||
Published: time.Now(),
|
Published: time.Now(),
|
||||||
versionNum: indexVersion,
|
versionNum: indexVersion,
|
||||||
|
isLocallyGenerated: true,
|
||||||
}
|
}
|
||||||
if index.Version == "" && cfg.PrimaryArtifact != "" {
|
if index.Version == "" && cfg.PrimaryArtifact != "" {
|
||||||
pv, ok := artifacts[cfg.PrimaryArtifact]
|
pv, ok := artifacts[cfg.PrimaryArtifact]
|
||||||
|
|
|
@ -18,6 +18,7 @@ import (
|
||||||
"github.com/safing/portmaster/base/log"
|
"github.com/safing/portmaster/base/log"
|
||||||
"github.com/safing/portmaster/base/notifications"
|
"github.com/safing/portmaster/base/notifications"
|
||||||
"github.com/safing/portmaster/base/utils"
|
"github.com/safing/portmaster/base/utils"
|
||||||
|
"github.com/safing/portmaster/service/configure"
|
||||||
"github.com/safing/portmaster/service/mgr"
|
"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)
|
module.corruptedInstallation = fmt.Errorf("invalid index: %w", err)
|
||||||
}
|
}
|
||||||
index, err = GenerateIndexFromDir(cfg.Directory, IndexScanConfig{
|
index, err = GenerateIndexFromDir(cfg.Directory, IndexScanConfig{
|
||||||
|
Name: configure.DefaultBinaryIndexName,
|
||||||
Version: info.VersionNumber(),
|
Version: info.VersionNumber(),
|
||||||
})
|
})
|
||||||
if err == nil && index.init(currentPlatform) == nil {
|
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()) {
|
if slices.Contains(u.cfg.Ignore, file.Name()) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
// ignore PurgeDirectory itself
|
||||||
|
if strings.EqualFold(u.cfg.PurgeDirectory, filepath.Join(u.cfg.Directory, file.Name())) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
// Otherwise, move file to purge dir.
|
// Otherwise, move file to purge dir.
|
||||||
src := filepath.Join(u.cfg.Directory, file.Name())
|
src := filepath.Join(u.cfg.Directory, file.Name())
|
||||||
|
|
Loading…
Add table
Reference in a new issue