mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-13 18:10:59 +00:00
Setters with subpackages
This commit is contained in:
@@ -6,23 +6,29 @@ package pathutil
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// SubDirsWithFile takes the root directory path and returns all the paths of
|
||||
// sub-directories which contain file with input fileName including itself
|
||||
func SubDirsWithFile(root, fileName string) ([]string, error) {
|
||||
// DirsWithFile takes the root directory path and returns all the paths of
|
||||
// sub-directories(including itself) which contain file with input fileName
|
||||
// at top level if recurse is true
|
||||
func DirsWithFile(root, fileName string, recurse bool) ([]string, error) {
|
||||
var res []string
|
||||
if !recurse {
|
||||
// check if the file with fileName is present in root and return it
|
||||
// else return empty list
|
||||
_, err := os.Stat(filepath.Join(root, fileName))
|
||||
if !os.IsNotExist(err) {
|
||||
res = append(res, root)
|
||||
}
|
||||
return res, nil
|
||||
}
|
||||
err := filepath.Walk(root,
|
||||
func(path string, info os.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if strings.HasSuffix(path, fileName) {
|
||||
if root == "." {
|
||||
path = root + "/" + path
|
||||
}
|
||||
res = append(res, path)
|
||||
if filepath.Base(path) == fileName {
|
||||
res = append(res, filepath.Dir(path))
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user