public static void ensureDirectoryExists ( final Path path ) throws IOException { if ( Files . exists ( path ) ) { if ( ! Files . isDirectory ( path ) ) { throw new IOException ( "path is not a directory: " + path ) ; } // probably should fsync parent here just to be sure, but that might slow stuff down } else { Files . createDirectories ( path ) ; fsyncLineage ( path . getParent ( ) ) ; } }
Create a directory if it does not already exist . Fails if the path exists and is NOT a directory . Will fsync the parent directory inode .