tree.get does not include deleted branches

This commit is contained in:
Bel LaPointe
2022-02-09 11:41:07 -07:00
parent 77b057147c
commit 6a6d2ba822
2 changed files with 41 additions and 2 deletions

View File

@@ -103,7 +103,7 @@ func (tree Tree) getRoot(withContent bool) (Branch, error) {
} else if entry.IsDir() {
if branch, err := tree.WithRoot(path.Join(tree.root, entry.Name())).getRoot(withContent); err != nil {
return Branch{}, err
} else {
} else if !branch.Leaf.Deleted && !branch.IsZero() {
m.Branches[entry.Name()] = branch
}
}
@@ -145,6 +145,21 @@ func (tree Tree) Put(id []string, input Leaf) error {
}
func (tree Tree) Del(id []string) error {
got, err := tree.Get(id)
if os.IsNotExist(err) {
return nil
}
if err != nil {
return err
}
if got.Deleted {
return nil
}
got.Deleted = true
return tree.Put(id, got)
}
func (tree Tree) HardDel(id []string) error {
os.RemoveAll(tree.toDir(id))
tree.cachedRoot = Branch{}
return nil