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