lens @ 024da3e546e98cbaeea5f7bc86af12b671996f41

 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(root string) *FileSystemRepository {
15	return &FileSystemRepository{
16		root: root,
17	}
18}
19
20func (self *FileSystemRepository) getFilesFromPath(filepath string) ([]fs.FileInfo, error) {
21	dirs, err := os.ReadDir(filepath)
22	if err != nil {
23		return nil, err
24	}
25
26	infos := make([]fs.FileInfo, 0, len(dirs))
27	for _, dir := range dirs {
28		if strings.HasPrefix(dir.Name(), ".") {
29			continue
30		}
31		info, err := dir.Info()
32		if err != nil {
33			return nil, err
34		}
35		infos = append(infos, info)
36	}
37
38	return infos, nil
39}
40
41func (self *FileSystemRepository) List(filepath string) ([]fs.FileInfo, error) {
42	workingPath := path.Join(self.root, filepath)
43	return self.getFilesFromPath(workingPath)
44}
45
46func (self *FileSystemRepository) Stat(filepath string) (fs.FileInfo, error) {
47	workingPath := path.Join(self.root, filepath)
48	return os.Stat(workingPath)
49}