mirror of
https://github.com/safing/portmaster
synced 2025-04-23 12:29:10 +00:00
[updates] fix: update from locally generated index (timestamps and downgrade)
This commit is contained in:
parent
776b4860ef
commit
2a85a4bfd0
2 changed files with 22 additions and 4 deletions
service/updates
|
@ -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]
|
||||
|
|
Loading…
Add table
Reference in a new issue