Skip to content

Commit

Permalink
Fix path create in absence of acl for base prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
secwall committed Sep 20, 2024
1 parent 3050bab commit 4e7c8f2
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion internal/dcs/zk.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"net"
"os"
"slices"
"strings"
"sync"
"time"
Expand Down Expand Up @@ -157,12 +158,30 @@ func (z *zkDCS) getSelfLockOwner() LockOwner {
func (z *zkDCS) makePath(path string) error {
parts := strings.Split(path, sep)
prefix := ""
var paths []string
for _, part := range parts {
if part == "" {
continue
}
prefix = JoinPath(prefix, part)
_, err := z.retryCreate(prefix, []byte{}, 0, z.acl)
paths = append(paths, prefix)
}
slices.Reverse(paths)
var createPaths []string
for _, path := range paths {
_, _, err := z.retryGet(path)
if err == nil {
break
}
if err == zk.ErrNoNode {
createPaths = append(createPaths, path)
} else {
return err
}
}
slices.Reverse(createPaths)
for _, path := range createPaths {
_, err := z.retryCreate(path, []byte{}, 0, z.acl)
if err != nil && err != zk.ErrNodeExists {
return err
}
Expand Down

0 comments on commit 4e7c8f2

Please sign in to comment.