internal/store: rename from state
All checks were successful
Test / Create distribution (push) Successful in 33s
Test / Sandbox (push) Successful in 2m9s
Test / Hakurei (push) Successful in 3m8s
Test / Hpkg (push) Successful in 4m2s
Test / Sandbox (race detector) (push) Successful in 4m7s
Test / Hakurei (race detector) (push) Successful in 4m55s
Test / Flake checks (push) Successful in 1m25s
All checks were successful
Test / Create distribution (push) Successful in 33s
Test / Sandbox (push) Successful in 2m9s
Test / Hakurei (push) Successful in 3m8s
Test / Hpkg (push) Successful in 4m2s
Test / Sandbox (race detector) (push) Successful in 4m7s
Test / Hakurei (race detector) (push) Successful in 4m55s
Test / Flake checks (push) Successful in 1m25s
This reduces collision with local variable names, and generally makes sense for the new store package, since it no longer specifies the state struct. Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
parent
46c5ce4936
commit
ebdcff1049
@ -20,7 +20,7 @@ import (
|
|||||||
"hakurei.app/internal"
|
"hakurei.app/internal"
|
||||||
"hakurei.app/internal/env"
|
"hakurei.app/internal/env"
|
||||||
"hakurei.app/internal/outcome"
|
"hakurei.app/internal/outcome"
|
||||||
"hakurei.app/internal/state"
|
"hakurei.app/internal/store"
|
||||||
"hakurei.app/message"
|
"hakurei.app/message"
|
||||||
"hakurei.app/system/dbus"
|
"hakurei.app/system/dbus"
|
||||||
)
|
)
|
||||||
@ -322,7 +322,7 @@ func buildCommand(ctx context.Context, msg message.Msg, early *earlyHardeningErr
|
|||||||
c.NewCommand("ps", "List active instances", func(args []string) error {
|
c.NewCommand("ps", "List active instances", func(args []string) error {
|
||||||
var sc hst.Paths
|
var sc hst.Paths
|
||||||
env.CopyPaths().Copy(&sc, new(outcome.Hsu).MustID(nil))
|
env.CopyPaths().Copy(&sc, new(outcome.Hsu).MustID(nil))
|
||||||
printPs(os.Stdout, time.Now().UTC(), state.NewMulti(msg, sc.RunDirPath), flagShort, flagJSON)
|
printPs(os.Stdout, time.Now().UTC(), store.NewMulti(msg, sc.RunDirPath), flagShort, flagJSON)
|
||||||
return errSuccess
|
return errSuccess
|
||||||
}).Flag(&flagShort, "short", command.BoolFlag(false), "Print instance id")
|
}).Flag(&flagShort, "short", command.BoolFlag(false), "Print instance id")
|
||||||
}
|
}
|
||||||
|
|||||||
@ -13,7 +13,7 @@ import (
|
|||||||
"hakurei.app/hst"
|
"hakurei.app/hst"
|
||||||
"hakurei.app/internal/env"
|
"hakurei.app/internal/env"
|
||||||
"hakurei.app/internal/outcome"
|
"hakurei.app/internal/outcome"
|
||||||
"hakurei.app/internal/state"
|
"hakurei.app/internal/store"
|
||||||
"hakurei.app/message"
|
"hakurei.app/message"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -85,8 +85,8 @@ func tryIdentifier(msg message.Msg, name string) (config *hst.Config, entry *hst
|
|||||||
return tryIdentifierEntries(msg, name, func() map[hst.ID]*hst.State {
|
return tryIdentifierEntries(msg, name, func() map[hst.ID]*hst.State {
|
||||||
var sc hst.Paths
|
var sc hst.Paths
|
||||||
env.CopyPaths().Copy(&sc, new(outcome.Hsu).MustID(nil))
|
env.CopyPaths().Copy(&sc, new(outcome.Hsu).MustID(nil))
|
||||||
s := state.NewMulti(msg, sc.RunDirPath)
|
s := store.NewMulti(msg, sc.RunDirPath)
|
||||||
if entries, err := state.Join(s); err != nil {
|
if entries, err := store.Join(s); err != nil {
|
||||||
msg.GetLogger().Printf("cannot join store: %v", err) // not fatal
|
msg.GetLogger().Printf("cannot join store: %v", err) // not fatal
|
||||||
return nil
|
return nil
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -14,7 +14,7 @@ import (
|
|||||||
"hakurei.app/internal"
|
"hakurei.app/internal"
|
||||||
"hakurei.app/internal/env"
|
"hakurei.app/internal/env"
|
||||||
"hakurei.app/internal/outcome"
|
"hakurei.app/internal/outcome"
|
||||||
"hakurei.app/internal/state"
|
"hakurei.app/internal/store"
|
||||||
"hakurei.app/message"
|
"hakurei.app/message"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -168,9 +168,9 @@ func printShowInstance(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// printPs writes a representation of active instances to output.
|
// printPs writes a representation of active instances to output.
|
||||||
func printPs(output io.Writer, now time.Time, s state.Store, short, flagJSON bool) {
|
func printPs(output io.Writer, now time.Time, s store.Store, short, flagJSON bool) {
|
||||||
var entries map[hst.ID]*hst.State
|
var entries map[hst.ID]*hst.State
|
||||||
if e, err := state.Join(s); err != nil {
|
if e, err := store.Join(s); err != nil {
|
||||||
log.Fatalf("cannot join store: %v", err)
|
log.Fatalf("cannot join store: %v", err)
|
||||||
} else {
|
} else {
|
||||||
entries = e
|
entries = e
|
||||||
|
|||||||
@ -6,7 +6,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"hakurei.app/hst"
|
"hakurei.app/hst"
|
||||||
"hakurei.app/internal/state"
|
"hakurei.app/internal/store"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -709,6 +709,6 @@ func TestPrintPs(t *testing.T) {
|
|||||||
type stubStore map[hst.ID]*hst.State
|
type stubStore map[hst.ID]*hst.State
|
||||||
|
|
||||||
func (s stubStore) Join() (map[hst.ID]*hst.State, error) { return s, nil }
|
func (s stubStore) Join() (map[hst.ID]*hst.State, error) { return s, nil }
|
||||||
func (s stubStore) Do(int, func(c state.Cursor)) (bool, error) { panic("unreachable") }
|
func (s stubStore) Do(int, func(c store.Cursor)) (bool, error) { panic("unreachable") }
|
||||||
func (s stubStore) List() ([]int, error) { panic("unreachable") }
|
func (s stubStore) List() ([]int, error) { panic("unreachable") }
|
||||||
func (s stubStore) Close() error { return nil }
|
func (s stubStore) Close() error { return nil }
|
||||||
|
|||||||
@ -15,7 +15,7 @@ import (
|
|||||||
"hakurei.app/container/fhs"
|
"hakurei.app/container/fhs"
|
||||||
"hakurei.app/hst"
|
"hakurei.app/hst"
|
||||||
"hakurei.app/internal"
|
"hakurei.app/internal"
|
||||||
"hakurei.app/internal/state"
|
"hakurei.app/internal/store"
|
||||||
"hakurei.app/message"
|
"hakurei.app/message"
|
||||||
"hakurei.app/system"
|
"hakurei.app/system"
|
||||||
)
|
)
|
||||||
@ -34,7 +34,7 @@ type mainState struct {
|
|||||||
// Time is nil if no process was ever created.
|
// Time is nil if no process was ever created.
|
||||||
Time *time.Time
|
Time *time.Time
|
||||||
|
|
||||||
store state.Store
|
store store.Store
|
||||||
cancel context.CancelFunc
|
cancel context.CancelFunc
|
||||||
cmd *exec.Cmd
|
cmd *exec.Cmd
|
||||||
cmdWait chan error
|
cmdWait chan error
|
||||||
@ -127,7 +127,7 @@ func (ms mainState) beforeExit(isFault bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ms.uintptr&mainNeedsRevert != 0 {
|
if ms.uintptr&mainNeedsRevert != 0 {
|
||||||
if ok, err := ms.store.Do(ms.k.state.identity.unwrap(), func(c state.Cursor) {
|
if ok, err := ms.store.Do(ms.k.state.identity.unwrap(), func(c store.Cursor) {
|
||||||
if ms.uintptr&mainNeedsDestroy != 0 {
|
if ms.uintptr&mainNeedsDestroy != 0 {
|
||||||
if err := c.Destroy(ms.k.state.id.unwrap()); err != nil {
|
if err := c.Destroy(ms.k.state.id.unwrap()); err != nil {
|
||||||
perror(err, "destroy state entry")
|
perror(err, "destroy state entry")
|
||||||
@ -220,7 +220,7 @@ func (k *outcome) main(msg message.Msg) {
|
|||||||
ms.fatal("cannot commit system setup:", err)
|
ms.fatal("cannot commit system setup:", err)
|
||||||
}
|
}
|
||||||
ms.uintptr |= mainNeedsRevert
|
ms.uintptr |= mainNeedsRevert
|
||||||
ms.store = state.NewMulti(msg, k.state.sc.RunDirPath)
|
ms.store = store.NewMulti(msg, k.state.sc.RunDirPath)
|
||||||
|
|
||||||
ctx, cancel := context.WithCancel(k.ctx)
|
ctx, cancel := context.WithCancel(k.ctx)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
@ -281,7 +281,7 @@ func (k *outcome) main(msg message.Msg) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// shim accepted setup payload, create process state
|
// shim accepted setup payload, create process state
|
||||||
if ok, err := ms.store.Do(k.state.identity.unwrap(), func(c state.Cursor) {
|
if ok, err := ms.store.Do(k.state.identity.unwrap(), func(c store.Cursor) {
|
||||||
if err := c.Save(&hst.State{
|
if err := c.Save(&hst.State{
|
||||||
ID: k.state.id.unwrap(),
|
ID: k.state.id.unwrap(),
|
||||||
PID: os.Getpid(),
|
PID: os.Getpid(),
|
||||||
|
|||||||
@ -1,5 +1,4 @@
|
|||||||
// Package state provides cross-process state tracking for hakurei container instances.
|
package store
|
||||||
package state
|
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strconv"
|
"strconv"
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package state_test
|
package store_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
||||||
@ -10,12 +10,12 @@ import (
|
|||||||
|
|
||||||
"hakurei.app/container/check"
|
"hakurei.app/container/check"
|
||||||
"hakurei.app/hst"
|
"hakurei.app/hst"
|
||||||
"hakurei.app/internal/state"
|
"hakurei.app/internal/store"
|
||||||
"hakurei.app/message"
|
"hakurei.app/message"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestMulti(t *testing.T) {
|
func TestMulti(t *testing.T) {
|
||||||
s := state.NewMulti(message.NewMsg(log.New(log.Writer(), "multi: ", 0)), check.MustAbs(t.TempDir()))
|
s := store.NewMulti(message.NewMsg(log.New(log.Writer(), "multi: ", 0)), check.MustAbs(t.TempDir()))
|
||||||
|
|
||||||
t.Run("list empty store", func(t *testing.T) {
|
t.Run("list empty store", func(t *testing.T) {
|
||||||
if identities, err := s.List(); err != nil {
|
if identities, err := s.List(); err != nil {
|
||||||
@ -43,14 +43,14 @@ func TestMulti(t *testing.T) {
|
|||||||
tc[i].Time = time.Now()
|
tc[i].Time = time.Now()
|
||||||
}
|
}
|
||||||
|
|
||||||
do := func(identity int, f func(c state.Cursor)) {
|
do := func(identity int, f func(c store.Cursor)) {
|
||||||
if ok, err := s.Do(identity, f); err != nil {
|
if ok, err := s.Do(identity, f); err != nil {
|
||||||
t.Fatalf("Do: ok = %v, error = %v", ok, err)
|
t.Fatalf("Do: ok = %v, error = %v", ok, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
insert := func(i, identity int) {
|
insert := func(i, identity int) {
|
||||||
do(identity, func(c state.Cursor) {
|
do(identity, func(c store.Cursor) {
|
||||||
if err := c.Save(&tc[i]); err != nil {
|
if err := c.Save(&tc[i]); err != nil {
|
||||||
t.Fatalf("Save: error = %v", err)
|
t.Fatalf("Save: error = %v", err)
|
||||||
}
|
}
|
||||||
@ -58,7 +58,7 @@ func TestMulti(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
check := func(i, identity int) {
|
check := func(i, identity int) {
|
||||||
do(identity, func(c state.Cursor) {
|
do(identity, func(c store.Cursor) {
|
||||||
if entries, err := c.Load(); err != nil {
|
if entries, err := c.Load(); err != nil {
|
||||||
t.Fatalf("Load: error = %v", err)
|
t.Fatalf("Load: error = %v", err)
|
||||||
} else if got, ok := entries[tc[i].ID]; !ok {
|
} else if got, ok := entries[tc[i].ID]; !ok {
|
||||||
@ -98,19 +98,19 @@ func TestMulti(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// join store
|
// join store
|
||||||
if entries, err := state.Join(s); err != nil {
|
if entries, err := store.Join(s); err != nil {
|
||||||
t.Fatalf("Join: error = %v", err)
|
t.Fatalf("Join: error = %v", err)
|
||||||
} else if len(entries) != 3 {
|
} else if len(entries) != 3 {
|
||||||
t.Fatalf("Join(s) = %#v", entries)
|
t.Fatalf("Join(s) = %#v", entries)
|
||||||
}
|
}
|
||||||
|
|
||||||
// clear identity 1
|
// clear identity 1
|
||||||
do(1, func(c state.Cursor) {
|
do(1, func(c store.Cursor) {
|
||||||
if err := c.Destroy(tc[insertEntryOtherApp].ID); err != nil {
|
if err := c.Destroy(tc[insertEntryOtherApp].ID); err != nil {
|
||||||
t.Fatalf("Destroy: error = %v", err)
|
t.Fatalf("Destroy: error = %v", err)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
do(1, func(c state.Cursor) {
|
do(1, func(c store.Cursor) {
|
||||||
if l, err := c.Len(); err != nil {
|
if l, err := c.Len(); err != nil {
|
||||||
t.Fatalf("Len: error = %v", err)
|
t.Fatalf("Len: error = %v", err)
|
||||||
} else if l != 0 {
|
} else if l != 0 {
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package state
|
package store
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/gob"
|
"encoding/gob"
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package state
|
package store
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package state
|
package store
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package state
|
package store
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package state
|
package store
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package state
|
package store
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package state
|
package store
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package state
|
package store
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package state
|
package store
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"cmp"
|
"cmp"
|
||||||
Loading…
x
Reference in New Issue
Block a user