MCPcopy
hub / github.com/benbjohnson/litestream / initWriteBufferWithLock

Method initWriteBufferWithLock

vfs.go:2097–2112  ·  view source on GitHub ↗

initWriteBufferWithLock initializes the write buffer file for durability. Any existing buffer content is discarded since unsync'd changes are lost on restart. Caller must hold f.mu.

()

Source from the content-addressed store, hash-verified

2095// Any existing buffer content is discarded since unsync'd changes are lost on restart.
2096// Caller must hold f.mu.
2097func (f *VFSFile) initWriteBufferWithLock() error {
2098 // Ensure parent directory exists
2099 if err := os.MkdirAll(filepath.Dir(f.bufferPath), 0755); err != nil {
2100 return fmt.Errorf("create buffer directory: %w", err)
2101 }
2102
2103 // Open or create buffer file, truncating any existing content
2104 file, err := os.OpenFile(f.bufferPath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644)
2105 if err != nil {
2106 return fmt.Errorf("open buffer file: %w", err)
2107 }
2108 f.bufferFile = file
2109 f.bufferNextOff = 0
2110
2111 return nil
2112}
2113
2114// writeToBuffer writes a dirty page to the write buffer for durability.
2115// If the page already exists in the buffer, it overwrites at the same offset.

Callers 2

initWriteBufferMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected