From 0aceefe75fddb911711b4c3b31dbbcc8bc10022a Mon Sep 17 00:00:00 2001 From: Levi Neely Date: Tue, 21 Apr 2026 16:10:21 +0200 Subject: [PATCH] store: use core pkg/store, re-export types as aliases Replace local store interfaces and FlatDirStore with type aliases to ollie/pkg/store. Synthetic dir entry helpers remain 9p-local. --- internal/p9/configstore.go | 3 +- internal/p9/store.go | 95 +++++++------------------------------- 2 files changed, 17 insertions(+), 81 deletions(-) diff --git a/internal/p9/configstore.go b/internal/p9/configstore.go index f78baa0..b2b966a 100644 --- a/internal/p9/configstore.go +++ b/internal/p9/configstore.go @@ -3,7 +3,6 @@ package p9 import ( "os" - "ollie/pkg/agent" "ollie/pkg/config" ) @@ -11,7 +10,7 @@ import ( // Returns nil (not an error) if the config file does not exist; // BuildAgentEnv handles nil configs. func loadAgentConfig(agentsDir, name string) *config.Config { - f, err := os.Open(agent.AgentConfigPath(agentsDir, name)) + f, err := os.Open(agentsDir + "/" + name + ".json") if err != nil { return nil } diff --git a/internal/p9/store.go b/internal/p9/store.go index 2583dc5..8d08d0a 100644 --- a/internal/p9/store.go +++ b/internal/p9/store.go @@ -2,10 +2,25 @@ package p9 import ( "os" - "path/filepath" "time" + + "ollie/pkg/store" ) +// Re-export core store types so existing 9p code compiles unchanged. +type ( + ReadableStore = store.ReadableStore + WritableStore = store.WritableStore + ReadWriteStore = store.ReadWriteStore + BlobStore = store.BlobStore + Store = store.Store + FlatDirStore = store.FlatDir +) + +func NewFlatDirStore(dir string, perm os.FileMode) *FlatDirStore { + return store.NewFlatDir(dir, perm) +} + // syntheticFileInfo implements os.FileInfo for entries with no backing file. type syntheticFileInfo struct { name string @@ -49,81 +64,3 @@ func syntheticEntry(name string, mode os.FileMode) os.DirEntry { func syntheticDirEntry(name string, mode os.FileMode) os.DirEntry { return &syntheticEntryImpl{name: name, mode: mode, isDir: true} } - -// ReadableStore is a named collection of byte blobs supporting only read operations. -type ReadableStore interface { - Stat(name string) (os.FileInfo, error) - List() ([]os.DirEntry, error) - Get(name string) ([]byte, error) -} - -// WritableStore supports writing blobs by name. -type WritableStore interface { - Put(name string, data []byte) error -} - -// ReadWriteStore supports reading and writing but not structural mutations. -type ReadWriteStore interface { - ReadableStore - WritableStore -} - -// BlobStore extends ReadWriteStore with creation and deletion. -// Suitable for content-addressed or append-only backing stores. -type BlobStore interface { - ReadWriteStore - Delete(name string) error - Create(name string) error -} - -// Store is a fully mutable store that also supports renaming entries. -type Store interface { - BlobStore - Rename(oldName, newName string) error -} - -// FlatDirStore implements Store backed by a directory on the local filesystem. -type FlatDirStore struct { - dir string - perm os.FileMode -} - -// NewFlatDirStore returns a FlatDirStore rooted at dir. -// perm is applied to newly created or written files. -func NewFlatDirStore(dir string, perm os.FileMode) *FlatDirStore { - return &FlatDirStore{dir: dir, perm: perm} -} - -func (s *FlatDirStore) Stat(name string) (os.FileInfo, error) { - return os.Stat(filepath.Join(s.dir, name)) -} - -func (s *FlatDirStore) List() ([]os.DirEntry, error) { - return os.ReadDir(s.dir) -} - -func (s *FlatDirStore) Get(name string) ([]byte, error) { - return os.ReadFile(filepath.Join(s.dir, name)) -} - -func (s *FlatDirStore) Put(name string, data []byte) error { - if err := os.MkdirAll(s.dir, 0755); err != nil { - return err - } - return os.WriteFile(filepath.Join(s.dir, name), data, s.perm) -} - -func (s *FlatDirStore) Delete(name string) error { - return os.Remove(filepath.Join(s.dir, name)) -} - -func (s *FlatDirStore) Create(name string) error { - if err := os.MkdirAll(s.dir, 0755); err != nil { - return err - } - return os.WriteFile(filepath.Join(s.dir, name), nil, s.perm) -} - -func (s *FlatDirStore) Rename(oldName, newName string) error { - return os.Rename(filepath.Join(s.dir, oldName), filepath.Join(s.dir, newName)) -}