From 2195920b3896dc016383f8043a4672d27c4bd703 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20H=C3=A4felfinger?= Date: Mon, 25 Feb 2019 23:58:44 +0100 Subject: [PATCH] updated path handling --- .../localFileStructure/filesystemScanner.go | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/internal/pkg/localFileStructure/filesystemScanner.go b/internal/pkg/localFileStructure/filesystemScanner.go index c221af7..f08c274 100644 --- a/internal/pkg/localFileStructure/filesystemScanner.go +++ b/internal/pkg/localFileStructure/filesystemScanner.go @@ -1,6 +1,7 @@ package localFileStructure import ( + "fmt" "github.com/sirupsen/logrus" "os" "path/filepath" @@ -8,21 +9,26 @@ import ( ) 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) - - relativeRoot := filepath.Base(path) + "/" - + fullPathReplace := fmt.Sprintf("%s%c",fullPathRoot, os.PathSeparator) numberOfDirectories := 0 numberOfImages := 0 - err := filepath.Walk(path, func(p string, info os.FileInfo, err error) error { - if path == p { + err = filepath.Walk(fullPathRoot, func(p string, info os.FileInfo, err error) error { + if fullPathRoot == p { return nil } //TODO: Only allow jpg and png files here - key := strings.Replace(p, relativeRoot, "", 1) + key := strings.Replace(p, fullPathReplace, "", 1) fileMap[p] = &FilesystemNode{ Key: key,