MCPcopy Create free account
hub / github.com/GoEdgeLab/EdgeNode / Close

Method Close

internal/caches/writer_file.go:131–169  ·  view source on GitHub ↗

Close 关闭

()

Source from the content-addressed store, hash-verified

129
130// Close 关闭
131func (this *FileWriter) Close() error {
132 defer this.once.Do(func() {
133 this.endFunc()
134 })
135
136 var path = this.rawWriter.Name()
137
138 // check content length
139 if this.metaBodySize > 0 && this.bodySize != this.metaBodySize {
140 _ = this.rawWriter.Close()
141 _ = fsutils.Remove(path)
142 return ErrUnexpectedContentLength
143 }
144
145 err := this.WriteHeaderLength(types.Int(this.headerSize))
146 if err != nil {
147 _ = this.rawWriter.Close()
148 _ = fsutils.Remove(path)
149 return err
150 }
151 err = this.WriteBodyLength(this.bodySize)
152 if err != nil {
153 _ = this.rawWriter.Close()
154 _ = fsutils.Remove(path)
155 return err
156 }
157
158 err = this.rawWriter.Close()
159 if err != nil {
160 _ = fsutils.Remove(path)
161 } else if strings.HasSuffix(path, FileTmpSuffix) {
162 err = fsutils.Rename(path, strings.Replace(path, FileTmpSuffix, "", 1))
163 if err != nil {
164 _ = fsutils.Remove(path)
165 }
166 }
167
168 return err
169}
170
171// Discard 丢弃
172func (this *FileWriter) Discard() error {

Callers

nothing calls this directly

Calls 6

WriteHeaderLengthMethod · 0.95
WriteBodyLengthMethod · 0.95
DoMethod · 0.80
NameMethod · 0.65
CloseMethod · 0.65
RemoveMethod · 0.65

Tested by

no test coverage detected