private static void makeSanityCheckedDirectory(File directory, String indexName, boolean verifyIsWritable) {
if ( !directory.exists() ) {
log.indexDirectoryNotFoundCreatingNewOne( directory.getAbsolutePath() );
//if not existing, create the full path
if ( !directory.mkdirs() ) {
throw new SearchException(
"Unable to create index directory: "
+ directory.getAbsolutePath() + " for index "
+ indexName
);
}
}
else {
// else check it is not a file
if ( !directory.isDirectory() ) {
throw new SearchException(
"Unable to initialize index: "
+ indexName + ": "
+ directory.getAbsolutePath() + " is a file."
);
}
}
// and ensure it's writable
if ( verifyIsWritable && ( !directory.canWrite() ) ) {
throw new SearchException(
"Cannot write into index directory: "
+ directory.getAbsolutePath() + " for index "
+ indexName
);
}