Files
litestream/db_bsd.go
Ben Johnson a090706421 Implement live read replication
This commit adds an http server and client for streaming snapshots
and WAL pages from an upstream Litestream primary to a read-only
replica.
2022-02-19 09:06:49 -07:00

22 lines
454 B
Go

//go:build !linux
package litestream
import (
"io"
"os"
)
// WithFile executes fn with a file handle for the main database file.
// On Linux, this is a unique file handle for each call. On non-Linux
// systems, the file handle is shared because of lock semantics.
func (db *DB) WithFile(fn func(f *os.File) error) error {
db.mu.Lock()
defer db.mu.Unlock()
if _, err := db.f.Seek(0, io.SeekStart); err != nil {
return err
}
return fn(db.f)
}