private static DirId getDirId(final Path path, final Mode mode, final AtomicReference<Path> incompletePath) {
        LOGGER.trace("getLastDirId - path: {}, mode: {}", path, mode);

        LOGGER.trace("Checking depthPath: '{}'", path);
        final Predicate<Path> pathPredicate = DirUtil::isValidLeafOrBranchPath;
        final List<DirId> dirs = findDirs(path, mode, pathPredicate);
        LOGGER.trace(() -> LogUtil.message("Found {} dirs in {}", dirs.size(), path));
        DirId dirId = null;
        if (!dirs.isEmpty()) {
            for (final DirId aDirId : dirs) {
                if (isValidLeafPath(aDirId.dir)) {
                    // Found what we are looking for so break out
                    dirId = aDirId;
                } else {
                    // Is a branch so recurse in
                    dirId = getDirId(aDirId.dir, mode, incompletePath);
                }
                if (dirId != null) {
                    break;
                }
            }
        }
        if (dirId == null && isValidLeafOrBranchPath(path)) {
            // No leaf or child branch found so this path is incomplete
            // Just record the first case we find
            incompletePath.compareAndSet(null, path);
        }

        LOGGER.trace("getDirId - returning dirId {}", dirId);
        return dirId;
    }
Get the ID for the dir matching mode in the root directory, i.e. the directory
that contains the depth paths.
stroom-state/stroom-planb-impl/src/main/java/stroom/planb/impl/data/DirUtil.java