for (int step = 0, size = components.size(); step < size; step++) {
GridUuid fileId = ids.get(step + 1); // Skip the first ROOT element.
if (fileId == null) {
GridGgfsFileInfo fileInfo = new GridGgfsFileInfo(true, props); // Create new directory.
String fileName = components.get(step); // Get current component name.
curPath = new GridGgfsPath(curPath, fileName);
try {
// Fails only if parent is not a directory or if modified concurrently.
GridUuid oldId = meta.putIfAbsent(parentId, fileName, fileInfo);
fileId = oldId == null ? fileInfo.id() : oldId; // Update node ID.
if (oldId == null && evts.isRecordable(EVT_GGFS_DIR_CREATED))
evts.record(new GridGgfsEvent(curPath, localNode(), EVT_GGFS_DIR_CREATED));
}
catch (GridException e) {
if (log.isDebugEnabled())
log.debug("Failed to create directory [path=" + path + ", parentId=" + parentId +
", fileName=" + fileName + ", step=" + step + ", e=" + e.getMessage() + ']');
// Check directory with such name already exists.
GridGgfsFileInfo stored = meta.info(meta.fileId(parentId, fileName));
if (stored == null)
throw new GridGgfsException(e);
if (!stored.isDirectory())
throw new GridGgfsParentNotDirectoryException("Failed to create directory (parent " +
"element is not a directory)");
fileId = stored.id(); // Update node ID.
}
}
assert fileId != null;