SOLR-15009 Propogate IOException from DF.exists

This commit is contained in:
Mike Drob 2020-11-20 13:22:50 -08:00
parent 37a61635e1
commit cb5ba42bd7
No known key found for this signature in database
GPG Key ID: 3E48C0C6EF362B9E
3 changed files with 14 additions and 18 deletions

View File

@ -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
---------------------

View File

@ -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;
}
/*

View File

@ -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);