Skip to content

Commit

Permalink
fix(compute/build): avoid empty config value
Browse files Browse the repository at this point in the history
  • Loading branch information
Integralist committed Oct 31, 2023
1 parent 16095fe commit 64c2230
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions pkg/commands/compute/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ func GetWasmTools(spinner text.Spinner, out io.Writer, wasmtoolsVersioner github
}

if installedVersion != "" {
err = updateWasmtools(binPath, spinner, out, wasmtoolsVersioner, g.Verbose(), installedVersion, g.Config.WasmTools, g.Config, g.ConfigPath)
err = updateWasmtools(binPath, spinner, out, wasmtoolsVersioner, g.Verbose(), installedVersion, g.Config, g.ConfigPath)
if err != nil {
g.ErrLog.Add(err)
return binPath, err
Expand Down Expand Up @@ -648,12 +648,17 @@ func updateWasmtools(
wasmtoolsVersioner github.AssetVersioner,
verbose bool,
installedVersion string,
wasmtoolsConfig config.Versioner,
cfg config.File,
cfgPath string,
) error {
stale := wasmtoolsConfig.LastChecked != "" && wasmtoolsConfig.LatestVersion != "" && check.Stale(wasmtoolsConfig.LastChecked, wasmtoolsConfig.TTL)
if !stale {
// NOTE: We shouldn't see LastChecked with no value if wasm-tools installed.
if cfg.WasmTools.LastChecked == "" {
cfg.WasmTools.LastChecked = time.Now().Format(time.RFC3339)
if err := cfg.Write(cfgPath); err != nil {
return err
}
}
if !check.Stale(cfg.WasmTools.LastChecked, cfg.WasmTools.TTL) {
if verbose {
text.Info(out, "\nwasm-tools is installed but the CLI config (`fastly config`) shows the TTL, checking for a newer version, hasn't expired.\n\n")
}
Expand All @@ -676,12 +681,8 @@ func updateWasmtools(
return err
}

wasmtoolsConfig.LatestVersion = latestVersion
wasmtoolsConfig.LastChecked = time.Now().Format(time.RFC3339)

// Before attempting to write the config data back to disk we need to
// ensure we reassign the modified struct which is a copy (not reference).
cfg.WasmTools = wasmtoolsConfig
cfg.WasmTools.LatestVersion = latestVersion
cfg.WasmTools.LastChecked = time.Now().Format(time.RFC3339)

err = cfg.Write(cfgPath)
if err != nil {
Expand Down

0 comments on commit 64c2230

Please sign in to comment.