From 46c025b594f16892aca5792300127d5603e1b31f Mon Sep 17 00:00:00 2001 From: Levi Neely <141506390+lneely@users.noreply.github.com> Date: Tue, 19 May 2026 17:43:48 +0200 Subject: [PATCH] fix empty session directories: add WithListDir hook DirStore.ListDir now uses listDirFn when set. SessionManager wires ListDir through the hook so session subdirectory listing works via the DirStore view. --- store/dirstore.go | 9 +++++++++ store/session.go | 1 + 2 files changed, 10 insertions(+) diff --git a/store/dirstore.go b/store/dirstore.go index 75eae8f..63d3d89 100644 --- a/store/dirstore.go +++ b/store/dirstore.go @@ -23,6 +23,7 @@ type DirStore struct { renameFn func([]string, string, string) error openFn func([]string, string) (StoreEntry, error) statFn func([]string, string) (os.FileInfo, error) + listDirFn func([]string, string) ([]os.DirEntry, error) children map[string]*DirStore } @@ -73,6 +74,11 @@ func WithStat(fn func(dirs []string, name string) (os.FileInfo, error)) DirOptio return func(d *DirStore) { d.statFn = fn } } +// WithListDir overrides subdirectory listing. +func WithListDir(fn func(dirs []string, name string) ([]os.DirEntry, error)) DirOption { + return func(d *DirStore) { d.listDirFn = fn } +} + // NewDirStore creates a DirStore backed by one or more directories. // The first directory is the write target for unions. func NewDirStore(dirs []string, perm os.FileMode, opts ...DirOption) *DirStore { @@ -338,6 +344,9 @@ func (d *DirStore) ListDir(rel string) ([]os.DirEntry, error) { } return child.ListDir(rest) } + if d.listDirFn != nil { + return d.listDirFn(d.dirs, rel) + } if len(d.dirs) == 0 { return nil, fmt.Errorf("%s: not found", rel) } diff --git a/store/session.go b/store/session.go index 1c103f3..49ec564 100644 --- a/store/session.go +++ b/store/session.go @@ -155,6 +155,7 @@ func NewSessionManager(cfg SessionManagerConfig) *SessionManager { WithStat(func(_ []string, name string) (os.FileInfo, error) { return ss.stat(name) }), WithOpener(func(_ []string, name string) (StoreEntry, error) { return ss.openEntry(name) }), WithLister(func(_ []string) ([]os.DirEntry, error) { return ss.list() }), + WithListDir(func(_ []string, name string) ([]os.DirEntry, error) { return ss.ListDir(name) }), WithDeleter(func(_ []string, name string) error { return ss.del(name) }), WithCreator(func(_ []string, name string, _ os.FileMode) error { return ss.create(name) }), WithRenamer(func(_ []string, old, new string) error { return ss.renameSession(old, new) }),