internal/app/state: improve store internals

This fully exposes the store internals for #19 and are final preparations for removing the legacy store interface.

This change also fixes a potential deadlock in the handle initialisation mkdir failure path. This however is never reachable in hakurei as the store is never accessed concurrently.

Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
2025-10-28 23:04:17 +09:00
parent 5e5826459e
commit 65342d588f
5 changed files with 382 additions and 72 deletions

View File

@@ -194,19 +194,7 @@ func TestStoreHandle(t *testing.T) {
if err := os.Mkdir(p.String(), 0700); err != nil {
t.Fatal(err.Error())
}
for _, s := range tc.ents[0] {
if f, err := os.OpenFile(p.Append(s).String(), os.O_CREATE|os.O_EXCL, 0600); err != nil {
t.Fatal(err.Error())
} else if err = f.Close(); err != nil {
t.Fatal(err.Error())
}
}
for _, s := range tc.ents[1] {
if err := os.Mkdir(p.Append(s).String(), 0700); err != nil {
t.Fatal(err.Error())
}
}
createEntries(t, p, tc.ents)
var got []*stateEntryHandle
if entries, n, err := (&storeHandle{
@@ -253,3 +241,19 @@ func TestStoreHandle(t *testing.T) {
}
})
}
// createEntries creates file and directory entries in the specified prefix.
func createEntries(t *testing.T, prefix *check.Absolute, ents [2][]string) {
for _, s := range ents[0] {
if f, err := os.OpenFile(prefix.Append(s).String(), os.O_CREATE|os.O_EXCL, 0600); err != nil {
t.Fatal(err.Error())
} else if err = f.Close(); err != nil {
t.Fatal(err.Error())
}
}
for _, s := range ents[1] {
if err := os.Mkdir(prefix.Append(s).String(), 0700); err != nil {
t.Fatal(err.Error())
}
}
}