mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Plugins: Fix loading of dist folders (#80015)
* end to end * tidy * fix whitespace * remove unused code * fix linter * fix gosec + add sort * fix test * apply cr feedback
This commit is contained in:
@@ -27,7 +27,7 @@ func newWalker(rootDir string) *walker {
|
||||
// it calls the walkFn passed.
|
||||
//
|
||||
// It is similar to filepath.Walk, except that it supports symbolic links and
|
||||
// can detect infinite loops while following sym links.
|
||||
// can detect infinite loops while following symlinks.
|
||||
// It solves the issue where your WalkFunc needs a path relative to the symbolic link
|
||||
// (resolving links within walkfunc loses the path to the symbolic link for each traversal).
|
||||
func Walk(path string, followSymlinks bool, detectSymlinkInfiniteLoop bool, followDistFolder bool, walkFn WalkFunc) error {
|
||||
@@ -112,20 +112,22 @@ func (w *walker) walk(path string, info os.FileInfo, resolvedPath string, symlin
|
||||
subFiles = append(subFiles, subFile{path: path2, resolvedPath: resolvedPath2, fileInfo: fileInfo})
|
||||
}
|
||||
|
||||
// If we have found a dist directory in a subdirectory (IE not at root path), and followDistFolder is true,
|
||||
// then we want to follow only the dist directory and ignore all other subdirectories.
|
||||
atRootDir := w.rootDir == path
|
||||
if followDistFolder && w.containsDistFolder(subFiles) && !atRootDir {
|
||||
return w.walk(filepath.Join(path, "dist"), info, filepath.Join(resolvedPath, "dist"), symlinkPathsFollowed,
|
||||
followDistFolder, walkFn)
|
||||
if followDistFolder && w.containsDistFolder(subFiles) {
|
||||
err := w.walk(
|
||||
filepath.Join(path, "dist"),
|
||||
info,
|
||||
filepath.Join(resolvedPath, "dist"),
|
||||
symlinkPathsFollowed,
|
||||
followDistFolder,
|
||||
walkFn)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
// Follow all subdirectories, with special handling for dist directories.
|
||||
for _, p := range subFiles {
|
||||
// We only want to skip a dist directory if it is not in the root directory, and followDistFolder is false.
|
||||
if p.isDistDir() && !atRootDir && !followDistFolder {
|
||||
if p.isDistDir() && !followDistFolder {
|
||||
continue
|
||||
}
|
||||
|
||||
err = w.walk(p.path, p.fileInfo, p.resolvedPath, symlinkPathsFollowed, followDistFolder, walkFn)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user