MCPcopy Index your code
hub / github.com/GoEdgeLab/EdgeNode / load

Method load

internal/utils/bfs/meta_file.go:51–99  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

49}
50
51func (this *MetaFile) load() error {
52 AckReadThread()
53 _, err := this.fp.Seek(0, io.SeekStart)
54 ReleaseReadThread()
55 if err != nil {
56 return err
57 }
58
59 // TODO 检查文件是否完整
60
61 var buf = make([]byte, 4<<10)
62 var blockBytes []byte
63 for {
64 AckReadThread()
65 n, readErr := this.fp.Read(buf)
66 ReleaseReadThread()
67 if n > 0 {
68 blockBytes = append(blockBytes, buf[:n]...)
69 for len(blockBytes) > 4 {
70 var l = int(binary.BigEndian.Uint32(blockBytes[:4])) + 4 /* Len **/
71 if len(blockBytes) < l {
72 break
73 }
74
75 action, hash, data, decodeErr := DecodeMetaBlock(blockBytes[:l])
76 if decodeErr != nil {
77 return decodeErr
78 }
79
80 switch action {
81 case MetaActionNew:
82 this.headerMap[hash] = NewLazyFileHeaderFromData(data)
83 case MetaActionRemove:
84 delete(this.headerMap, hash)
85 }
86
87 blockBytes = blockBytes[l:]
88 }
89 }
90 if readErr != nil {
91 if readErr == io.EOF {
92 break
93 }
94 return readErr
95 }
96 }
97
98 return nil
99}
100
101func (this *MetaFile) WriteMeta(hash string, status int, expiresAt int64, expectedFileSize int64) error {
102

Callers 2

OpenMetaFileFunction · 0.80
sqlparse2c.pyFile · 0.80

Calls 6

AckReadThreadFunction · 0.85
ReleaseReadThreadFunction · 0.85
DecodeMetaBlockFunction · 0.85
SeekMethod · 0.80
ReadMethod · 0.65

Tested by

no test coverage detected