From 4e7c8f22a67159071a103188f0cb08e324c7921e Mon Sep 17 00:00:00 2001 From: secwall Date: Fri, 20 Sep 2024 13:14:05 +0200 Subject: [PATCH] Fix path create in absence of acl for base prefix --- internal/dcs/zk.go | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/internal/dcs/zk.go b/internal/dcs/zk.go index dad96014..3fa35506 100644 --- a/internal/dcs/zk.go +++ b/internal/dcs/zk.go @@ -6,6 +6,7 @@ import ( "fmt" "net" "os" + "slices" "strings" "sync" "time" @@ -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 }