updated path handling
This commit is contained in:
parent
470df78264
commit
2195920b38
@ -1,6 +1,7 @@
|
|||||||
package localFileStructure
|
package localFileStructure
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@ -8,21 +9,26 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func ScanLocalFileStructure(path string) (map[string]*FilesystemNode, error) {
|
func ScanLocalFileStructure(path string) (map[string]*FilesystemNode, error) {
|
||||||
|
fullPathRoot, err := filepath.Abs(path)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
logrus.Infof("Scanning %s for images...", fullPathRoot)
|
||||||
|
|
||||||
fileMap := make(map[string]*FilesystemNode)
|
fileMap := make(map[string]*FilesystemNode)
|
||||||
|
fullPathReplace := fmt.Sprintf("%s%c",fullPathRoot, os.PathSeparator)
|
||||||
relativeRoot := filepath.Base(path) + "/"
|
|
||||||
|
|
||||||
numberOfDirectories := 0
|
numberOfDirectories := 0
|
||||||
numberOfImages := 0
|
numberOfImages := 0
|
||||||
|
|
||||||
err := filepath.Walk(path, func(p string, info os.FileInfo, err error) error {
|
err = filepath.Walk(fullPathRoot, func(p string, info os.FileInfo, err error) error {
|
||||||
if path == p {
|
if fullPathRoot == p {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: Only allow jpg and png files here
|
//TODO: Only allow jpg and png files here
|
||||||
|
|
||||||
key := strings.Replace(p, relativeRoot, "", 1)
|
key := strings.Replace(p, fullPathReplace, "", 1)
|
||||||
|
|
||||||
fileMap[p] = &FilesystemNode{
|
fileMap[p] = &FilesystemNode{
|
||||||
Key: key,
|
Key: key,
|
||||||
|
Loading…
Reference in New Issue
Block a user