Skip to content

Commit

Permalink
Merge remote-tracking branch 'github/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
thmull committed Aug 29, 2023
2 parents 98203ce + 72ae49c commit ddb388d
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions helpers/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package helpers

import (
"fmt"
"github.com/kiprotect/go-helpers/settings"
"github.com/kiprotect/kodex"
"io/fs"
Expand All @@ -34,6 +35,9 @@ func SettingsPaths() ([]string, fs.FS, error) {
}
values := strings.Split(envValue, ":")
sanitizedValues := make([]string, 0, len(values))

mainRoot := ""

for _, value := range values {
if value == "" {
continue
Expand All @@ -42,10 +46,28 @@ func SettingsPaths() ([]string, fs.FS, error) {
if value, err = filepath.Abs(value); err != nil {
return nil, nil, err
}
value = value[1:]

root := filepath.VolumeName(value)

if mainRoot != "" && root != mainRoot {
return nil, nil, fmt.Errorf("cannot load settings from multiple volumes on Windows, sorry...")
}

// we set the main root from the path root
mainRoot = root + "/"

value = filepath.ToSlash(value)

value = value[len(root)+1:]
sanitizedValues = append(sanitizedValues, value)
}
return sanitizedValues, os.DirFS("/"), nil

// on Linux, mainRoot will be unset
if mainRoot == "" {
mainRoot = "/"
}

return sanitizedValues, os.DirFS(mainRoot), nil
}

func Settings(settingsPaths []string, fS fs.FS) (kodex.Settings, error) {
Expand Down

0 comments on commit ddb388d

Please sign in to comment.