From 5a91dbe34ed658ac981b792b8a905200459ef422 Mon Sep 17 00:00:00 2001 From: GoEdgeLab Date: Thu, 17 Feb 2022 17:38:56 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=96=87=E4=BB=B6=E5=8F=A5?= =?UTF-8?q?=E6=9F=84=E7=BC=93=E5=AD=98=E5=8F=AF=E8=83=BD=E9=87=8D=E5=A4=8D?= =?UTF-8?q?=E5=8A=A0=E5=85=A5=E7=9A=84Bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/caches/reader_file.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/internal/caches/reader_file.go b/internal/caches/reader_file.go index aabc100..781b64f 100644 --- a/internal/caches/reader_file.go +++ b/internal/caches/reader_file.go @@ -23,6 +23,8 @@ type FileReader struct { headerSize int bodySize int64 bodyOffset int64 + + isClosed bool } func NewFileReader(fp *os.File) *FileReader { @@ -326,6 +328,11 @@ func (this *FileReader) ReadBodyRange(buf []byte, start int64, end int64, callba func (this *FileReader) Close() error { if this.openFileCache != nil { + if this.isClosed { + return nil + } + this.isClosed = true + if this.openFile != nil { this.openFileCache.Put(this.fp.Name(), this.openFile) } else { @@ -347,5 +354,6 @@ func (this *FileReader) readToBuff(fp *os.File, buf []byte) (ok bool, err error) func (this *FileReader) discard() error { _ = this.fp.Close() + this.isClosed = true return os.Remove(this.fp.Name()) }