mirror of
https://github.com/spf13/viper
synced 2025-05-06 20:27:17 +00:00
Only try to read configuration from regular files
Before this commit, if the configuration is called "foo" and "foo" is a directory, then Viper will return an error trying to read the directory "foo" as a file and never try "foo.json", "foo.toml", etc. With this commit, Viper will only try to read configuration from regular files. Non-regular files (e.g. directories, device nodes, etc.) will be ignored.
This commit is contained in:
parent
d104d259b3
commit
1591fbedbf
2 changed files with 5 additions and 5 deletions
8
util.go
8
util.go
|
@ -114,10 +114,10 @@ func absPathify(inPath string) string {
|
|||
return ""
|
||||
}
|
||||
|
||||
// Check if File / Directory Exists
|
||||
func exists(fs afero.Fs, path string) (bool, error) {
|
||||
_, err := fs.Stat(path)
|
||||
if err == nil {
|
||||
// isRegular returns true if path exists and is a regular file.
|
||||
func isRegular(fs afero.Fs, path string) (bool, error) {
|
||||
info, err := fs.Stat(path)
|
||||
if err == nil && info.Mode().IsRegular() {
|
||||
return true, nil
|
||||
}
|
||||
if os.IsNotExist(err) {
|
||||
|
|
2
viper.go
2
viper.go
|
@ -1812,7 +1812,7 @@ func (v *Viper) searchInPath(in string) (filename string) {
|
|||
jww.DEBUG.Println("Searching for config in ", in)
|
||||
for _, ext := range SupportedExts {
|
||||
jww.DEBUG.Println("Checking for", filepath.Join(in, v.configName+"."+ext))
|
||||
if b, _ := exists(v.fs, filepath.Join(in, v.configName+"."+ext)); b {
|
||||
if b, _ := isRegular(v.fs, filepath.Join(in, v.configName+"."+ext)); b {
|
||||
jww.DEBUG.Println("Found: ", filepath.Join(in, v.configName+"."+ext))
|
||||
return filepath.Join(in, v.configName+"."+ext)
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue