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.
This commit is contained in:
parent
18aaddd8b1
commit
46c025b594
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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) }),
|
||||
|
|
|
|||
Reference in New Issue