tree.get does not include deleted branches
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user