diff --git a/cmd/gf/internal/utility/utils/utils_http_download.go b/cmd/gf/internal/utility/utils/utils_http_download.go index 2117b4afa06..a0654d0c641 100644 --- a/cmd/gf/internal/utility/utils/utils_http_download.go +++ b/cmd/gf/internal/utility/utils/utils_http_download.go @@ -69,16 +69,18 @@ func doPrintDownloadPercent(doneCh chan int64, localSaveFilePath string, total i stop = false lastPercentFmt string ) + file, err := os.Open(localSaveFilePath) + if err != nil { + mlog.Fatal(err) + } + defer file.Close() + for { select { case <-doneCh: stop = true default: - file, err := os.Open(localSaveFilePath) - if err != nil { - mlog.Fatal(err) - } fi, err := file.Stat() if err != nil { mlog.Fatal(err)