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

Function OpenBlocksFile

internal/utils/bfs/blocks_file.go:82–100  ·  view source on GitHub ↗
(filename string, options *BlockFileOptions)

Source from the content-addressed store, hash-verified

80}
81
82func OpenBlocksFile(filename string, options *BlockFileOptions) (*BlocksFile, error) {
83 // TODO 考虑是否使用flock锁定,防止多进程写冲突
84 fp, err := os.OpenFile(filename, os.O_CREATE|os.O_WRONLY, 0666)
85 if err != nil {
86 if os.IsNotExist(err) {
87 var dir = filepath.Dir(filename)
88 _ = os.MkdirAll(dir, 0777)
89
90 // try again
91 fp, err = os.OpenFile(filename, os.O_CREATE|os.O_WRONLY, 0666)
92 }
93
94 if err != nil {
95 return nil, fmt.Errorf("open blocks file failed: %w", err)
96 }
97 }
98
99 return NewBlocksFileWithRawFile(fp, options)
100}
101
102func (this *BlocksFile) Filename() string {
103 return this.fp.Name()

Callers 12

TestNewFileWriterFunction · 0.92
TestFileReader_ReadAtFunction · 0.92
TestFileReader_PoolFunction · 0.92
TestBlocksFile_CanCloseFunction · 0.92
TestBlocksFile_RemoveAllFunction · 0.92
openBFileMethod · 0.85

Calls 2

NewBlocksFileWithRawFileFunction · 0.85
ErrorfMethod · 0.80

Tested by 11

TestNewFileWriterFunction · 0.74
TestFileReader_ReadAtFunction · 0.74
TestFileReader_PoolFunction · 0.74
TestBlocksFile_CanCloseFunction · 0.74
TestBlocksFile_RemoveAllFunction · 0.74