mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-13 01:50:55 +00:00
List and set setters in folders recursively
This commit is contained in:
35
kyaml/pathutil/pathutil.go
Normal file
35
kyaml/pathutil/pathutil.go
Normal file
@@ -0,0 +1,35 @@
|
||||
// Copyright 2019 The Kubernetes Authors.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package pathutil
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"sigs.k8s.io/kustomize/kyaml/errors"
|
||||
)
|
||||
|
||||
// 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) {
|
||||
var res []string
|
||||
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)
|
||||
}
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return res, errors.Wrap(err)
|
||||
}
|
||||
return res, nil
|
||||
}
|
||||
Reference in New Issue
Block a user