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

This commit is contained in:
Mike McCandless 2017-04-22 08:49:34 -04:00
parent 3316f47bcf
commit 4cd83ea276
3 changed files with 17 additions and 1 deletions

View File

@ -97,6 +97,9 @@ Bug Fixes
ArrayIndexOutOfBoundsException when byte blocks larger than 32 KB ArrayIndexOutOfBoundsException when byte blocks larger than 32 KB
were added (Mike McCandless) were added (Mike McCandless)
* LUCENE-7797: The static FSDirectory.listAll(Path) method was always
returning an empty array. (Atkins Chang via Mike McCandless)
Improvements Improvements
* LUCENE-7782: OfflineSorter now passes the total number of items it * LUCENE-7782: OfflineSorter now passes the total number of items it

View File

@ -215,7 +215,7 @@ public abstract class FSDirectory extends BaseDirectory {
try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir)) { try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir)) {
for (Path path : stream) { for (Path path : stream) {
String name = path.getFileName().toString(); String name = path.getFileName().toString();
if (skipNames != null && skipNames.contains(name) == false) { if (skipNames == null || skipNames.contains(name) == false) {
entries.add(name); entries.add(name);
} }
} }

View File

@ -22,7 +22,9 @@ import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set;
import org.apache.lucene.util.LuceneTestCase; import org.apache.lucene.util.LuceneTestCase;
@ -137,5 +139,16 @@ public class TestDirectory extends LuceneTestCase {
fsDir.close(); 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()));
}
} }