mirror of
https://github.com/42wim/matterbridge.git
synced 2024-12-11 19:52:04 -08:00
6aa05b3981
Bumps [github.com/spf13/viper](https://github.com/spf13/viper) from 1.9.0 to 1.10.1. - [Release notes](https://github.com/spf13/viper/releases) - [Commits](https://github.com/spf13/viper/compare/v1.9.0...v1.10.1) --- updated-dependencies: - dependency-name: github.com/spf13/viper dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
66 lines
1.0 KiB
Go
66 lines
1.0 KiB
Go
//go:build go1.16 && finder
|
|
// +build go1.16,finder
|
|
|
|
package viper
|
|
|
|
import (
|
|
"errors"
|
|
"io/fs"
|
|
"path"
|
|
)
|
|
|
|
type finder struct {
|
|
paths []string
|
|
fileNames []string
|
|
extensions []string
|
|
|
|
withoutExtension bool
|
|
}
|
|
|
|
func (f finder) Find(fsys fs.FS) (string, error) {
|
|
for _, searchPath := range f.paths {
|
|
for _, fileName := range f.fileNames {
|
|
for _, extension := range f.extensions {
|
|
filePath := path.Join(searchPath, fileName+"."+extension)
|
|
|
|
ok, err := fileExists(fsys, filePath)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
if ok {
|
|
return filePath, nil
|
|
}
|
|
}
|
|
|
|
if f.withoutExtension {
|
|
filePath := path.Join(searchPath, fileName)
|
|
|
|
ok, err := fileExists(fsys, filePath)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
if ok {
|
|
return filePath, nil
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return "", nil
|
|
}
|
|
|
|
func fileExists(fsys fs.FS, filePath string) (bool, error) {
|
|
fileInfo, err := fs.Stat(fsys, filePath)
|
|
if err == nil {
|
|
return !fileInfo.IsDir(), nil
|
|
}
|
|
|
|
if errors.Is(err, fs.ErrNotExist) {
|
|
return false, nil
|
|
}
|
|
|
|
return false, err
|
|
}
|