You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by md...@apache.org on 2020/11/30 18:28:29 UTC

[lucene-solr] branch branch_8x updated: SOLR-15009 Propogate IOException from DF.exists

This is an automated email from the ASF dual-hosted git repository.

mdrob pushed a commit to branch branch_8x
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git


The following commit(s) were added to refs/heads/branch_8x by this push:
     new 388d665  SOLR-15009 Propogate IOException from DF.exists
388d665 is described below

commit 388d66573881175cf38a4f879e3b73fe25699086
Author: Mike Drob <md...@apple.com>
AuthorDate: Fri Nov 20 13:22:50 2020 -0800

    SOLR-15009 Propogate IOException from DF.exists
---
 solr/CHANGES.txt                                        |  2 ++
 .../org/apache/solr/core/CachingDirectoryFactory.java   | 15 +++++++++++----
 .../org/apache/solr/core/StandardDirectoryFactory.java  | 17 ++---------------
 3 files changed, 15 insertions(+), 19 deletions(-)

diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 4e98279..cf4c2d6 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -51,6 +51,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.java
index 0b4e193..c76389b 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 {
 
   @Override
   public 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.java
index 3f90146..05fe2d3 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();
-  }
-  
+
   @Override
   protected void removeDirectory(CacheValue cacheValue) throws IOException {
     File dirFile = new File(cacheValue.path);