fixed category path separator usage

This commit is contained in:
Philipp Häfelfinger 2019-02-25 23:40:26 +01:00
parent 6df316fe19
commit 1fbf889a4b

View File

@ -8,6 +8,7 @@ import (
"haefelfinger.net/piwigo/DirectoriesToAlbums/internal/pkg/piwigo" "haefelfinger.net/piwigo/DirectoriesToAlbums/internal/pkg/piwigo"
"net/http" "net/http"
"net/url" "net/url"
"os"
) )
func GetAllCategories(context *piwigo.PiwigoContext) (map[string]*PiwigoCategory, error) { func GetAllCategories(context *piwigo.PiwigoContext) (map[string]*PiwigoCategory, error) {
@ -50,7 +51,7 @@ func GetAllCategories(context *piwigo.PiwigoContext) (map[string]*PiwigoCategory
func buildLookupMap(categories map[int]*PiwigoCategory) map[string]*PiwigoCategory { func buildLookupMap(categories map[int]*PiwigoCategory) map[string]*PiwigoCategory {
categoryLookups := map[string]*PiwigoCategory{} categoryLookups := map[string]*PiwigoCategory{}
for _, category := range categories { for _, category := range categories {
logrus.Debugf("Category %s", category.Key) logrus.Debugf("Existing category %s", category.Key)
categoryLookups[category.Key] = category categoryLookups[category.Key] = category
} }
return categoryLookups return categoryLookups
@ -75,7 +76,9 @@ func buildCategoryKeys(categories map[int]*PiwigoCategory) {
parentId := category.ParentId parentId := category.ParentId
for parentId != 0 { for parentId != 0 {
parent := categories[parentId] parent := categories[parentId]
key = fmt.Sprintf("%s/%s", parent.Name, key) // as we build the category as a directory hierarchy,
// we have to use the path separator to construct the path key
key = fmt.Sprintf("%s%c%s", parent.Name, os.PathSeparator, key)
parentId = parent.ParentId parentId = parent.ParentId
} }