Skip to content

Commit d0ec48f

Browse files
authored
SOLR-17654: Fix DistribFileStore._getRealPath() for Windows (#3160)
Revert but use NIO API to obtain path separator
1 parent bca4cd6 commit d0ec48f

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

solr/core/src/java/org/apache/solr/filestore/DistribFileStore.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import java.lang.invoke.MethodHandles;
3131
import java.nio.ByteBuffer;
3232
import java.nio.channels.SeekableByteChannel;
33+
import java.nio.file.FileSystems;
3334
import java.nio.file.Files;
3435
import java.nio.file.Path;
3536
import java.nio.file.Paths;
@@ -88,13 +89,13 @@ public Path getRealPath(String path) {
8889
return _getRealPath(path, solrHome);
8990
}
9091

91-
private static Path _getRealPath(String dir, Path solrHome) {
92-
Path path = Path.of(dir);
93-
SolrPaths.assertNotUnc(path);
94-
95-
if (path.isAbsolute()) {
96-
// Strip the path of from being absolute to become relative to resolve with SolrHome
97-
path = path.subpath(0, path.getNameCount());
92+
private static Path _getRealPath(String path, Path solrHome) {
93+
if (FileSystems.getDefault().getSeparator().equals("\\")) {
94+
path = path.replace("/", FileSystems.getDefault().getSeparator());
95+
}
96+
SolrPaths.assertNotUnc(Path.of(path));
97+
while (path.startsWith(FileSystems.getDefault().getSeparator())) { // Trim all leading slashes
98+
path = path.substring(1);
9899
}
99100

100101
var finalPath = getFileStoreDirPath(solrHome).resolve(path);

0 commit comments

Comments
 (0)