From ec251bf2963404f8ded5fed0b85c3f5b99fc4140 Mon Sep 17 00:00:00 2001 From: Levi Neely Date: Tue, 21 Apr 2026 16:14:40 +0200 Subject: [PATCH] store: use core synthetic types via aliases, remove local implementations --- internal/p9/batchstore.go | 8 +++--- internal/p9/sessionfilestore.go | 2 +- internal/p9/sessionstore.go | 4 +-- internal/p9/skillstore.go | 4 +-- internal/p9/store.go | 43 +++------------------------------ internal/p9/toolstore.go | 2 +- 6 files changed, 14 insertions(+), 49 deletions(-) diff --git a/internal/p9/batchstore.go b/internal/p9/batchstore.go index b9d00a4..20c860c 100644 --- a/internal/p9/batchstore.go +++ b/internal/p9/batchstore.go @@ -89,15 +89,15 @@ func (s *BatchStore) List() ([]os.DirEntry, error) { func (s *BatchStore) Stat(name string) (os.FileInfo, error) { switch name { case "new": - return &syntheticFileInfo{name: "new", mode: 0666, size: int64(len(batchNewTemplate))}, nil + return &syntheticFileInfo{Name_: "new", Mode_: 0666, Size_: int64(len(batchNewTemplate))}, nil case "idx": - return &syntheticFileInfo{name: "idx", mode: 0444, size: int64(len(s.index()))}, nil + return &syntheticFileInfo{Name_: "idx", Mode_: 0444, Size_: int64(len(s.index()))}, nil } s.mu.RLock() _, ok := s.jobs[name] s.mu.RUnlock() if ok { - return &syntheticFileInfo{name: name, mode: 0555, isDir: true}, nil + return &syntheticFileInfo{Name_: name, Mode_: 0555, IsDir_: true}, nil } return nil, fmt.Errorf("%s: not found", name) } @@ -449,7 +449,7 @@ func (js *BatchJobStore) Stat(name string) (os.FileInfo, error) { } else { size = int64(len(js.content(name))) } - return &syntheticFileInfo{name: name, mode: f.mode, size: size}, nil + return &syntheticFileInfo{Name_: name, Mode_: f.mode, Size_: size}, nil } } return nil, fmt.Errorf("%s: not found", name) diff --git a/internal/p9/sessionfilestore.go b/internal/p9/sessionfilestore.go index d8c3722..75913ff 100644 --- a/internal/p9/sessionfilestore.go +++ b/internal/p9/sessionfilestore.go @@ -77,7 +77,7 @@ func (s *SessionFileStore) Stat(name string) (os.FileInfo, error) { default: size = int64(len(s.content(name))) } - return &syntheticFileInfo{name: name, mode: f.mode, size: size}, nil + return &syntheticFileInfo{Name_: name, Mode_: f.mode, Size_: size}, nil } } return nil, fmt.Errorf("%s: not found", name) diff --git a/internal/p9/sessionstore.go b/internal/p9/sessionstore.go index 6233fc8..be38ef4 100644 --- a/internal/p9/sessionstore.go +++ b/internal/p9/sessionstore.go @@ -44,13 +44,13 @@ func (s *SessionStore) List() ([]os.DirEntry, error) { func (s *SessionStore) Stat(name string) (os.FileInfo, error) { if mode, ok := sessionStoreFiles[name]; ok { - return &syntheticFileInfo{name: name, mode: mode}, nil + return &syntheticFileInfo{Name_: name, Mode_: mode}, nil } s.srv.mu.RLock() _, ok := s.srv.sessions[name] s.srv.mu.RUnlock() if ok { - return &syntheticFileInfo{name: name, mode: 0555, isDir: true}, nil + return &syntheticFileInfo{Name_: name, Mode_: 0555, IsDir_: true}, nil } return nil, fmt.Errorf("%s: not found", name) } diff --git a/internal/p9/skillstore.go b/internal/p9/skillstore.go index e8d38cd..2120849 100644 --- a/internal/p9/skillstore.go +++ b/internal/p9/skillstore.go @@ -74,13 +74,13 @@ func readSkill(name string) ([]byte, error) { func (s *SkillStore) Stat(name string) (os.FileInfo, error) { if name == "idx" { - return &syntheticFileInfo{name: "idx", mode: 0444}, nil + return &syntheticFileInfo{Name_: "idx", Mode_: 0444}, nil } skillName := strings.TrimSuffix(name, ".md") if _, err := readSkill(skillName); err != nil { return nil, fmt.Errorf("%s: not found", name) } - return &syntheticFileInfo{name: name, mode: 0666}, nil + return &syntheticFileInfo{Name_: name, Mode_: 0666}, nil } func (s *SkillStore) List() ([]os.DirEntry, error) { diff --git a/internal/p9/store.go b/internal/p9/store.go index 8d08d0a..cca0936 100644 --- a/internal/p9/store.go +++ b/internal/p9/store.go @@ -2,7 +2,6 @@ package p9 import ( "os" - "time" "ollie/pkg/store" ) @@ -15,52 +14,18 @@ type ( BlobStore = store.BlobStore Store = store.Store FlatDirStore = store.FlatDir + + syntheticFileInfo = store.SyntheticFileInfo ) 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 - mode os.FileMode - size int64 - isDir bool -} - -func (f *syntheticFileInfo) Name() string { return f.name } -func (f *syntheticFileInfo) Size() int64 { return f.size } -func (f *syntheticFileInfo) Mode() os.FileMode { return f.mode } -func (f *syntheticFileInfo) ModTime() time.Time { return time.Time{} } -func (f *syntheticFileInfo) IsDir() bool { return f.isDir } -func (f *syntheticFileInfo) Sys() any { return nil } - -// syntheticEntryImpl implements os.DirEntry for entries with no backing file. -type syntheticEntryImpl struct { - name string - mode os.FileMode - isDir bool -} - -func (e *syntheticEntryImpl) Name() string { return e.name } -func (e *syntheticEntryImpl) IsDir() bool { return e.isDir } -func (e *syntheticEntryImpl) Type() os.FileMode { - if e.isDir { - return os.ModeDir - } - return 0 -} -func (e *syntheticEntryImpl) Info() (os.FileInfo, error) { - return &syntheticFileInfo{name: e.name, mode: e.mode, isDir: e.isDir}, nil -} - -// syntheticEntry returns a synthetic file DirEntry. func syntheticEntry(name string, mode os.FileMode) os.DirEntry { - return &syntheticEntryImpl{name: name, mode: mode} + return store.FileEntry(name, mode) } -// syntheticDirEntry returns a synthetic directory DirEntry. func syntheticDirEntry(name string, mode os.FileMode) os.DirEntry { - return &syntheticEntryImpl{name: name, mode: mode, isDir: true} + return store.DirEntry(name, mode) } diff --git a/internal/p9/toolstore.go b/internal/p9/toolstore.go index 9c3689f..b02f0bb 100644 --- a/internal/p9/toolstore.go +++ b/internal/p9/toolstore.go @@ -21,7 +21,7 @@ func NewToolStore() *ToolStore { func (s *ToolStore) Stat(name string) (os.FileInfo, error) { if name == "idx" { - return &syntheticFileInfo{name: "idx", mode: 0444}, nil + return &syntheticFileInfo{Name_: "idx", Mode_: 0444}, nil } return s.FlatDirStore.Stat(name) }