From e87bcde6944247e1990bc4bc1ed68378184e8014 Mon Sep 17 00:00:00 2001 From: Zachary Scott Date: Thu, 21 Jun 2018 17:50:17 +0900 Subject: [PATCH] Skip dotfiles when populating the tree with nodes, that aren't root This change also addresses some confusing names in the codebase --- filetree/filetree.go | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/filetree/filetree.go b/filetree/filetree.go index 874ab1827..9ee8126d9 100644 --- a/filetree/filetree.go +++ b/filetree/filetree.go @@ -59,32 +59,32 @@ func (n Node) rootFile() bool { return n.Info.Mode().IsRegular() && n.root() == n.Parent } -func (n Node) notYaml() bool { +func (n Node) isYaml() bool { re := regexp.MustCompile(`.+\.(yml|yaml)$`) - return !re.MatchString(n.FullPath) + return re.MatchString(n.FullPath) } func (n Node) marshalParent() (interface{}, error) { - tree := map[string]interface{}{} + subtree := map[string]interface{}{} for _, child := range n.Children { c, err := child.MarshalYAML() if err != nil { - return tree, err + return subtree, err } if child.rootFile() { - merged := mergeTree(tree, c) - tree = merged + merged := mergeTree(subtree, c) + subtree = merged } else if SpecialCase(child.basename()) { - merged := mergeTree(tree, tree[child.Parent.name()], c) - tree = merged + merged := mergeTree(subtree, subtree[child.Parent.name()], c) + subtree = merged } else { - merged := mergeTree(tree[child.name()], c) - tree[child.name()] = merged + merged := mergeTree(subtree[child.name()], c) + subtree[child.name()] = merged } } - return tree, nil + return subtree, nil } // Returns the root node @@ -103,7 +103,7 @@ func (n Node) marshalLeaf() (interface{}, error) { if n.Info.IsDir() { return content, nil } - if n.notYaml() { + if !n.isYaml() { return content, nil } @@ -145,7 +145,7 @@ func NewTree(root string, specialCase func(path string) bool) (*Node, error) { return err } - // Skip any dotfolders automatically + // Skip any dotfolders that aren't the root path if absroot != path && dotfolder(info) { // Turn off logging to stdout in this package //fmt.Printf("Skipping dotfolder: %+v\n", path) @@ -172,6 +172,10 @@ func NewTree(root string, specialCase func(path string) bool) (*Node, error) { for _, path := range pathKeys { node := parents[path] + // skip dotfile nodes that aren't the root path + if absroot != path && dotfile(node.Info.Name()) { + continue + } parentPath := filepath.Dir(path) parent, exists := parents[parentPath] if exists {