From be80256aab487487912e8d0a895f97c0c2be2ec2 Mon Sep 17 00:00:00 2001 From: GoEdgeLab Date: Wed, 2 Aug 2023 08:51:31 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=B9=E7=BC=93=E5=AD=98=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E5=85=B3=E9=97=AD=E4=BA=8B=E4=BB=B6=E4=B9=9F=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E5=86=99=E5=85=A5=E7=BB=9F=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/caches/writer_file.go | 8 ++++++++ internal/caches/writer_partial_file.go | 10 ++++++++++ 2 files changed, 18 insertions(+) diff --git a/internal/caches/writer_file.go b/internal/caches/writer_file.go index 4949eff..49c957c 100644 --- a/internal/caches/writer_file.go +++ b/internal/caches/writer_file.go @@ -138,18 +138,24 @@ func (this *FileWriter) Close() error { err := this.WriteHeaderLength(types.Int(this.headerSize)) if err != nil { + fsutils.WriteBegin() _ = this.rawWriter.Close() + fsutils.WriteEnd() _ = os.Remove(path) return err } err = this.WriteBodyLength(this.bodySize) if err != nil { + fsutils.WriteBegin() _ = this.rawWriter.Close() + fsutils.WriteEnd() _ = os.Remove(path) return err } + fsutils.WriteBegin() err = this.rawWriter.Close() + fsutils.WriteEnd() if err != nil { _ = os.Remove(path) } else if strings.HasSuffix(path, FileTmpSuffix) { @@ -168,7 +174,9 @@ func (this *FileWriter) Discard() error { this.endFunc() }) + fsutils.WriteBegin() _ = this.rawWriter.Close() + fsutils.WriteEnd() err := os.Remove(this.rawWriter.Name()) return err diff --git a/internal/caches/writer_partial_file.go b/internal/caches/writer_partial_file.go index cf4b3fd..0b07394 100644 --- a/internal/caches/writer_partial_file.go +++ b/internal/caches/writer_partial_file.go @@ -181,7 +181,9 @@ func (this *PartialFileWriter) Close() error { this.ranges.BodySize = this.bodySize err := this.ranges.WriteToFile(this.rangePath) if err != nil { + fsutils.WriteBegin() _ = this.rawWriter.Close() + fsutils.WriteEnd() this.remove() return err } @@ -190,19 +192,25 @@ func (this *PartialFileWriter) Close() error { if this.isNew { err = this.WriteHeaderLength(types.Int(this.headerSize)) if err != nil { + fsutils.WriteBegin() _ = this.rawWriter.Close() + fsutils.WriteEnd() this.remove() return err } err = this.WriteBodyLength(this.bodySize) if err != nil { + fsutils.WriteBegin() _ = this.rawWriter.Close() + fsutils.WriteEnd() this.remove() return err } } + fsutils.WriteBegin() err = this.rawWriter.Close() + fsutils.WriteEnd() if err != nil { this.remove() } @@ -216,7 +224,9 @@ func (this *PartialFileWriter) Discard() error { this.endFunc() }) + fsutils.WriteBegin() _ = this.rawWriter.Close() + fsutils.WriteEnd() _ = os.Remove(this.rangePath)