Folders: Show no error if fs.Dirs returns at least one result
Signed-off-by: Michael Mayer <michael@photoprism.app>
This commit is contained in:
parent
da2cb2c55f
commit
86ee51321c
|
@ -8,12 +8,18 @@ import (
|
||||||
"github.com/photoprism/photoprism/pkg/fs"
|
"github.com/photoprism/photoprism/pkg/fs"
|
||||||
)
|
)
|
||||||
|
|
||||||
// FoldersByPath returns a slice of folders in a given directory incl sub directories in recursive mode.
|
// FoldersByPath returns a slice of folders in a given directory incl sub-folders in recursive mode.
|
||||||
func FoldersByPath(rootName, rootPath, path string, recursive bool) (folders entity.Folders, err error) {
|
func FoldersByPath(rootName, rootPath, path string, recursive bool) (folders entity.Folders, err error) {
|
||||||
dirs, err := fs.Dirs(filepath.Join(rootPath, path), recursive, true)
|
dirs, err := fs.Dirs(filepath.Join(rootPath, path), recursive, true)
|
||||||
|
|
||||||
|
// Failed?
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if len(dirs) == 0 {
|
||||||
return folders, err
|
return folders, err
|
||||||
|
} else {
|
||||||
|
// At least one folder found.
|
||||||
|
log.Infof("folders: %s", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
folders = make(entity.Folders, len(dirs))
|
folders = make(entity.Folders, len(dirs))
|
||||||
|
@ -21,7 +27,7 @@ func FoldersByPath(rootName, rootPath, path string, recursive bool) (folders ent
|
||||||
for i, dir := range dirs {
|
for i, dir := range dirs {
|
||||||
newFolder := entity.NewFolder(rootName, filepath.Join(path, dir), fs.BirthTime(filepath.Join(rootPath, dir)))
|
newFolder := entity.NewFolder(rootName, filepath.Join(path, dir), fs.BirthTime(filepath.Join(rootPath, dir)))
|
||||||
|
|
||||||
if err := newFolder.Create(); err == nil {
|
if err = newFolder.Create(); err == nil {
|
||||||
folders[i] = newFolder
|
folders[i] = newFolder
|
||||||
} else if folder := entity.FindFolder(rootName, filepath.Join(path, dir)); folder != nil {
|
} else if folder := entity.FindFolder(rootName, filepath.Join(path, dir)); folder != nil {
|
||||||
folders[i] = *folder
|
folders[i] = *folder
|
||||||
|
|
Loading…
Reference in a new issue