Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

SOLR-17654: Fix DistribFileStore._getRealPath() for Windows (#3160)

Matthew Biscochod0ec48f1c5aa
diff --git a/solr/core/src/java/org/apache/solr/filestore/DistribFileStore.java b/solr/core/src/java/org/apache/solr/filestore/DistribFileStore.java
index c1b48fadf88..00e71968250 100644
--- a/solr/core/src/java/org/apache/solr/filestore/DistribFileStore.java
+++ b/solr/core/src/java/org/apache/solr/filestore/DistribFileStore.java
@@ -30,6 +30,7 @@ import java.io.InputStream;
import java.lang.invoke.MethodHandles;
import java.nio.ByteBuffer;
import java.nio.channels.SeekableByteChannel;
+import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
@@ -88,13 +89,13 @@ public class DistribFileStore implements FileStore {
return _getRealPath(path, solrHome);
}
- private static Path _getRealPath(String dir, Path solrHome) {
- Path path = Path.of(dir);
- SolrPaths.assertNotUnc(path);
-
- if (path.isAbsolute()) {
- // Strip the path of from being absolute to become relative to resolve with SolrHome
- path = path.subpath(0, path.getNameCount());
+ private static Path _getRealPath(String path, Path solrHome) {
+ if (FileSystems.getDefault().getSeparator().equals("\\")) {
+ path = path.replace("/", FileSystems.getDefault().getSeparator());
+ }
+ SolrPaths.assertNotUnc(Path.of(path));
+ while (path.startsWith(FileSystems.getDefault().getSeparator())) { // Trim all leading slashes
+ path = path.substring(1);
}
var finalPath = getFileStoreDirPath(solrHome).resolve(path);