Skip to content
This repository has been archived by the owner on Jul 21, 2021. It is now read-only.

If there is no parent node, the node is created level by level #251

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions zk/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"errors"
"fmt"
"io"
"log"
"net"
"strconv"
"strings"
Expand Down Expand Up @@ -1121,6 +1122,39 @@ func (c *Conn) CreateProtectedEphemeralSequential(path string, data []byte, acl
return "", err
}

//If there is no parent node, the node is created level by level
func (c *Conn) CreatingParentsIfNeededWithDefaultACL(path string, data []byte, flags int32) (string, error) {
return c.CreatingParentsIfNeededWithCustomizeACL(path, data, flags, WorldACL(PermAll))
}

func (c *Conn) CreatingParentsIfNeededWithCustomizeACL(path string, data []byte, flags int32, acl []ACL) (string, error) {
var zkPath string

if path == "" {
return zkPath, ErrInvalidPath
}

paths := strings.Split(path, "/")

size := len(paths)

for index, node := range paths {
log.Println("size: ", size, ", index: ", index, ", node: ", node)
if node == "" {
continue
}
zkPath = zkPath + "/" + node
if index < size-1 {
zkPath, _ := c.Create(zkPath, []byte(""), FlagPersistence, acl)
log.Println("index = ", index, "zkPath = ", zkPath)
} else {
zkPath, _ = c.Create(zkPath, data, flags, acl)
log.Println("index = ", index, "zkPath = ", zkPath)
}
}
return zkPath, nil
}

func (c *Conn) Delete(path string, version int32) error {
if err := validatePath(path, false); err != nil {
return err
Expand Down
5 changes: 3 additions & 2 deletions zk/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,9 @@ const (
)

const (
FlagEphemeral = 1
FlagSequence = 2
FlagPersistence = 0
FlagEphemeral = 1
FlagSequence = 2
)

var (
Expand Down