Documentation
¶
Overview ¶
Package store manages a volume's local on-disk state: a content-addressed blob store, the per-device journals, and small JSON state files. Everything a volume needs works offline; the remote is only used to exchange blobs and journals.
Layout under <beardrive home>/volumes/<volume>/:
blobs/<aa>/<sha256> content-addressed file contents (immutable) journal/<device>.jsonl per-device op logs (own + cached copies of peers) state.json what is currently materialized in the folder sync.json lamport clock + push cursor lock flock guarding cycles
Index ¶
- func WriteFileAtomic(path string, data []byte, mode os.FileMode) error
- func WriteJSONAtomic(path string, v any) error
- type CachedFile
- type Note
- type ReadEvent
- type Store
- func (s *Store) AllOps() ([]journal.Op, error)
- func (s *Store) AppendOps(device string, ops []journal.Op) error
- func (s *Store) BlobPath(sum string) string
- func (s *Store) ClearNote() error
- func (s *Store) ClearPendingReads() error
- func (s *Store) DeviceOps(device string) ([]journal.Op, error)
- func (s *Store) Devices() ([]string, error)
- func (s *Store) Dir() string
- func (s *Store) HasBlob(sum string) bool
- func (s *Store) JournalPath(device string) string
- func (s *Store) LoadCache(mountID string) (map[string]CachedFile, error)
- func (s *Store) LoadNote() string
- func (s *Store) LoadSync() (SyncState, error)
- func (s *Store) Lock() (func() error, error)
- func (s *Store) LogRead(rel string) error
- func (s *Store) OpenBlob(sum string) (*os.File, error)
- func (s *Store) PendingReads() ([]ReadEvent, error)
- func (s *Store) PutBlobBytes(b []byte) (string, int64, error)
- func (s *Store) PutBlobFile(path string) (string, int64, error)
- func (s *Store) PutBlobReader(r io.Reader) (string, int64, error)
- func (s *Store) SaveCache(mountID string, c map[string]CachedFile) error
- func (s *Store) SaveNote(text string, ttl time.Duration) error
- func (s *Store) SaveSync(st SyncState) error
- type SyncState
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WriteFileAtomic ¶
WriteFileAtomic writes data via a temp file in the same directory + rename.
func WriteJSONAtomic ¶
WriteJSONAtomic writes v as JSON via temp-file + rename.
Types ¶
type CachedFile ¶
type CachedFile struct {
Blob string `json:"blob"`
Size int64 `json:"size"`
Mode uint32 `json:"mode"`
MTimeNS int64 `json:"mtime_ns"`
}
CachedFile records what beardrive last wrote to / observed in the working folder for a path. Size+MTimeNS make change detection cheap; Blob ties it back to content. The cache is per mount (one volume can be materialized into several folders, each with its own stat fingerprints).
type Note ¶ added in v0.4.0
type Note struct {
Text string `json:"text"`
Expires time.Time `json:"expires,omitzero"` // zero = never expires
}
Note is the on-disk shape of the session note.
type ReadEvent ¶ added in v0.4.0
ReadEvent is one observed read of a synced file (mount-relative path).
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
func (*Store) ClearPendingReads ¶ added in v0.4.0
ClearPendingReads drops the batch PendingReads returned, after a successful report.
func (*Store) JournalPath ¶
func (*Store) LoadNote ¶ added in v0.4.0
LoadNote returns the live session note, or "" if none is set or it has expired. Never errors: a missing or unreadable note is just no note.
func (*Store) Lock ¶
Lock takes an exclusive flock for the volume, serializing sync cycles between the daemon and one-shot commands. Blocks until acquired.
func (*Store) LogRead ¶ added in v0.4.0
LogRead appends one read event to the spool. Single-line O_APPEND writes keep concurrent hook invocations from interleaving.
func (*Store) PendingReads ¶ added in v0.4.0
PendingReads returns the queued batch awaiting report, deduplicated by path (latest time wins). The spool is rotated aside first, so events logged after this call land in a fresh spool; the batch survives until ClearPendingReads — a failed report is simply retried next cycle.
func (*Store) PutBlobReader ¶
PutBlobReader streams r into the blob store, returning its sha256 and size.