Add support for staging and purging
This commit is contained in:
@@ -35,6 +35,8 @@ type versions struct {
|
||||
|
||||
Core *info.Info
|
||||
Resources map[string]*updater.Resource
|
||||
Beta bool
|
||||
Staging bool
|
||||
|
||||
internalSave bool
|
||||
}
|
||||
@@ -43,6 +45,8 @@ func initVersionExport() (err error) {
|
||||
// init export struct
|
||||
versionExport = &versions{
|
||||
internalSave: true,
|
||||
Beta: registry.Beta,
|
||||
Staging: staging,
|
||||
}
|
||||
versionExport.SetKey(versionsDBKey)
|
||||
|
||||
|
||||
@@ -51,6 +51,7 @@ var (
|
||||
module *modules.Module
|
||||
registry *updater.ResourceRegistry
|
||||
userAgentFromFlag string
|
||||
staging bool
|
||||
|
||||
updateTask *modules.Task
|
||||
updateASAP bool
|
||||
@@ -78,6 +79,7 @@ func init() {
|
||||
module.RegisterEvent(ResourceUpdateEvent)
|
||||
|
||||
flag.StringVar(&userAgentFromFlag, "update-agent", "", "Sets the user agent for requests to the update server")
|
||||
flag.BoolVar(&staging, "staging", false, "Use staging update channel (for testing only)")
|
||||
|
||||
// initialize mandatory updates
|
||||
if onWindows {
|
||||
@@ -182,6 +184,18 @@ func start() error {
|
||||
Beta: true,
|
||||
})
|
||||
|
||||
if stagingActive() {
|
||||
// Set flag no matter how staging was activated.
|
||||
staging = true
|
||||
|
||||
log.Warning("updates: staging environment is active")
|
||||
|
||||
registry.AddIndex(updater.Index{
|
||||
Path: "staging.json",
|
||||
Stable: true,
|
||||
Beta: true,
|
||||
})
|
||||
}
|
||||
|
||||
err = registry.LoadIndexes(module.Ctx)
|
||||
if err != nil {
|
||||
@@ -308,3 +322,14 @@ func stop() error {
|
||||
func platform(identifier string) string {
|
||||
return fmt.Sprintf("%s_%s/%s", runtime.GOOS, runtime.GOARCH, identifier)
|
||||
}
|
||||
|
||||
func stagingActive() bool {
|
||||
// Check flag and env variable.
|
||||
if staging || os.Getenv("PORTMASTER_STAGING") == "enabled" {
|
||||
return true
|
||||
}
|
||||
|
||||
// Check if staging index is present and acessible.
|
||||
_, err := os.Stat(filepath.Join(registry.StorageDir().Path, "staging.json"))
|
||||
return err == nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user