internal/store: expose save via handle
All checks were successful
Test / Create distribution (push) Successful in 26s
Test / Sandbox (push) Successful in 42s
Test / Sandbox (race detector) (push) Successful in 42s
Test / Hakurei (push) Successful in 46s
Test / Hakurei (race detector) (push) Successful in 46s
Test / Hpkg (push) Successful in 42s
Test / Flake checks (push) Successful in 1m30s
All checks were successful
Test / Create distribution (push) Successful in 26s
Test / Sandbox (push) Successful in 42s
Test / Sandbox (race detector) (push) Successful in 42s
Test / Hakurei (push) Successful in 46s
Test / Hakurei (race detector) (push) Successful in 46s
Test / Hpkg (push) Successful in 42s
Test / Flake checks (push) Successful in 1m30s
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>
This commit is contained in:
@@ -54,11 +54,11 @@ func (eh *EntryHandle) Destroy() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Save encodes [hst.State] and writes it to the underlying file.
|
||||
// save encodes [hst.State] and writes it to the underlying file.
|
||||
// An error is returned if a file already exists with the same identifier.
|
||||
// Save does not validate the embedded [hst.Config].
|
||||
// A non-nil error returned by Save is of type [hst.AppError].
|
||||
func (eh *EntryHandle) Save(state *hst.State) error {
|
||||
// save does not validate the embedded [hst.Config].
|
||||
// A non-nil error returned by save is of type [hst.AppError].
|
||||
func (eh *EntryHandle) save(state *hst.State) error {
|
||||
f, err := eh.open(os.O_RDWR|os.O_CREATE|os.O_EXCL, 0600)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -123,6 +123,16 @@ func (h *Handle) Lock() (unlock func(), err error) {
|
||||
return
|
||||
}
|
||||
|
||||
// Save attempts to save [hst.State] as a segment entry, and returns its [EntryHandle].
|
||||
// Must be called while holding [Handle.Lock].
|
||||
// An error is returned if an entry already exists with the same identifier.
|
||||
// Save does not validate the embedded [hst.Config].
|
||||
// A non-nil error returned by Save is of type [hst.AppError].
|
||||
func (h *Handle) Save(state *hst.State) (*EntryHandle, error) {
|
||||
eh := EntryHandle{nil, h.Path.Append(state.ID.String()), state.ID}
|
||||
return &eh, eh.save(state)
|
||||
}
|
||||
|
||||
// Entries returns an iterator over all [EntryHandle] held in this segment.
|
||||
// Must be called while holding [Handle.Lock].
|
||||
// A non-nil error attached to a [EntryHandle] indicates a malformed identifier and is of type [hst.AppError].
|
||||
|
||||
Reference in New Issue
Block a user