1package localfs
2
3import (
4 "io/fs"
5 "os"
6 "path"
7 "strings"
8)
9
10type FileSystemRepository struct {
11 root string
12}
13
14func NewFileSystemRepository() *FileSystemRepository {
15 return &FileSystemRepository{}
16}
17
18func (self *FileSystemRepository) getFilesFromPath(filepath string) ([]fs.FileInfo, error) {
19 dirs, err := os.ReadDir(filepath)
20 if err != nil {
21 return nil, err
22 }
23
24 infos := make([]fs.FileInfo, 0, len(dirs))
25 for _, dir := range dirs {
26 if strings.HasPrefix(dir.Name(), ".") {
27 continue
28 }
29 info, err := dir.Info()
30 if err != nil {
31 return nil, err
32 }
33 infos = append(infos, info)
34 }
35
36 return infos, nil
37}
38
39func (self *FileSystemRepository) List(filepath string) ([]fs.FileInfo, error) {
40 workingPath := path.Join(self.root, filepath)
41 return self.getFilesFromPath(workingPath)
42}
43
44func (self *FileSystemRepository) Stat(filepath string) (fs.FileInfo, error) {
45 workingPath := path.Join(self.root, filepath)
46 return os.Stat(workingPath)
47}