photoprism/pkg/fs/dirs.go
Michael Mayer 23df85375e Originals and import path auto-configuration #66
Signed-off-by: Michael Mayer <michael@liquidbytes.net>
2020-05-31 12:20:32 +02:00

127 lines
2.2 KiB
Go

package fs
import (
"os"
"path/filepath"
"sort"
"strings"
"sync"
"github.com/photoprism/photoprism/pkg/fastwalk"
)
var OriginalPaths = []string{
"/photoprism/photos/originals",
"/photoprism/originals",
"photoprism/originals",
"PhotoPrism/Originals",
"photoprism/original",
"PhotoPrism/Original",
"pictures/originals",
"Pictures/Originals",
"pictures/original",
"Pictures/Original",
"photos/originals",
"Photos/Originals",
"photos/original",
"Photos/Original",
"originals",
"Originals",
"original",
"Original",
"pictures",
"Pictures",
"photos",
"Photos",
"images",
"Images",
"bilder",
"Bilder",
"fotos",
"Fotos",
"~/photoprism/originals",
"~/PhotoPrism/Originals",
"~/photoprism/original",
"~/PhotoPrism/Original",
"~/pictures/originals",
"~/Pictures/Originals",
"~/pictures/original",
"~/Pictures/Original",
"~/photos/originals",
"~/Photos/Originals",
"~/photos/original",
"~/Photos/Original",
"~/pictures",
"~/Pictures",
"~/photos",
"~/Photos",
"~/images",
"~/Images",
"~/bilder",
"~/Bilder",
"~/fotos",
"~/Fotos",
}
var ImportPaths = []string{
"/photoprism/photos/import",
"/photoprism/import",
"photoprism/import",
"PhotoPrism/Import",
"pictures/import",
"Pictures/Import",
"photos/import",
"Photos/Import",
"import",
"Import",
"~/pictures/import",
"~/Pictures/Import",
"~/photoprism/import",
"~/PhotoPrism/Import",
"~/photos/import",
"~/Photos/Import",
"~/import",
"~/Import",
}
func Dirs(root string, recursive bool) (result []string, err error) {
result = []string{}
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
}
func FindDir(dirs []string) string {
for _, dir := range dirs {
absDir := Abs(dir)
if PathExists(absDir) {
return absDir
}
}
return ""
}