make config dir configurable

Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de>
This commit is contained in:
Jörn Friedrich Dreyer
2022-04-01 11:43:29 +00:00
parent 22dd458b37
commit 41abe71b46
+12 -3
View File
@@ -31,14 +31,23 @@ var (
func DefaultConfigSources(filename string, drivers []string) []string {
var sources []string
for i := range defaultLocations {
dirFS := os.DirFS(defaultLocations[i])
locations := []string{}
if os.Getenv("OCIS_CONFIG_DIR") != "" {
// only use the configured config dir
locations = append(locations, os.Getenv("OCIS_CONFIG_DIR"))
} else {
// merge config from all default locations
locations = append(locations, defaultLocations...)
}
for i := range locations {
dirFS := os.DirFS(locations[i])
pattern := filename + ".*"
matched, _ := fs.Glob(dirFS, pattern)
if len(matched) > 0 {
// prepend path to results
for j := 0; j < len(matched); j++ {
matched[j] = filepath.Join(defaultLocations[i], matched[j])
matched[j] = filepath.Join(locations[i], matched[j])
}
}
sources = append(sources, matched...)