in curator-client/src/main/java/org/apache/curator/utils/ZKPaths.java [283:338]
public static void mkdirs(
ZooKeeper zookeeper,
final String path,
boolean makeLastNode,
InternalACLProvider aclProvider,
boolean asContainers)
throws InterruptedException, KeeperException {
PathUtils.validatePath(path);
// This first loop locates the first node that doesn't exist from leaf nodes towards root
// this way, it is not required to have read access on all parents.
// This is relevant after https://issues.apache.org/jira/browse/ZOOKEEPER-2590.
int pos = path.length();
do {
String subPath = path.substring(0, pos);
if (zookeeper.exists(subPath, false) != null) {
break;
}
pos = path.lastIndexOf(PATH_SEPARATOR_CHAR, pos - 1);
} while (pos > 0);
// Start creating the subtree after the longest path that exists, assuming root always exists.
while (pos < path.length()) {
pos = path.indexOf(PATH_SEPARATOR_CHAR, pos + 1);
if (pos == -1) {
if (makeLastNode) {
pos = path.length();
} else {
break;
}
}
String subPath = path.substring(0, pos);
// All the paths from the initial `pos` do not exist.
try {
List<ACL> acl = null;
if (aclProvider != null) {
acl = aclProvider.getAclForPath(subPath);
if (acl == null) {
acl = aclProvider.getDefaultAcl();
}
}
if (acl == null) {
acl = ZooDefs.Ids.OPEN_ACL_UNSAFE;
}
zookeeper.create(subPath, new byte[0], acl, getCreateMode(asContainers));
} catch (KeeperException.NodeExistsException ignore) {
// ignore... someone else has created it since we checked
}
}
;
}