Skip to content

Apache Lucene open-source search software

SOLR-6158: Fix configSetBaseDir path resolution

Alan Woodward0b621ca84228
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index a359b91f76e..983661033de 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -163,6 +163,9 @@ Bug Fixes
* SOLR-6146: Incorrect configuration such as wrong chroot in zk server address can
cause CloudSolrServer to leak resources. (Jessica Cheng, Varun Thacker, shalin)
+* SOLR-6158: Relative configSetBase directories were resolved relative to the
+ container CWD, rather than solr.home. (Simon Endele, Alan Woodward)
+
Other Changes
---------------------
diff --git a/solr/core/src/java/org/apache/solr/core/ConfigSetService.java b/solr/core/src/java/org/apache/solr/core/ConfigSetService.java
index 3f21d194acc..1065a866f2f 100644
--- a/solr/core/src/java/org/apache/solr/core/ConfigSetService.java
+++ b/solr/core/src/java/org/apache/solr/core/ConfigSetService.java
@@ -113,7 +113,7 @@ public abstract class ConfigSetService {
*/
public static class Default extends ConfigSetService {
- private final String configSetBase;
+ private final File configSetBase;
/**
* Create a new ConfigSetService.Default
@@ -122,7 +122,19 @@ public abstract class ConfigSetService {
*/
public Default(SolrResourceLoader loader, String configSetBase) {
super(loader);
- this.configSetBase = configSetBase;
+ this.configSetBase = resolveBaseDirectory(loader, configSetBase);
+ }
+
+ private File resolveBaseDirectory(SolrResourceLoader loader, String configSetBase) {
+ File csBase = new File(configSetBase);
+ if (!csBase.isAbsolute())
+ csBase = new File(loader.getInstanceDir(), configSetBase);
+ return csBase;
+ }
+
+ // for testing
+ File getConfigSetBase() {
+ return this.configSetBase;
}
@Override
diff --git a/solr/core/src/test/org/apache/solr/core/TestConfigSets.java b/solr/core/src/test/org/apache/solr/core/TestConfigSets.java
index a1ab19d90b2..61baedf88ed 100644
--- a/solr/core/src/test/org/apache/solr/core/TestConfigSets.java
+++ b/solr/core/src/test/org/apache/solr/core/TestConfigSets.java
@@ -17,14 +17,7 @@ package org.apache.solr.core;
* limitations under the License.
*/
-import static org.hamcrest.CoreMatchers.notNullValue;
-import static org.hamcrest.CoreMatchers.nullValue;
-import static org.hamcrest.core.Is.is;
-import static org.junit.internal.matchers.StringContains.containsString;
-
-import java.io.File;
-import java.io.IOException;
-
+import com.carrotsearch.randomizedtesting.rules.SystemPropertiesRestoreRule;
import org.apache.commons.io.FileUtils;
import org.apache.solr.SolrTestCaseJ4;
import org.junit.Rule;
@@ -32,7 +25,13 @@ import org.junit.Test;
import org.junit.rules.RuleChain;
import org.junit.rules.TestRule;
-import com.carrotsearch.randomizedtesting.rules.SystemPropertiesRestoreRule;
+import java.io.File;
+import java.io.IOException;
+
+import static org.hamcrest.CoreMatchers.notNullValue;
+import static org.hamcrest.CoreMatchers.nullValue;
+import static org.hamcrest.core.Is.is;
+import static org.junit.internal.matchers.StringContains.containsString;
public class TestConfigSets extends SolrTestCaseJ4 {
@@ -53,6 +52,16 @@ public class TestConfigSets extends SolrTestCaseJ4 {
return container;
}
+ @Test
+ public void testDefaultConfigSetBasePathResolution() throws IOException {
+ try (SolrResourceLoader loader = new SolrResourceLoader("/path/to/solr/home")) {
+ ConfigSetService.Default relativeCSS = new ConfigSetService.Default(loader, "configsets");
+ assertThat(relativeCSS.getConfigSetBase().getAbsolutePath(), is("/path/to/solr/home/configsets"));
+ ConfigSetService.Default absoluteCSS = new ConfigSetService.Default(loader, "/path/to/configsets");
+ assertThat(absoluteCSS.getConfigSetBase().getAbsolutePath(), is("/path/to/configsets"));
+ }
+ }
+
@Test
public void testConfigSetServiceFindsConfigSets() {
CoreContainer container = null;