From e67ec6c40ab2884e7a18d6936961f4e9da1fd4cc Mon Sep 17 00:00:00 2001 From: secwall Date: Fri, 20 Sep 2024 13:03:00 +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 786deb0..0e9cea6 100644 --- a/internal/dcs/zk.go +++ b/internal/dcs/zk.go @@ -7,6 +7,7 @@ import ( "log/slog" "net" "os" + "slices" "strings" "sync" "time" @@ -159,12 +160,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 }