remove tree.cached...root as it wasnt used in server notable
parent
b076b6a9cf
commit
76d67cff7a
|
|
@ -2,7 +2,6 @@ package main
|
|||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"path"
|
||||
|
||||
|
|
@ -54,8 +53,6 @@ func (base Leaf) Merge(updated Leaf) Leaf {
|
|||
|
||||
type Tree struct {
|
||||
root string
|
||||
cachedRoot Branch
|
||||
cachedMetaRoot Branch
|
||||
}
|
||||
|
||||
func NewTree(root string) Tree {
|
||||
|
|
@ -64,30 +61,16 @@ func NewTree(root string) Tree {
|
|||
|
||||
func (tree Tree) WithRoot(root string) Tree {
|
||||
tree.root = root
|
||||
tree.cachedRoot = Branch{}
|
||||
tree.cachedMetaRoot = Branch{}
|
||||
return tree
|
||||
}
|
||||
|
||||
func (tree Tree) GetRootMeta() (Branch, error) {
|
||||
if !tree.cachedMetaRoot.IsZero() {
|
||||
return tree.cachedMetaRoot, nil
|
||||
}
|
||||
got, err := tree.getRoot(NewID(""), false, false)
|
||||
if err == nil {
|
||||
tree.cachedMetaRoot = got
|
||||
}
|
||||
return got, err
|
||||
}
|
||||
|
||||
func (tree Tree) GetRoot() (Branch, error) {
|
||||
if !tree.cachedRoot.IsZero() {
|
||||
return tree.cachedRoot, nil
|
||||
}
|
||||
got, err := tree.getRoot(NewID(""), true, false)
|
||||
if err == nil {
|
||||
tree.cachedRoot = got
|
||||
}
|
||||
return got, err
|
||||
}
|
||||
|
||||
|
|
@ -102,7 +85,6 @@ func (tree Tree) getRoot(pid ID, withContent, withDeleted bool) (Branch, error)
|
|||
}
|
||||
for _, entry := range entries {
|
||||
if entry.Name() == "data.yaml" {
|
||||
log.Printf("reading %s", tree.root)
|
||||
if b, err := peekLeaf(withContent, path.Join(tree.root, entry.Name())); err != nil {
|
||||
return Branch{}, err
|
||||
} else if err := yaml.Unmarshal(b, &m.Leaf); err != nil {
|
||||
|
|
@ -127,9 +109,6 @@ func (tree Tree) getRoot(pid ID, withContent, withDeleted bool) (Branch, error)
|
|||
}
|
||||
|
||||
func peekLeaf(all bool, path string) ([]byte, error) {
|
||||
if all {
|
||||
return ioutil.ReadFile(path)
|
||||
}
|
||||
return ioutil.ReadFile(path)
|
||||
}
|
||||
|
||||
|
|
@ -162,8 +141,6 @@ func (tree Tree) Put(id ID, input Leaf) error {
|
|||
if err := ensureAndWrite(tree.toData(id), b); err != nil {
|
||||
return err
|
||||
}
|
||||
tree.cachedRoot = Branch{}
|
||||
tree.cachedMetaRoot = Branch{}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
@ -184,8 +161,6 @@ func (tree Tree) Del(id ID) error {
|
|||
|
||||
func (tree Tree) HardDel(id ID) error {
|
||||
os.RemoveAll(tree.toDir(id))
|
||||
tree.cachedRoot = Branch{}
|
||||
tree.cachedMetaRoot = Branch{}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue