2020-05-06 15:53:47 +02:00
|
|
|
package fs
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
"sort"
|
|
|
|
"strings"
|
|
|
|
"sync"
|
|
|
|
|
|
|
|
"github.com/photoprism/photoprism/pkg/fastwalk"
|
|
|
|
)
|
|
|
|
|
|
|
|
func Dirs(root string, recursive bool) (result []string, err error) {
|
2020-05-14 19:03:12 +02:00
|
|
|
result = []string{}
|
2020-05-06 15:53:47 +02:00
|
|
|
ignore := NewIgnoreList(".ppignore", true, false)
|
|
|
|
mutex := sync.Mutex{}
|
|
|
|
|
|
|
|
err = fastwalk.Walk(root, func(fileName string, info os.FileMode) error {
|
|
|
|
if info.IsDir() {
|
|
|
|
if ignore.Ignore(fileName) {
|
|
|
|
return filepath.SkipDir
|
|
|
|
}
|
|
|
|
|
|
|
|
if fileName != root {
|
|
|
|
mutex.Lock()
|
|
|
|
fileName = strings.Replace(fileName, root, "", 1)
|
|
|
|
result = append(result, fileName)
|
|
|
|
mutex.Unlock()
|
|
|
|
|
|
|
|
if !recursive {
|
|
|
|
return filepath.SkipDir
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
|
|
|
|
sort.Strings(result)
|
|
|
|
|
|
|
|
return result, err
|
|
|
|
}
|