From ebe567dab2e8f3fa2ab6a5fa44f1e42cc37d09b1 Mon Sep 17 00:00:00 2001 From: guangwu Date: Tue, 16 Apr 2024 19:49:09 +0800 Subject: [PATCH] fix: missing file closding when printing downloading percent of gf cli file for command `gf up` (#3483) --- cmd/gf/internal/utility/utils/utils_http_download.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) 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)