arche / internal/store/store.go

commit 154431fd
  1package store
  2
  3import (
  4	"database/sql"
  5
  6	"arche/internal/object"
  7)
  8
  9type Bookmark struct {
 10	Name     string
 11	CommitID [32]byte
 12	Remote   string
 13}
 14
 15type WCacheEntry struct {
 16	Path    string
 17	Inode   uint64
 18	MtimeNs int64
 19	Size    int64
 20	BlobID  [32]byte
 21	Mode    uint8 // object.EntryMode value (0=file,1=exec,2=symlink,3=dir)
 22	Dirty   bool  // set by watcher; cleared by snap/status after processing
 23}
 24
 25type Operation struct {
 26	Seq       int64
 27	Kind      string
 28	Timestamp int64
 29	Before    string
 30	After     string
 31	Metadata  string
 32}
 33
 34type Tx struct {
 35	sqlTx *sql.Tx
 36}
 37
 38func (t *Tx) SQLTx() *sql.Tx { return t.sqlTx }
 39
 40type Store interface {
 41	HasObject(id [32]byte) (bool, error)
 42	ReadObject(id [32]byte) (kind string, raw []byte, err error)
 43	WriteObject(tx *Tx, id [32]byte, kind string, raw []byte) error
 44	ListObjectsByKind(kind string) ([][32]byte, error)
 45
 46	GetBookmark(name string) (*Bookmark, error)
 47	SetBookmark(tx *Tx, b Bookmark) error
 48	DeleteBookmark(tx *Tx, name string) error
 49	ListBookmarks() ([]Bookmark, error)
 50
 51	GetPhase(commitID [32]byte) (object.Phase, error)
 52	SetPhase(tx *Tx, commitID [32]byte, phase object.Phase) error
 53	ListPublicCommitIDs() ([][32]byte, error)
 54
 55	AllocChangeID(tx *Tx) (string, error)
 56	GetChangeCommit(changeID string) ([32]byte, error)
 57	SetChangeCommit(tx *Tx, changeID string, commitID [32]byte) error
 58	ListChanges() ([]Bookmark, error)
 59
 60	GetWCacheEntry(path string) (*WCacheEntry, error)
 61	SetWCacheEntry(tx *Tx, e WCacheEntry) error
 62	DeleteWCacheEntry(tx *Tx, path string) error
 63	ListWCacheEntries() ([]WCacheEntry, error)
 64	ClearWCache(tx *Tx) error
 65	MarkWCacheDirty(path string) error
 66	ListDirtyWCacheEntries() ([]WCacheEntry, error)
 67	ClearWCacheDirtyFlags(tx *Tx) error
 68
 69	InsertOperation(tx *Tx, op Operation) (int64, error)
 70	ListOperations(n int) ([]Operation, error)
 71	GetOperation(seq int64) (*Operation, error)
 72	GetLastOperation() (*Operation, error)
 73
 74	AddConflict(tx *Tx, path string) error
 75	ClearConflict(tx *Tx, path string) error
 76	ClearAllConflicts(tx *Tx) error
 77	ListConflicts() ([]string, error)
 78	ListSecretCommitIDs() ([][32]byte, error)
 79
 80	Begin() (*Tx, error)
 81	Commit(tx *Tx) error
 82	Rollback(tx *Tx) error
 83	Close() error
 84}
 85
 86type FileLock struct {
 87	Path       string
 88	Owner      string
 89	AcquiredAt int64
 90	Comment    string
 91}
 92
 93type LockStore interface {
 94	AcquireLock(tx *Tx, path, owner, comment string) error
 95	ReleaseLock(tx *Tx, path, owner string) error
 96	ReleaseLockAdmin(tx *Tx, path string) error
 97	GetLock(path string) (*FileLock, error)
 98	ListLocks() ([]FileLock, error)
 99}
100
101type DictTrainer interface {
102	TrainAndSaveDict() error
103}