Skip to content

Commit

Permalink
Cosmetic changes
Browse files Browse the repository at this point in the history
  • Loading branch information
aalexfvk committed Jan 11, 2024
1 parent 0df87bc commit 671b7a4
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions ch_tools/chadmin/internal/zookeeper.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,23 +171,24 @@ def _delete_nodes_transaction(zk, to_delete_in_trasaction):

def _remove_subpaths(paths):
"""
Removing from the list paths that are subpath of antoher.
Removing from the list paths that are subpath of another.
Example:
[/a, /a/b/c<-remove it]
"""
if not paths:
return
# Sorting the list in the lexicographic order
paths.sort()
paths = [path.split("/") for path in paths]
normalized = [paths[0]]
# If path[i] have subnode path[j] then all paths from i to j will be subnode of i.
normalized_paths = [paths[0]]
# If path[i] has subnode path[j] then all paths from i to j will be subnode of i.
for path in paths:
if (
len(normalized[-1]) > len(path)
or path[: len(normalized[-1])] != normalized[-1]
):
normalized.append(path)
return ["/".join(normalized_list) for normalized_list in normalized]
last = normalized_paths[-1]
# Ignore the path if the last normalized one is its prefix
if len(last) > len(path) or path[: len(last)] != last:
normalized_paths.append(path)
return ["/".join(path) for path in normalized_paths]


def _delete_recursive(zk, paths):
Expand Down

0 comments on commit 671b7a4

Please sign in to comment.