Skip to content

Commit

Permalink
atg. implement DeleteNodeRecursively()
Browse files Browse the repository at this point in the history
  • Loading branch information
jaten committed Feb 5, 2016
1 parent ffebfec commit 3088683
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,29 @@ func (z *Client) DeleteNode(path string) error {
return z.Delete(path, -1)
}

// A convenience version of Delete, DeleteNodeRecursively deletes a znode
// and any of its children, using version -1 to delete any version.
// z.Cfg.Chroot will be prepended to a relative path. The call will be retried.
func (z *Client) DeleteNodeRecursively(path string) error {

// find children and delete then
chldList, _, err := z.Children(path)
switch err {
case nil:
case zk.ErrNoNode:
// no children, ignore
default:
return err
}
for _, chld := range chldList {
err = z.DeleteNodeRecursively(path + "/" + chld)
if err != nil {
return err
}
}
return z.Delete(path, -1)
}

// A convenience version of Create, CreateNode supplies
// empty data, 0 flags, and the default z.Cfg.Acl list
// to a z.Create() call.
Expand Down

0 comments on commit 3088683

Please sign in to comment.