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

Method WriteClose

internal/utils/bfs/meta_file.go:165–210  ·  view source on GitHub ↗
(hash string, headerSize int64, bodySize int64)

Source from the content-addressed store, hash-verified

163}
164
165func (this *MetaFile) WriteClose(hash string, headerSize int64, bodySize int64) error {
166 // TODO 考虑单个hash多次重复调用的情况
167
168 this.mu.Lock()
169 lazyHeader, ok := this.headerMap[hash]
170 if !ok {
171 this.mu.Unlock()
172 return nil
173 }
174
175 header, err := lazyHeader.FileHeaderUnsafe()
176 if err != nil {
177 return err
178 }
179
180 this.mu.Unlock()
181
182 // TODO 检查bodySize和expectedBodySize是否一致,如果不一致则从headerMap中删除
183
184 header.ModifiedAt = fasttime.Now().Unix()
185 header.HeaderSize = headerSize
186 header.BodySize = bodySize
187 header.Compact()
188
189 blockBytes, err := header.Encode(hash)
190 if err != nil {
191 return err
192 }
193
194 this.mu.Lock()
195 defer this.mu.Unlock()
196
197 AckReadThread()
198 _, err = this.fp.Seek(0, io.SeekEnd)
199 ReleaseReadThread()
200 if err != nil {
201 return err
202 }
203
204 AckWriteThread()
205 _, err = this.fp.Write(blockBytes)
206 ReleaseWriteThread()
207
208 this.isModified = true
209 return err
210}
211
212func (this *MetaFile) RemoveFile(hash string) error {
213 this.mu.Lock()

Callers 3

CloseMethod · 0.80
TestMetaFile_WriteMetaFunction · 0.80
TestMetaFile_WriteFunction · 0.80

Calls 13

NowFunction · 0.92
AckReadThreadFunction · 0.85
ReleaseReadThreadFunction · 0.85
AckWriteThreadFunction · 0.85
ReleaseWriteThreadFunction · 0.85
UnixMethod · 0.80
SeekMethod · 0.80
EncodeMethod · 0.65
WriteMethod · 0.65
LockMethod · 0.45
UnlockMethod · 0.45
FileHeaderUnsafeMethod · 0.45

Tested by 2

TestMetaFile_WriteMetaFunction · 0.64
TestMetaFile_WriteFunction · 0.64