From d561c86c68b229e948b2aca5a7c462d3aea45ccf Mon Sep 17 00:00:00 2001 From: zhengkunwang <31820853+zhengkunwang223@users.noreply.github.com> Date: Mon, 12 Aug 2024 17:58:52 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E7=BD=91=E7=AB=99?= =?UTF-8?q?=E6=97=A5=E5=BF=97=E5=9C=A8=E6=AF=8F=E8=A1=8C=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E9=87=8F=E5=A4=A7=E6=83=85=E5=86=B5=E4=B8=8B=E7=9A=84=E8=AF=BB?= =?UTF-8?q?=E5=8F=96=20(#6103)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Refs https://github.com/1Panel-dev/1Panel/issues/6102 --- backend/utils/files/utils.go | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/backend/utils/files/utils.go b/backend/utils/files/utils.go index 76ba78156..5347ce964 100644 --- a/backend/utils/files/utils.go +++ b/backend/utils/files/utils.go @@ -72,16 +72,21 @@ func countLines(path string) (int, error) { return 0, err } defer file.Close() - - scanner := bufio.NewScanner(file) - lineCount := 0 - for scanner.Scan() { - lineCount++ - } - if err := scanner.Err(); err != nil { - return 0, err + reader := bufio.NewReader(file) + count := 0 + for { + _, err := reader.ReadString('\n') + if err != nil { + if err == io.EOF { + if count > 0 { + count++ + } + return count, nil + } + return count, err + } + count++ } - return lineCount, nil } func ReadFileByLine(filename string, page, pageSize int, latest bool) (lines []string, isEndOfFile bool, total int, err error) {