Skip to content

Commit

Permalink
Remove a level of nesting
Browse files Browse the repository at this point in the history
This code should only bother running if `err != nil`, makes it easier to
understand and removes a level of nesting.
  • Loading branch information
rustydb committed Sep 26, 2024
1 parent cbd1adb commit 0431358
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions cmd/boot-script-service/default_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -628,22 +628,23 @@ func buildBootScript(bd BootData, sp scriptParams, chain, role, subRole, descr s
}
u := bd.Kernel.Path
u, err = checkURL(u)
if err == nil {
script += "kernel --name kernel " + u + " " + strings.Trim(params, " ")
script += " || goto boot_retry\n"
if bd.Initrd.Path != "" {
u, err = checkURL(bd.Initrd.Path)
if err == nil {
script += "initrd --name initrd " + u + " || goto boot_retry\n"
script += "imgstat || echo Could not show image information."
}
}
script += "boot || goto boot_retry\n:boot_retry\n"
// We could vary the length of the sleep based on retry count or some
// other criteria.
// For now, just sleep a bit
script += fmt.Sprintf("sleep %d\n", retryDelay) + chain + "\n"
}
if err != nil {
return script, err
}
script += "kernel --name kernel " + u + " " + strings.Trim(params, " ")
script += " || goto boot_retry\n"
if bd.Initrd.Path != "" {
u, err = checkURL(bd.Initrd.Path)
if err == nil {
script += "initrd --name initrd " + u + " || goto boot_retry\n"
script += "imgstat || echo Could not show image information."
}
}
script += "boot || goto boot_retry\n:boot_retry\n"
// We could vary the length of the sleep based on retry count or some
// other criteria.
// For now, just sleep a bit
script += fmt.Sprintf("sleep %d\n", retryDelay) + chain + "\n"
return script, err
}

Expand Down

0 comments on commit 0431358

Please sign in to comment.