diff --git a/service/updates/index.go b/service/updates/index.go index d98d92d7..13285f9d 100644 --- a/service/updates/index.go +++ b/service/updates/index.go @@ -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)") diff --git a/service/updates/index_scan.go b/service/updates/index_scan.go index 1dc1a7f6..3ac52f5f 100644 --- a/service/updates/index_scan.go +++ b/service/updates/index_scan.go @@ -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]