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

Function NewBlocksFileWithRawFile

internal/utils/bfs/blocks_file.go:45–80  ·  view source on GitHub ↗
(fp *os.File, options *BlockFileOptions)

Source from the content-addressed store, hash-verified

43}
44
45func NewBlocksFileWithRawFile(fp *os.File, options *BlockFileOptions) (*BlocksFile, error) {
46 options.EnsureDefaults()
47
48 var bFilename = fp.Name()
49 if !strings.HasSuffix(bFilename, BFileExt) {
50 return nil, errors.New("filename '" + bFilename + "' must has a '" + BFileExt + "' extension")
51 }
52
53 var mu = &sync.RWMutex{}
54
55 var mFilename = strings.TrimSuffix(bFilename, BFileExt) + MFileExt
56 mFile, err := OpenMetaFile(mFilename, mu)
57 if err != nil {
58 _ = fp.Close()
59 return nil, fmt.Errorf("load '%s' failed: %w", mFilename, err)
60 }
61
62 AckReadThread()
63 _, err = fp.Seek(0, io.SeekEnd)
64 ReleaseReadThread()
65 if err != nil {
66 _ = fp.Close()
67 _ = mFile.Close()
68 return nil, err
69 }
70
71 return &BlocksFile{
72 fp: fp,
73 mFile: mFile,
74 mu: mu,
75 opt: options,
76 syncAt: time.Now(),
77 readerPool: make(chan *FileReader, 32),
78 writingFileMap: map[string]zero.Zero{},
79 }, nil
80}
81
82func OpenBlocksFile(filename string, options *BlockFileOptions) (*BlocksFile, error) {
83 // TODO 考虑是否使用flock锁定,防止多进程写冲突

Callers 1

OpenBlocksFileFunction · 0.85

Calls 8

OpenMetaFileFunction · 0.85
AckReadThreadFunction · 0.85
ReleaseReadThreadFunction · 0.85
ErrorfMethod · 0.80
SeekMethod · 0.80
NameMethod · 0.65
CloseMethod · 0.65
EnsureDefaultsMethod · 0.45

Tested by

no test coverage detected