Apache Solr open-source search software
SOLR-15009 Propogate IOException from DF.exists
Mike Drobcb5ba42bd7d9
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex 98e2a87d81a..b9464c9aa14 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -205,6 +205,8 @@ Bug Fixes* SOLR-14851: Http2SolrClient doesn't handle keystore type correctly (Andras Salamon via janhoy)+* SOLR-15009: Correctly propogate exceptions from DirectoryFactory.exists (Mike Drob)+Other Changes---------------------diff --git a/solr/core/src/java/org/apache/solr/core/CachingDirectoryFactory.java b/solr/core/src/java/org/apache/solr/core/CachingDirectoryFactory.javaindex 0b4e193b8d7..c76389bce0c 100644--- a/solr/core/src/java/org/apache/solr/core/CachingDirectoryFactory.java+++ b/solr/core/src/java/org/apache/solr/core/CachingDirectoryFactory.java@@ -16,9 +16,11 @@*/package org.apache.solr.core;-import java.io.File;import java.io.IOException;import java.lang.invoke.MethodHandles;+import java.nio.file.DirectoryStream;+import java.nio.file.Files;+import java.nio.file.Path;import java.nio.file.Paths;import java.util.ArrayList;import java.util.Collection;@@ -323,9 +325,14 @@ public abstract class CachingDirectoryFactory extends DirectoryFactory {@Overridepublic boolean exists(String path) throws IOException {- // back compat behavior- File dirFile = new File(path);- return dirFile.canRead() && dirFile.list().length > 0;+ // we go by the persistent storage ...+ Path dirPath = Path.of(path);+ if (Files.isReadable(dirPath)) {+ try (DirectoryStream<Path> directory = Files.newDirectoryStream(dirPath)) {+ return directory.iterator().hasNext();+ }+ }+ return false;}/*diff --git a/solr/core/src/java/org/apache/solr/core/StandardDirectoryFactory.java b/solr/core/src/java/org/apache/solr/core/StandardDirectoryFactory.javaindex 3f901467b74..71bb9a91647 100644--- a/solr/core/src/java/org/apache/solr/core/StandardDirectoryFactory.java+++ b/solr/core/src/java/org/apache/solr/core/StandardDirectoryFactory.java@@ -84,24 +84,11 @@ public class StandardDirectoryFactory extends CachingDirectoryFactory {return super.normalize(cpath);}-- @Override- public boolean exists(String path) throws IOException {- // we go by the persistent storage ...- File dirFile = new File(path);- return dirFile.canRead() && dirFile.list().length > 0;- }-+public boolean isPersistent() {return true;}- @Override- public boolean isAbsolute(String path) {- // back compat- return new File(path).isAbsolute();- }-@Overrideprotected void removeDirectory(CacheValue cacheValue) throws IOException {File dirFile = new File(cacheValue.path);