|
|
|
|
@ -21,7 +21,7 @@ type WalkFunc func(resolvedPath string, info os.FileInfo, err error) error |
|
|
|
|
// can detect infinite loops while following sym links.
|
|
|
|
|
// 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, walkFn WalkFunc) error { |
|
|
|
|
func Walk(path string, followSymlinks bool, detectSymlinkInfiniteLoop bool, followDistFolder bool, walkFn WalkFunc) error { |
|
|
|
|
info, err := os.Lstat(path) |
|
|
|
|
if err != nil { |
|
|
|
|
return err |
|
|
|
|
@ -34,7 +34,7 @@ func Walk(path string, followSymlinks bool, detectSymlinkInfiniteLoop bool, walk |
|
|
|
|
symlinkPathsFollowed = make(map[string]bool, 8) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return walk(path, info, resolvedPath, symlinkPathsFollowed, walkFn) |
|
|
|
|
return walk(path, info, resolvedPath, symlinkPathsFollowed, followDistFolder, walkFn) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// walk walks the path. It is a helper/sibling function to Walk.
|
|
|
|
|
@ -43,7 +43,7 @@ func Walk(path string, followSymlinks bool, detectSymlinkInfiniteLoop bool, walk |
|
|
|
|
//
|
|
|
|
|
// If resolvedPath is "", then we are not following symbolic links.
|
|
|
|
|
// If symlinkPathsFollowed is not nil, then we need to detect infinite loop.
|
|
|
|
|
func walk(path string, info os.FileInfo, resolvedPath string, symlinkPathsFollowed map[string]bool, walkFn WalkFunc) error { |
|
|
|
|
func walk(path string, info os.FileInfo, resolvedPath string, symlinkPathsFollowed map[string]bool, followDistFolder bool, walkFn WalkFunc) error { |
|
|
|
|
if info == nil { |
|
|
|
|
return errors.New("walk: Nil FileInfo passed") |
|
|
|
|
} |
|
|
|
|
@ -81,7 +81,7 @@ func walk(path string, info os.FileInfo, resolvedPath string, symlinkPathsFollow |
|
|
|
|
if err != nil { |
|
|
|
|
return err |
|
|
|
|
} |
|
|
|
|
return walk(path, info2, path2, symlinkPathsFollowed, walkFn) |
|
|
|
|
return walk(path, info2, path2, symlinkPathsFollowed, followDistFolder, walkFn) |
|
|
|
|
} else if info.IsDir() { |
|
|
|
|
list, err := os.ReadDir(path) |
|
|
|
|
if err != nil { |
|
|
|
|
@ -102,12 +102,13 @@ func walk(path string, info os.FileInfo, resolvedPath string, symlinkPathsFollow |
|
|
|
|
subFiles = append(subFiles, subFile{path: path2, resolvedPath: resolvedPath2, fileInfo: fileInfo}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if containsDistFolder(subFiles) { |
|
|
|
|
if containsDistFolder(subFiles) && followDistFolder { |
|
|
|
|
err := walk( |
|
|
|
|
filepath.Join(path, "dist"), |
|
|
|
|
info, |
|
|
|
|
filepath.Join(resolvedPath, "dist"), |
|
|
|
|
symlinkPathsFollowed, |
|
|
|
|
followDistFolder, |
|
|
|
|
walkFn) |
|
|
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
@ -115,7 +116,7 @@ func walk(path string, info os.FileInfo, resolvedPath string, symlinkPathsFollow |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
for _, p := range subFiles { |
|
|
|
|
err = walk(p.path, p.fileInfo, p.resolvedPath, symlinkPathsFollowed, walkFn) |
|
|
|
|
err = walk(p.path, p.fileInfo, p.resolvedPath, symlinkPathsFollowed, followDistFolder, walkFn) |
|
|
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
return err |
|
|
|
|
|