store

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 10, 2026 License: AGPL-3.0 Imports: 11 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func WriteFileAtomic

func WriteFileAtomic(path string, data []byte, mode os.FileMode) error

WriteFileAtomic writes data via a temp file in the same directory + rename.

func WriteJSONAtomic

func WriteJSONAtomic(path string, v any) error

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 Store

type Store struct {
	// contains filtered or unexported fields
}

func Open

func Open(dir string) (*Store, error)

func (*Store) AllOps

func (s *Store) AllOps() ([]journal.Op, error)

AllOps returns the union of every journal known locally.

func (*Store) AppendOps

func (s *Store) AppendOps(device string, ops []journal.Op) error

func (*Store) BlobPath

func (s *Store) BlobPath(sum string) string

func (*Store) DeviceOps

func (s *Store) DeviceOps(device string) ([]journal.Op, error)

func (*Store) Devices

func (s *Store) Devices() ([]string, error)

Devices lists device IDs that have a local journal copy.

func (*Store) Dir

func (s *Store) Dir() string

func (*Store) HasBlob

func (s *Store) HasBlob(sum string) bool

func (*Store) JournalPath

func (s *Store) JournalPath(device string) string

func (*Store) LoadCache

func (s *Store) LoadCache(mountID string) (map[string]CachedFile, error)

func (*Store) LoadSync

func (s *Store) LoadSync() (SyncState, error)

func (*Store) Lock

func (s *Store) Lock() (func() error, error)

Lock takes an exclusive flock for the volume, serializing sync cycles between the daemon and one-shot commands. Blocks until acquired.

func (*Store) OpenBlob

func (s *Store) OpenBlob(sum string) (*os.File, error)

func (*Store) PutBlobBytes

func (s *Store) PutBlobBytes(b []byte) (string, int64, error)

func (*Store) PutBlobFile

func (s *Store) PutBlobFile(path string) (string, int64, error)

func (*Store) PutBlobReader

func (s *Store) PutBlobReader(r io.Reader) (string, int64, error)

PutBlobReader streams r into the blob store, returning its sha256 and size.

func (*Store) SaveCache

func (s *Store) SaveCache(mountID string, c map[string]CachedFile) error

func (*Store) SaveSync

func (s *Store) SaveSync(st SyncState) error

type SyncState

type SyncState struct {
	Lamport   int64 `json:"lamport"`
	PushedOps int64 `json:"pushed_ops"` // how many of our own ops the remote has
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL