some bug fixes

This commit is contained in:
ston1th 2019-05-05 19:06:51 +02:00
commit 0e914c629e
16 changed files with 179 additions and 52 deletions

View file

@ -10,6 +10,7 @@ import (
"path/filepath"
"sort"
"strings"
"sync"
)
const (
@ -25,6 +26,10 @@ type Directory struct {
type Filesystem struct {
Base string
// protects scan
m sync.RWMutex
scan map[string]struct{}
}
func NewFilesystem(base string) (fs *Filesystem, err error) {
@ -48,7 +53,7 @@ func NewFilesystem(base string) (fs *Filesystem, err error) {
err = errors.New("base dir '" + base + "' is not a directory")
return
}
fs = &Filesystem{base}
fs = &Filesystem{Base: base, scan: make(map[string]struct{})}
return
}
@ -75,7 +80,8 @@ func (fs *Filesystem) ReadDir(path string) (d *Directory) {
continue
}
if m.IsRegular() {
d.Files = append(d.Files, core.Path{Name: n, Abs: filepath.Join(path, n)})
abs := filepath.Join(path, n)
d.Files = append(d.Files, core.Path{Name: n, Abs: abs, Scan: fs.CheckScan(abs)})
}
}
sort.Sort(d.Dirs)