Skip to content

Commit

Permalink
fix: folder listing without globs
Browse files Browse the repository at this point in the history
  • Loading branch information
moshloop committed Sep 15, 2024
1 parent 63b29fe commit ab5baf5
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions fs/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"io"
"os"
"path/filepath"
"strings"

"github.com/bmatcuk/doublestar/v4"
)
Expand Down Expand Up @@ -33,6 +34,31 @@ func (t *localFS) Close() error {
}

func (t *localFS) ReadDir(name string) ([]FileInfo, error) {
if strings.Contains(name, "*") {
return t.ReadDirGlob(name)
}

path := filepath.Join(t.base, name)
files, err := os.ReadDir(path)
if err != nil {
return nil, err
}

output := make([]FileInfo, 0, len(files))
for _, match := range files {
fullPath := filepath.Join(path, match.Name())
info, err := os.Stat(fullPath)
if err != nil {
return nil, err
}

output = append(output, localFileInfo{FileInfo: info, fullpath: fullPath})
}

return output, nil
}

func (t *localFS) ReadDirGlob(name string) ([]FileInfo, error) {
base, pattern := doublestar.SplitPattern(filepath.Join(t.base, name))
matches, err := doublestar.Glob(os.DirFS(base), pattern)
if err != nil {
Expand Down

0 comments on commit ab5baf5

Please sign in to comment.