From affc5a5bf93a3dcc005dab0d7e8d36681f4bfc75 Mon Sep 17 00:00:00 2001 From: Zachary Scott Date: Fri, 15 Jun 2018 21:59:15 +0900 Subject: [PATCH] **WIP**: Try merging child into the parent if it has no siblings This doesn't work yet, but this should be the right place for that work. --- filetree/filetree.go | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/filetree/filetree.go b/filetree/filetree.go index 399da9517..4d27e91b8 100644 --- a/filetree/filetree.go +++ b/filetree/filetree.go @@ -1,6 +1,7 @@ package filetree import ( + "encoding/json" "fmt" "io/ioutil" "os" @@ -32,12 +33,30 @@ func (n Node) marshalParent() (interface{}, error) { if err != nil { return tree, err } - tree[child.Info.Name()] = c + + if len(child.siblings()) > 0 { + result := make(map[string]interface{}) + merge, _ := json.Marshal(c) + json.Unmarshal(merge, &result) + tree[child.Parent.Info.Name()] = result + } else { + tree[child.Info.Name()] = c + } } return tree, nil } +func (n Node) siblings() []*Node { + siblings := []*Node{} + for _, child := range n.Parent.Children { + if child != &n { + siblings = append(siblings, child) + } + } + return siblings +} + func (n Node) marshalLeaf() (interface{}, error) { var content interface{} if n.Info.IsDir() {