diff --git a/docs/INSTALL.md b/docs/INSTALL.md index 7a49e8ea..254f5685 100644 --- a/docs/INSTALL.md +++ b/docs/INSTALL.md @@ -42,7 +42,7 @@ curl -LO https://github.com/haveachin/infrared/releases/download/{version}/infra Downloading by using Powershell on Windows: ```Powershell -Invoke-WebRequest -Uri https://github.com/haveachin/infrared/releases/download/v1.3.4/infrared_Windows_x86_64.zip -OutFile c:\temp\infrared.zip +Invoke-WebRequest -Uri https://github.com/haveachin/infrared/releases/download/v1.3.4/infrared_Windows_x86_64.zip -OutFile c:\infrared.zip ``` ### Extracting the binary @@ -52,7 +52,7 @@ Extracting by using the terminal on macOS or GNU/Linux: tar -xzf infrared_{architecture}.tar.gz ``` -Downloading by using Powershell on Windows: +Extracting by using Powershell on Windows: ```Powershell Expand-Archive c:\infrared.zip -DestinationPath c:\ ``` \ No newline at end of file diff --git a/internal/pkg/config/provider/file.go b/internal/pkg/config/provider/file.go index 5e9b758c..4c364e47 100644 --- a/internal/pkg/config/provider/file.go +++ b/internal/pkg/config/provider/file.go @@ -170,15 +170,43 @@ func (p file) readConfigData() (Data, error) { } func readConfigsFromDir(dir string, v any) error { - readConfig := func(path string, info fs.FileInfo, err error) error { + fi, err := os.Lstat(dir) + if err != nil { + return err + } + + if fi.Mode()&os.ModeSymlink == os.ModeSymlink { + dir, err = os.Readlink(dir) if err != nil { return err } + } - if info.IsDir() { + readConfig := func(path string, d fs.DirEntry, err error) error { + if err != nil { + return err + } + + if d.IsDir() { return nil } + if d.Type()&os.ModeSymlink == os.ModeSymlink { + path, err := filepath.EvalSymlinks(path) + if err != nil { + return err + } + + fi, err := os.Lstat(path) + if err != nil { + return err + } + + if fi.IsDir() { + return nil + } + } + cfgData := map[string]any{} if err := ReadConfigFile(path, &cfgData); err != nil { return fmt.Errorf("could not read %s; %v", path, err) @@ -187,16 +215,33 @@ func readConfigsFromDir(dir string, v any) error { return mergo.Merge(v, cfgData, mergo.WithOverride) } - return filepath.Walk(dir, readConfig) + return filepath.WalkDir(dir, readConfig) } -func ReadConfigFile(filename string, v any) error { - bb, err := os.ReadFile(filename) +func ReadConfigFile(name string, v any) error { + name, err := filepath.EvalSymlinks(name) + if err != nil { + return err + } + + fi, err := os.Lstat(name) + if err != nil { + return err + } + + if fi.Mode()&os.ModeSymlink == os.ModeSymlink { + name, err = os.Readlink(name) + if err != nil { + return err + } + } + + bb, err := os.ReadFile(name) if err != nil { return err } - ext := filepath.Ext(filename)[1:] + ext := filepath.Ext(name)[1:] switch ext { case "json": if err := json.Unmarshal(bb, v); err != nil {