SOLR-6179: Fix unit test breakage by using InMemory storage if config dir is not writable.

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1607128 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Timothy Potter 2014-07-01 16:06:59 +00:00
parent f512330b14
commit 5c75969c04
1 changed files with 17 additions and 1 deletions

View File

@ -117,7 +117,23 @@ public abstract class ManagedResourceStorage {
if (storageIO instanceof FileStorageIO) {
// using local fs, if storageDir is not set in the solrconfig.xml, assume the configDir for the core
if (initArgs.get(STORAGE_DIR_INIT_ARG) == null) {
initArgs.add(STORAGE_DIR_INIT_ARG, resourceLoader.getConfigDir());
File configDir = new File(resourceLoader.getConfigDir());
boolean hasAccess = false;
try {
hasAccess = configDir.isDirectory() && configDir.canWrite();
} catch (java.security.AccessControlException ace) {}
if (hasAccess) {
initArgs.add(STORAGE_DIR_INIT_ARG, configDir.getAbsolutePath());
} else {
// most likely this is because of a unit test
// that doesn't have write-access to the config dir
// while this failover approach is not ideal, it's better
// than causing the core to fail esp. if managed resources aren't being used
log.warn("Cannot write to config directory "+configDir.getAbsolutePath()+
"; switching to use InMemory storage instead.");
storageIO = new ManagedResourceStorage.InMemoryStorageIO();
}
}
}