Fix: fix loading symbolically linked plugins (#35635) (#35693)

(cherry picked from commit 5b5cb94809)

Co-authored-by: Domas <domas.lapinskas@grafana.com>
This commit is contained in:
Grot (@grafanabot)
2021-06-15 13:24:53 +03:00
committed by GitHub
co-authored by Domas
parent 9fce4436ea
commit dd24946f0f
3 changed files with 46 additions and 20 deletions
+27 -20
View File
@@ -55,28 +55,35 @@ func walk(path string, info os.FileInfo, resolvedPath string, symlinkPathsFollow
}
return err
}
// We only want to lstat on directories. If this entry is a symbolic link to a file, no need to recurse.
if info.IsDir() {
if resolvedPath != "" && info.Mode()&os.ModeSymlink == os.ModeSymlink {
path2, err := os.Readlink(resolvedPath)
if err != nil {
return err
}
// vout("SymLink Path: %v, links to: %v", resolvedPath, path2)
if symlinkPathsFollowed != nil {
if _, ok := symlinkPathsFollowed[path2]; ok {
errMsg := "potential symLink infinite loop, path: %v, link to: %v"
return fmt.Errorf(errMsg, resolvedPath, path2)
}
symlinkPathsFollowed[path2] = true
}
info2, err := os.Lstat(path2)
if err != nil {
return err
}
return walk(path, info2, path2, symlinkPathsFollowed, walkFn)
if resolvedPath != "" && info.Mode()&os.ModeSymlink == os.ModeSymlink {
// We only want to lstat on directories. If this entry is a symbolic link to a file, no need to recurse.
statInfo, err := os.Stat(resolvedPath)
if err != nil {
return err
}
if !statInfo.IsDir() {
return nil
}
path2, err := filepath.EvalSymlinks(resolvedPath)
if err != nil {
return err
}
// vout("SymLink Path: %v, links to: %v", resolvedPath, path2)
if symlinkPathsFollowed != nil {
if _, ok := symlinkPathsFollowed[path2]; ok {
errMsg := "potential symLink infinite loop, path: %v, link to: %v"
return fmt.Errorf(errMsg, resolvedPath, path2)
}
symlinkPathsFollowed[path2] = true
}
info2, err := os.Lstat(path2)
if err != nil {
return err
}
return walk(path, info2, path2, symlinkPathsFollowed, walkFn)
} else if info.IsDir() {
list, err := ioutil.ReadDir(path)
if err != nil {
return walkFn(resolvedPath, info, err)