static Path addDirectoryToPath(final Path parent, final Path subDirectory)
            throws IOException {
        Objects.requireNonNull(parent);
        Objects.requireNonNull(subDirectory);

        final Path realPath;
        try {
            realPath = parent.toRealPath();
        } catch (IOException e) {
            throw new IOException("Parent directory '" + parent + "' does not exist");
        }

        final Path subDirPath = realPath.resolve(subDirectory);
        final Path canonicalSubDirPath = subDirPath.toFile().getCanonicalFile().toPath();

        if (!canonicalSubDirPath.startsWith(realPath)) {
            throw new IOException("Invalid sub directory: '" + subDirectory);
        }
        return canonicalSubDirPath;
    }
Safely adds a subdirectory to the parent path given.
Ensures that the real path to the resulting 'subdirectory' starts
with the real path 'parent'.
Note that the parent of the directory you are trying to resolve must
already exist on disk, so this isn't a general purpose function.
<p>
Package public static to allow testing.

@param parent       The path that subDirectory should be under. Assumed to
                    be safe. Must not be null. Must exist on disk.
@param subDirectory The subdirectory path that should be under path.
                    Might not be safe so must be checked.
                    Must not be null. Might not exist on disk.
@return The path on disk to the subdirectory.
stroom-gitrepo/stroom-gitrepo-impl/src/main/java/stroom/gitrepo/impl/GitRepoStorageService.java