diff options
| author | Ophestra <cat@gensokyo.uk> | 2025-10-31 04:20:22 +0900 |
|---|---|---|
| committer | Ophestra <cat@gensokyo.uk> | 2025-10-31 04:20:22 +0900 |
| commit | 6a0ecced9021482f1f2f05d6ec63c1e4cd33c8a0 (patch) | |
| tree | 9310939469a43d6688355ec7413bd2499915f5cb /internal/store/compat.go | |
| parent | b667fea1cbb6e4efc4f79ea02df6471f7826a42a (diff) | |
internal/store: expose save via handle
The handle is otherwise inaccessible without the compat interface. This change also moves compatibility methods to separate adapter structs to avoid inadvertently using them.
Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'internal/store/compat.go')
| -rw-r--r-- | internal/store/compat.go | 31 |
1 files changed, 16 insertions, 15 deletions
diff --git a/internal/store/compat.go b/internal/store/compat.go index aca26b8c..c0d4057c 100644 --- a/internal/store/compat.go +++ b/internal/store/compat.go @@ -22,20 +22,20 @@ type Compat interface { List() (identities []int, err error) } -func (s *Store) Do(identity int, f func(c Cursor)) (bool, error) { - if h, err := s.Handle(identity); err != nil { - return false, err - } else { - return h.do(f) - } -} - // storeAdapter satisfies [Compat] via [Store]. type storeAdapter struct { msg message.Msg *Store } +func (s storeAdapter) Do(identity int, f func(c Cursor)) (bool, error) { + if h, err := s.Handle(identity); err != nil { + return false, err + } else { + return handleAdapter{h}.do(f) + } +} + func (s storeAdapter) List() ([]int, error) { segments, n, err := s.Segments() if err != nil { @@ -71,8 +71,11 @@ type Cursor interface { Len() (int, error) } +// handleAdapter satisfies [Cursor] via [Handle]. +type handleAdapter struct{ *Handle } + // do implements [Compat.Do] on [Handle]. -func (h *Handle) do(f func(c Cursor)) (bool, error) { +func (h handleAdapter) do(f func(c Cursor)) (bool, error) { if unlock, err := h.Lock(); err != nil { return false, err } else { @@ -85,15 +88,13 @@ func (h *Handle) do(f func(c Cursor)) (bool, error) { /* these compatibility methods must only be called while fileMu is held */ -func (h *Handle) Save(state *hst.State) error { - return (&EntryHandle{nil, h.Path.Append(state.ID.String()), state.ID}).Save(state) -} +func (h handleAdapter) Save(state *hst.State) error { _, err := h.Handle.Save(state); return err } -func (h *Handle) Destroy(id hst.ID) error { +func (h handleAdapter) Destroy(id hst.ID) error { return (&EntryHandle{nil, h.Path.Append(id.String()), id}).Destroy() } -func (h *Handle) Load() (map[hst.ID]*hst.State, error) { +func (h handleAdapter) Load() (map[hst.ID]*hst.State, error) { entries, n, err := h.Entries() if err != nil { return nil, err @@ -114,7 +115,7 @@ func (h *Handle) Load() (map[hst.ID]*hst.State, error) { return r, err } -func (h *Handle) Len() (int, error) { +func (h handleAdapter) Len() (int, error) { entries, _, err := h.Entries() if err != nil { return -1, err |
