Skip to content

Commit

Permalink
Merge pull request #44 from b4b4r07/fix/43
Browse files Browse the repository at this point in the history
Improve resolveSymlink function
  • Loading branch information
b4b4r07 authored May 4, 2022
2 parents 054f74c + d95f5c0 commit 4b34e4c
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,29 +108,33 @@ func visitYAML(files *[]string) filepath.WalkFunc {
}
}

func resolveSymlink(path string) (string, error) {
func resolvePath(path string) (string, bool, error) {
fi, err := os.Lstat(path)
if err != nil {
return path, err
return path, false, err
}

isDir := fi.IsDir()

if filepath.IsAbs(path) {
return path, isDir, nil
}

if fi.Mode()&os.ModeSymlink == os.ModeSymlink {
return os.Readlink(path)
path, err = os.Readlink(path)
}
return path, nil

return path, isDir, err
}

// WalkDir walks given directory path and returns full-path of all yaml files
func WalkDir(path string) ([]string, error) {
var files []string
path, err := resolveSymlink(path)
if err != nil {
return files, err
}
fi, err := os.Stat(path)
path, isDir, err := resolvePath(path)
if err != nil {
return files, err
}
if fi.IsDir() {
if isDir {
return files, filepath.Walk(path, visitYAML(&files))
}
switch filepath.Ext(path) {
Expand Down

0 comments on commit 4b34e4c

Please sign in to comment.