Skip to content

Commit

Permalink
**WIP**: Try merging child into the parent if it has no siblings
Browse files Browse the repository at this point in the history
This doesn't work yet, but this should be the right place for that work.
  • Loading branch information
Zachary Scott committed Jun 15, 2018
1 parent ce436f8 commit affc5a5
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion filetree/filetree.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package filetree

import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit affc5a5

Please sign in to comment.