2020-05-06 15:53:47 +02:00
|
|
|
package fs
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
"sort"
|
|
|
|
"strings"
|
|
|
|
"sync"
|
|
|
|
|
|
|
|
"github.com/photoprism/photoprism/pkg/fastwalk"
|
|
|
|
)
|
|
|
|
|
2020-05-31 12:20:32 +02:00
|
|
|
var OriginalPaths = []string{
|
|
|
|
"/photoprism/photos/originals",
|
2020-06-02 15:51:14 +02:00
|
|
|
"/photoprism/storage/originals",
|
2020-05-31 12:20:32 +02:00
|
|
|
"/photoprism/originals",
|
|
|
|
"photoprism/originals",
|
|
|
|
"PhotoPrism/Originals",
|
|
|
|
"photoprism/original",
|
|
|
|
"PhotoPrism/Original",
|
|
|
|
"pictures/originals",
|
|
|
|
"Pictures/Originals",
|
|
|
|
"pictures/original",
|
|
|
|
"Pictures/Original",
|
|
|
|
"photos/originals",
|
|
|
|
"Photos/Originals",
|
2020-06-02 15:51:14 +02:00
|
|
|
"storage/originals",
|
2020-05-31 12:20:32 +02:00
|
|
|
"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",
|
2020-08-18 19:09:46 +02:00
|
|
|
"/var/lib/photoprism/originals",
|
2020-05-31 12:20:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
var ImportPaths = []string{
|
|
|
|
"/photoprism/photos/import",
|
2020-06-02 15:51:14 +02:00
|
|
|
"/photoprism/storage/import",
|
2020-05-31 12:20:32 +02:00
|
|
|
"/photoprism/import",
|
|
|
|
"photoprism/import",
|
|
|
|
"PhotoPrism/Import",
|
|
|
|
"pictures/import",
|
|
|
|
"Pictures/Import",
|
|
|
|
"photos/import",
|
|
|
|
"Photos/Import",
|
2020-06-02 15:51:14 +02:00
|
|
|
"storage/import",
|
2020-05-31 12:20:32 +02:00
|
|
|
"import",
|
|
|
|
"Import",
|
|
|
|
"~/pictures/import",
|
|
|
|
"~/Pictures/Import",
|
|
|
|
"~/photoprism/import",
|
|
|
|
"~/PhotoPrism/Import",
|
|
|
|
"~/photos/import",
|
|
|
|
"~/Photos/Import",
|
|
|
|
"~/import",
|
|
|
|
"~/Import",
|
2020-08-18 19:09:46 +02:00
|
|
|
"/var/lib/photoprism/import",
|
|
|
|
}
|
|
|
|
|
|
|
|
var AssetPaths = []string{
|
|
|
|
"/photoprism/assets",
|
|
|
|
"~/.photoprism/assets",
|
|
|
|
"~/photoprism/assets",
|
|
|
|
"photoprism/assets",
|
|
|
|
"assets",
|
|
|
|
"/var/lib/photoprism/assets",
|
2020-05-31 12:20:32 +02:00
|
|
|
}
|
|
|
|
|
2020-07-16 15:43:23 +02:00
|
|
|
// Dirs returns a slice of directories in a path, optional recursively and with symlinks.
|
|
|
|
//
|
|
|
|
// Warning: Following symlinks can make the result non-deterministic and hard to test!
|
|
|
|
func Dirs(root string, recursive bool, followLinks 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{}
|
|
|
|
|
2020-07-16 15:43:23 +02:00
|
|
|
symlinks := make(map[string]bool)
|
|
|
|
symlinksMutex := sync.Mutex{}
|
|
|
|
|
|
|
|
appendResult := func(fileName string) {
|
|
|
|
fileName = strings.Replace(fileName, root, "", 1)
|
|
|
|
mutex.Lock()
|
|
|
|
defer mutex.Unlock()
|
|
|
|
result = append(result, fileName)
|
|
|
|
}
|
|
|
|
|
|
|
|
err = fastwalk.Walk(root, func(fileName string, typ os.FileMode) error {
|
|
|
|
if typ.IsDir() || typ == os.ModeSymlink && followLinks {
|
2020-05-06 15:53:47 +02:00
|
|
|
if ignore.Ignore(fileName) {
|
|
|
|
return filepath.SkipDir
|
|
|
|
}
|
|
|
|
|
|
|
|
if fileName != root {
|
|
|
|
if !recursive {
|
2020-07-16 15:43:23 +02:00
|
|
|
appendResult(fileName)
|
|
|
|
|
2020-05-06 15:53:47 +02:00
|
|
|
return filepath.SkipDir
|
2020-07-16 15:43:23 +02:00
|
|
|
} else if typ != os.ModeSymlink {
|
|
|
|
appendResult(fileName)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
} else if resolved, err := filepath.EvalSymlinks(fileName); err == nil {
|
|
|
|
symlinksMutex.Lock()
|
|
|
|
defer symlinksMutex.Unlock()
|
|
|
|
|
|
|
|
if _, ok := symlinks[resolved]; ok {
|
|
|
|
return filepath.SkipDir
|
|
|
|
} else {
|
|
|
|
symlinks[resolved] = true
|
|
|
|
appendResult(fileName)
|
|
|
|
}
|
|
|
|
|
|
|
|
return fastwalk.ErrTraverseLink
|
2020-05-06 15:53:47 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
|
|
|
|
sort.Strings(result)
|
|
|
|
|
|
|
|
return result, err
|
|
|
|
}
|
2020-05-31 12:20:32 +02:00
|
|
|
|
|
|
|
func FindDir(dirs []string) string {
|
|
|
|
for _, dir := range dirs {
|
|
|
|
absDir := Abs(dir)
|
|
|
|
if PathExists(absDir) {
|
|
|
|
return absDir
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ""
|
|
|
|
}
|