Skip to content

Commit

Permalink
Merge pull request #80 from safing/fix/pmctl-download
Browse files Browse the repository at this point in the history
 Fix downloading of assets in pmctl
  • Loading branch information
dhaavi authored Jun 20, 2020
2 parents b3fb256 + 0548175 commit dc35964
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
19 changes: 7 additions & 12 deletions pmctl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ var (
},
Beta: false,
DevMode: false,
Online: false,
Online: true, // is disabled later based on command
}

rootCmd = &cobra.Command{
Expand Down Expand Up @@ -182,17 +182,12 @@ func cmdSetup(cmd *cobra.Command, args []string) (err error) {
Beta: false,
})

registry.AddIndex(updater.Index{
Path: "beta.json",
Stable: false,
Beta: true,
})

registry.AddIndex(updater.Index{
Path: "all/intel/intel.json",
Stable: true,
Beta: false,
})
// TODO: enable loading beta versions
// registry.AddIndex(updater.Index{
// Path: "beta.json",
// Stable: false,
// Beta: true,
// })

updateRegistryIndex()
}
Expand Down
14 changes: 10 additions & 4 deletions pmctl/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,10 @@ func handleRun(cmd *cobra.Command, opts *Options) (err error) {
return
}

func run(cmd *cobra.Command, opts *Options) (err error) {
func run(cmd *cobra.Command, opts *Options) (err error) { //nolint:gocognit

// set download option
if opts.AllowDownload {
registry.Online = true
}
registry.Online = opts.AllowDownload

// parse identifier
opts.ShortIdentifier = path.Dir(opts.Identifier)
Expand Down Expand Up @@ -187,8 +185,16 @@ func run(cmd *cobra.Command, opts *Options) (err error) {
log.Println("error seems to be permanent, giving up...")
return err
}
// resilience
time.Sleep(time.Duration(tries) * 2 * time.Second)
if tries >= 2 {
// try updating
updateRegistryIndex()
}
log.Println("trying again...")
case tryAgain && err == nil:
// reset error count
tries = 0
// upgrade
log.Println("restarting by request...")
// update index
Expand Down

0 comments on commit dc35964

Please sign in to comment.