Skip to content

Apache Lucene open-source search software

LUCENE-7797: the static FSDirectory.listAll was always returning an empty array

Mike McCandless4cd83ea276a7
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 3cee96081b9..aeeebd69d9d 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -97,6 +97,9 @@ Bug Fixes
ArrayIndexOutOfBoundsException when byte blocks larger than 32 KB
were added (Mike McCandless)
+* LUCENE-7797: The static FSDirectory.listAll(Path) method was always
+ returning an empty array. (Atkins Chang via Mike McCandless)
+
Improvements
* LUCENE-7782: OfflineSorter now passes the total number of items it
diff --git a/lucene/core/src/java/org/apache/lucene/store/FSDirectory.java b/lucene/core/src/java/org/apache/lucene/store/FSDirectory.java
index 50b52ceb07a..158a2e23034 100644
--- a/lucene/core/src/java/org/apache/lucene/store/FSDirectory.java
+++ b/lucene/core/src/java/org/apache/lucene/store/FSDirectory.java
@@ -215,7 +215,7 @@ public abstract class FSDirectory extends BaseDirectory {
try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir)) {
for (Path path : stream) {
String name = path.getFileName().toString();
- if (skipNames != null && skipNames.contains(name) == false) {
+ if (skipNames == null || skipNames.contains(name) == false) {
entries.add(name);
}
}
diff --git a/lucene/core/src/test/org/apache/lucene/store/TestDirectory.java b/lucene/core/src/test/org/apache/lucene/store/TestDirectory.java
index 5e4a5934d34..d3489ad7fd9 100644
--- a/lucene/core/src/test/org/apache/lucene/store/TestDirectory.java
+++ b/lucene/core/src/test/org/apache/lucene/store/TestDirectory.java
@@ -22,7 +22,9 @@ import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.HashSet;
import java.util.List;
+import java.util.Set;
import org.apache.lucene.util.LuceneTestCase;
@@ -137,5 +139,16 @@ public class TestDirectory extends LuceneTestCase {
fsDir.close();
}
}
+
+ public void testListAll() throws Throwable {
+ Path dir = createTempDir("testdir");
+ Path file1 = Files.createFile(dir.resolve("tempfile1"));
+ Path file2 = Files.createFile(dir.resolve("tempfile2"));
+ Set<String> files = new HashSet<>(Arrays.asList(FSDirectory.listAll(dir)));
+
+ assertTrue(files.size() == 2);
+ assertTrue(files.contains(file1.getFileName().toString()));
+ assertTrue(files.contains(file2.getFileName().toString()));
+ }
}