Skip to content

Commit

Permalink
fix: component download segv (#1476)
Browse files Browse the repository at this point in the history
  • Loading branch information
jon-stewart authored Dec 7, 2023
1 parent f9c47d0 commit 2a11eec
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions cli/cmd/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -1144,11 +1144,14 @@ func downloadProgress(complete chan int8, path string, sizeB int64) {
defer file.Close()

var (
previous float64 = 0
stop bool = false
previous float64 = 0
stop bool = false
spinnerSuffix string = ""
)

spinnerSuffix := cli.spinner.Suffix
if !cli.nonInteractive {
spinnerSuffix = cli.spinner.Suffix
}

for !stop {
select {
Expand All @@ -1170,15 +1173,23 @@ func downloadProgress(complete chan int8, path string, sizeB int64) {
mb := float64(size) / (1 << 20)

if mb > previous {
cli.spinner.Suffix = fmt.Sprintf("%s Downloaded: %.0fmb", spinnerSuffix, mb)
if !cli.nonInteractive {
cli.spinner.Suffix = fmt.Sprintf("%s Downloaded: %.0fmb", spinnerSuffix, mb)
} else {
cli.OutputHuman("..Downloaded: %.0fmb\n", mb)
}

previous = mb
}
} else {
percent := float64(size) / float64(sizeB) * 100

if percent > previous {
cli.spinner.Suffix = fmt.Sprintf("%s Downloaded: %.0f%s", spinnerSuffix, percent, "%")
if !cli.nonInteractive {
cli.spinner.Suffix = fmt.Sprintf("%s Downloaded: %.0f%s", spinnerSuffix, percent, "%")
} else {
cli.OutputHuman("..Downloaded: %.0f%s\n", percent, "%")
}

previous = percent
}
Expand Down

0 comments on commit 2a11eec

Please sign in to comment.