diff --git a/os/gcfg/gcfg_adapter_file.go b/os/gcfg/gcfg_adapter_file.go index 2c7dbe50d..fa546cf64 100644 --- a/os/gcfg/gcfg_adapter_file.go +++ b/os/gcfg/gcfg_adapter_file.go @@ -40,11 +40,15 @@ var ( supportedFileTypes = []string{"toml", "yaml", "yml", "json", "ini", "xml"} // All supported file types suffixes. localInstances = gmap.NewStrAnyMap(true) // Instances map containing configuration instances. customConfigContentMap = gmap.NewStrStrMap(true) // Customized configuration content. + // Prefix array for trying searching in resource manager. resourceTryFiles = []string{ "", "/", "config/", "config", "/config", "/config/", "manifest/config/", "manifest/config", "/manifest/config", "/manifest/config/", } + + // Prefix array for trying searching in local system. + localSystemTryFiles = []string{"", "config/", "manifest/config"} ) // NewAdapterFile returns a new configuration management object. diff --git a/os/gcfg/gcfg_adapter_file_path.go b/os/gcfg/gcfg_adapter_file_path.go index c826ed13c..a21f79ced 100644 --- a/os/gcfg/gcfg_adapter_file_path.go +++ b/os/gcfg/gcfg_adapter_file_path.go @@ -168,15 +168,18 @@ func (c *AdapterFile) GetFilePath(fileName ...string) (path string, err error) { }) } c.autoCheckAndAddMainPkgPathToSearchPaths() - // Searching the file system. + // Searching local file system. c.searchPaths.RLockFunc(func(array []string) { for _, prefix := range array { prefix = gstr.TrimRight(prefix, `\/`) - if path, _ = gspath.Search(prefix, usedFileName); path != "" { - return - } - if path, _ = gspath.Search(prefix+gfile.Separator+"config", usedFileName); path != "" { - return + for _, tryFile := range localSystemTryFiles { + relativePath := gstr.TrimRight( + gfile.Join(tryFile, usedFileName), + `\/`, + ) + if path, _ = gspath.Search(prefix, relativePath); path != "" { + return + } } } }) @@ -192,12 +195,13 @@ func (c *AdapterFile) GetFilePath(fileName ...string) (path string, err error) { )) c.searchPaths.RLockFunc(func(array []string) { index := 1 - for _, v := range array { - v = gstr.TrimRight(v, `\/`) - buffer.WriteString(fmt.Sprintf("\n%d. %s", index, v)) - index++ - buffer.WriteString(fmt.Sprintf("\n%d. %s", index, v+gfile.Separator+"config")) - index++ + for _, prefix := range array { + prefix = gstr.TrimRight(prefix, `\/`) + for _, tryFile := range localSystemTryFiles { + prefixPath := gfile.Join(prefix, tryFile) + buffer.WriteString(fmt.Sprintf("\n%d. %s", index, prefixPath)) + index++ + } } }) } else { diff --git a/os/gspath/gspath.go b/os/gspath/gspath.go index e0a986cfc..f036b75d3 100644 --- a/os/gspath/gspath.go +++ b/os/gspath/gspath.go @@ -205,7 +205,7 @@ func (sp *SPath) Search(name string, indexFiles ...string) (filePath string, isD name = "" } for _, file := range indexFiles { - if v := sp.cache.Get(name + "/" + file); v != "" { + if v = sp.cache.Get(name + "/" + file); v != "" { return sp.parseCacheValue(v) } }